# KSQL Server
- KSQL Server will provide us server to process topics using KSQL CLI
- In KSQL CLI we can write SQL query to process topics
+ We can create new streams or table out of processed topics
    + Streams: It shows all events occured on topic
    + Table: It shows current state of event on topic

## Run Setup
Start KSQL Server with given below command.

`$ cd ksql-server` \
`$ docker-compose up`

## KSQL CLI
Start KSQL CLI with given below command.

`$ docker run --network=host -it confluentinc/cp-ksql-cli http://0.0.0.0:8088`

### KSQL Basic Commands
- Show all topics \
    `$ show topics;`
- Print one of topic. \
    `$ print topic_name;`
- Create stream
    ```
    CREATE STREAM pageviews (
        viewtime BIGINT KEY,
        pageid VARCHAR,
        userid VARCHAR
    ) WITH (
        KAFKA_TOPIC='pageviews',
        VALUE_FORMAT='DELIMITED',
        TIMESTAMP='viewtime'
  );
  ```
- Create table
    ```
    CREATE TABLE users (
        userid VARCHAR PRIMARY KEY,
        registertime BIGINT,
        gender VARCHAR,
        regionid VARCHAR,
        interests array<VARCHAR>,
        contactinfo map<VARCHAR, VARCHAR>
    ) WITH (
        KAFKA_TOPIC='users',
        VALUE_FORMAT='JSON'
    );
  ```
- More examples https://docs.ksqldb.io/en/latest/tutorials/examples/
