有什么语句可以直接导出建表脚本吗

我们后台有表,有什么语句可以直接导出建表脚本吗?我们想要在别的机器上新建一套。

请先 登录 后评论

1 个回答

wale

可以用下面自定义函数导出:

/* @input  dbName:数据库名称
 *         tableName:表名称
 *  @output 返回分区表建表信息
 *  @注意:
 *         
*/
def getDDL(dbName,tableName){
	//表不存在提示信息
	if(!existsTable(dbName,tableName)){
		return "Please check whether the table exists"
        }
	//字段与字段类型
	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("db = database("+'\"'+database+'\")')
	print("db.createPartitionedTable(table(1:0,"+col1+","+col2+"),`"+tableName+","+partitionCol+")")
}

调用例子

login(`admin,`123456)
getDDL("dfs://level2","quotes")


attachments-2021-09-utXpLOdy6139c9c0f3eab.png

请先 登录 后评论
  • 1 关注
  • 0 收藏,1027 浏览
  • Boye 提出于 2021-09-09 16:16