We have tables in the background. Are there any statements that can directly export the table creation script? We want to create a new table on another machine.
Asked
Active
Viewed 15 times
1 Answers
0
You can use the following custom function to export:
/* @input dbName: database name
* tableName: table name
* @output: information from creating the table
* @note
*
*/
def getDDL(dbName,tableName){
//table not exist warning
if(!existsTable(dbName,tableName)){
return "Please check whether the table exists"
}
//Fields and field types
col1= schema(loadTable(dbName,tableName)).colDefs.name
col2= schema(loadTable(dbName,tableName)).colDefs.typeString
col1 = "`"+concat(col1,"`")
col2 = "["+concat(col2,",")+"]"
//
partitionCol = schema(loadTable(dbName,tableName)).partitionColumnName
partitionCol = "`"+concat(partitionCol,"`")
//print the information for the creation of table
print("db = database("+'\"'+database+'\")')
print("db.createPartitionedTable(table(1:0,"+col1+","+col2+"),`"+tableName+","+partitionCol+")")
}
login(`admin,`123456)
getDDL("dfs://level2","quotes")

dbaa9948
- 189
- 2
- 10