This topic describes how to use a LogHub data table.

Syntax

CREATE TABLE tbName(columnName dataType [,columnName dataType]*)
USING loghub
OPTIONS(propertyName=propertyValue[,propertyName=propertyValue]*);

Configuration parameters

Parameter Description Required
sls.project The name of the Log Service project. Yes
sls.store The name of the Logstore. Yes
access.key.id The AccessKey ID provided by Alibaba Cloud. Yes
access.key.secret The AccessKey secret provided by Alibaba Cloud. Yes
endpoint The endpoint of the Log Service API. Yes

Table schema

When creating a LogHub data table, you must explicitly define the fields in the data table. For example, a valid table creation statement is as follows:
spark-sql> CREATE TABLE loghub_table_test
         > USING loghub
         > OPTIONS
         > (...)
Otherwise, the following error is returned:
java.lang.IllegalArgumentException: requirement failed: Unable to infer the schema. The schema 
specification is required to create the table. ;
A valid table creation statement is as follows:
spark-sql> CREATE TABLE loghub_table_test(content string)
         > USING loghub
         > OPTIONS
         > (...)

spark-sql> DESC loghub_table_test;
content  string  NULL
Time taken: 0.436 seconds, Fetched 1 row(s)