This section introduces all the supported commands for managing a Kafka topic.
Lenses supports the typical SQL commands supported by a relational database:
CREATE TABLE table_name( $field $fieldType [, $field $fieldType,...] ) FORMAT ($keyStorageFormat, $valueStorageFormat) [PROPERTIES( partitions= *, replication=$replication, compacted=true/false) ];
The CREATE statement has the following parts:
CREATE
A Kafka topic which is compacted is a special type of topic with a finer-grained retention mechanism that retains the last update record for each key.
A compacted topic (once the compaction has been completed) contains a full snapshot of the final record values for every record key and not just the recently changed keys. They are useful for in-memory services, persistent data stores, reloading caches, etc.
For more details on the subject, you should look at Kafka Documentation.
Example:
CREATE TABLE customer ( id STRING , address.line STRING , address.city STRING, , address.postcode INT , email STRING ) FORMAT (string, json) PROPERTIES ( partitions=1, compacted=true );
Best practices dictate to use Avro as a storage format over other formats. In this case, the key can still be stored as STRING but the value can be Avro.
CREATE TABLE customer_avro ( id STRING , address.line STRING , address.city STRING , address.postcode int , email string ) FORMAT (string, avro) PROPERTIES ( partitions=1, compacted=true );
To list all tables:
SHOW TABLES;
To examine the schema an metadata for a topic:
DESCRIBE TABLE $tableName
The $tableName should contain the name of the table to describe.
$tableName
Given the two tables created earlier, a user can run the following SQL to get the information on each table:
DESCRIBE TABLE customer_avro
the following information will be displayed:
/* Output: # Column Name # Data Type _key String _value.address.postcode Int _value.address.city String _value.address.line String _value.email String _value.id String # Config Key # Config Value cleanup.policy compact compression.type producer delete.retention.ms 86400000 file.delete.delay.ms 60000 flush.messages 9223372036854775807 flush.ms 9223372036854775807 index.interval.bytes 4096 max.message.bytes 1000012 message.format.version 1.1-IV0 message.timestamp.difference.max.ms 9223372036854775807 message.timestamp.type CreateTime min.cleanable.dirty.ratio 0.5 min.compaction.lag.ms 0 min.insync.replicas 1 preallocate false retention.bytes 2147483648 retention.ms 604800000 segment.bytes 1073741824 segment.index.bytes 10485760 segment.jitter.ms 0 segment.ms 604800000 unclean.leader.election.enable false */
To drop a table:
DROP TABLE $Table;
Lenses provides a set of virtual tables that contain information about all the fields in all the tables.
Using the virtual table, you can quickly search for a table name but also see the table type.
The __table has a table_name column containing the table name, and a table_type column describing the table type (system, user, etc).
__table
table_name
table_type
SELECT * FROM __tables; SELECT * FROM __tables WHERE table_name LIKE '%customer%';
To see all the tables fields select from the _fields virtual table.
_fields
SELECT * FROM __fields; SELECT * FROM __fields WHERE table_name LIKE '%customer%'
On this page