schema

Syntax

schema(table|dbHandle)

Arguments

table | dbHandle can be a table object or a database handle.

Details

Display information about the schema of a table or a database. The function returns an unordered dictionary containing the following information (in alphabetical order):

  • atomic: the level at which the atomicity is guaranteed for a write transaction. It can be TRANS or CHUNK.
  • chunkGranularity: the chunk granularity which determines whether to allow concurrent writes to different tables in the same chunk. It can be TABLE or DATABASE.
  • clusterReplicationEnabled: whether asynchronous replication has been enabled.
  • colDefs: information about each column in the table:
    • name: column name
    • typeString: column type
    • typeInt: the type ID
    • extra: the scale of a DECIMAL value
    • comment: comment on the column
  • compressMethods: the compression methods used for specified columns of a DFS table.
    • name: Column names
    • compressMethods: Compression algorithm applied, including "lz4", "delta", or "zstd".
  • databaseDir: the directory where the database is stored.
  • databaseOwner: the database creator.
  • engineType: the storage engine type. It can be OLAP or TSDB.
  • keepDuplicates: how to deal with records with duplicate sort key values.
  • partitionColumnIndex: the index that indicates the positions of partitioning columns. It returns -1 for a dimension table.
  • partitionColumnName: the partitioning column names.
  • partitionColumnType: the data type ID (which can be checked at Data Types and Data Forms) of the partitioning column.
  • partitionSchema: how the partitions are organized
  • partitionSites (optional): If the parameter locations is specified for function database, it displays the ip:port information of the specified node.
  • partitionTypeName / partitionType: the partitioning scheme and the corresponding ID, including VALUE(1), RANGE(2), LIST(3), COMPO(4), HASH(5).
  • sortColumns: the sort columns for a table.
  • softDelete: whether soft deletion of the table has been enabled. This field will only be returned for tables in TSDB databases. Return true if soft deletion has been enabled, false otherwise.
  • sortKeyMappingFunction: the mapping functions applied to sort keys.
  • tableComment: the comment for DFS tables.
  • tableOwner: the table creator.
  • partitionFunction: the function applied to a column for data partitioning. It is a STRING vector with each element as a function signature. If an element is "asis", meaning no function is applied to that column. For example, partitionFunction->["myPartitionFunc{, 6, 8}","asis"].

Examples

OLAP database:

n=1000000
ID=rand(10, n)
x=rand(1.0, n)
t=table(ID, x)
db=database("dfs://rangedb101", RANGE, 0 5 10)
pt = db.createPartitionedTable(t, `pt, `ID)
pt.append!(t)
pt=loadTable(db,`pt);

schema(db);
// output
databaseDir->dfs://rangedb101
partitionSchema->[0,5,10]
partitionSites->
atomic->TRANS
chunkGranularity->TABLE
partitionType->2
partitionTypeName->RANGE
partitionColumnType->4
clusterReplicationEnabled->1
databaseOwner->admin

OLAP table:

schema(pt);
// output
chunkGranularity->TABLE
tableOwner->admin
compressMethods->
name compressMethods
---- ---------------
ID   lz4            
x    lz4            

colDefs->
name typeString typeInt comment
---- ---------- ------- -------
ID   INT        4              
x    DOUBLE     16             

chunkPath->
partitionColumnIndex->0
partitionColumnName->ID
partitionColumnType->4
partitionType->2
partitionTypeName->RANGE
partitionSchema->[0,5,10]
partitionSites->

TSDB database:

n = 10000
SecurityID = rand(`st0001`st0002`st0003`st0004`st0005, n)
sym = rand(`A`B, n)
TradeDate = 2022.01.01 + rand(100,n)
TotalVolumeTrade = rand(1000..3000, n)
TotalValueTrade = rand(100.0, n)
schemaTable_snap = table(SecurityID, TradeDate, TotalVolumeTrade, TotalValueTrade).sortBy!(`SecurityID`TradeDate)

dbPath = "dfs://TSDB_STOCK"
if (existsDatabase(dbPath)){dropDatabase(dbPath)}
db_snap = database(dbPath, VALUE, 2022.01.01..2022.01.05, engine='TSDB')

schema(db_snap)
// output
databaseDir->dfs://TSDB_STOCK
partitionSchema->[2022.01.01,2022.01.02,2022.01.03,2022.01.04,2022.01.05]
partitionSites->
engineType->TSDB
atomic->TRANS
chunkGranularity->TABLE
partitionType->1
partitionTypeName->VALUE
partitionColumnType->6
clusterReplicationEnabled->1
databaseOwner->admin

TSDB table:

def myHashFunc(x){
  return hashBucket(x, 10)
}
snap=createPartitionedTable(dbHandle=db_snap, table=schemaTable_snap, tableName="snap", partitionColumns=`TradeDate, sortColumns=`SecurityID`TradeDate, keepDuplicates=ALL, sortKeyMappingFunction=[myHashFunc])

schema(snap)
// output
engineType->TSDB
keepDuplicates->ALL
chunkGranularity->TABLE
sortColumns->["SecurityID","TradeDate"]
sortKeyMappingFunction->["def myHashFunc(x){
  return hashBucket(x, 10)
}"]
softDelete->0
tableOwner->admin
compressMethods->
name             compressMethods
---------------- ---------------
SecurityID       lz4            
TradeDate        lz4            
TotalVolumeTrade lz4            
TotalValueTrade  lz4            

colDefs->
name             typeString typeInt extra comment
---------------- ---------- ------- ----- -------
SecurityID       SYMBOL     17                   
TradeDate        DATE       6                    
TotalVolumeTrade INT        4                    
TotalValueTrade  DOUBLE     16                   

chunkPath->
partitionColumnIndex->1
partitionColumnName->TradeDate
partitionColumnType->6
partitionType->1
partitionTypeName->VALUE
partitionSchema->[2022.01.01,2022.01.02,2022.01.03,2022.01.04,2022.01.05]
partitionSites->