我们在后台有桌子。有没有可以直接导出建表脚本的语句?我们想在另一台机器上创建一个新表。
1 回答
0
您可以使用以下自定义函数进行导出:
/* @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")
于 2021-11-09T02:38:49.083 回答