我们可以使用pyspark中的数据从现有表创建一个新表

时间:2016-12-29 16:21:15

标签: apache-spark-sql pyspark-sql

为Teradat

创建表格语法

Create table <DBname>.<Tablename> as select * from <DBname>.<Tablename> with data.

类似的方式我们如何在SPARK SQL中创建表。

1 个答案:

答案 0 :(得分:1)

它在Spark SQL中几乎相同。

示例:

CREATE TABLE tablename 
    STORED AS PARQUET LOCATION 'some/location/incase/of/external/table' 
AS
SELECT *
    FROM source_table
WHERE 1=1

正则表达式:(高级别)

CREATE [TEMPORARY] [EXTERNAL] TABLE [IF NOT EXISTS] [db_name.]table_name
  [(col_name data_type [COMMENT col_comment], ...)]
  [COMMENT table_comment]
  [
   [ROW FORMAT row_format] 
   [STORED AS file_format]
  ]
  [LOCATION path_to_save]
  [AS select_statement]

BTW,Spark支持更多Hive语法和功能。你可以参考CTAS doc here