alter

The alter statement is used to add columns to an existing table.

Related functions: addColumn, dropColumns!, rename!.

Syntax

alter table tableObj add columnName columnType;
alter table tableObj drop [column] columnName;
alter table tableObj rename [column] columnName to newColumnName;

tableObj can be an in-memory table, a stream table, a DFS table, or a dimension table.

colNames is a string scalar indicating the name of the column to be added.

newColNames is a string scalar indicating the name of the column to be modified.

colTypes is a scalar indicating the data type of the column.

Examples

if(existsDatabase("dfs://test")) dropDatabase("dfs://test")
create database "dfs://test" partitioned by VALUE(1..10), HASH([SYMBOL, 40]), engine='OLAP', atomic='TRANS', chunkGranularity='TABLE'

create table "dfs://test"."pt"(
    id INT,
    deviceId SYMBOL,
    date DATE[comment="time_col", compress="delta"],
    value DOUBLE,
     isFin BOOL
)
partitioned by ID, deviceID

pt = loadTable("dfs://test", `pt)
alter table pt add location SYMBOL;
pt = loadTable("dfs://test", `pt)
pt.schema().colDefs
name typeString typeInt extra comment
id INT 4
deviceId SYMBOL 17
date DATE 6 time_col
value DOUBLE 16
isFin BOOL 1
location SYMBOL 17
alter table pt rename location to loc
pt = loadTable("dfs://test", `pt)
pt.schema().colDefs
name typeString typeInt extra comment
id INT 4
deviceId SYMBOL 17
date DATE 6 time_col
value DOUBLE 16
isFin BOOL 1
loc SYMBOL 17
alter table pt drop value
pt = loadTable("dfs://test", `pt)
pt.schema().colDefs
name typeString typeInt extra comment
id INT 4
deviceId SYMBOL 17
date DATE 6 time_col
isFin BOOL 1
loc SYMBOL 17