【问题标题】:How to create hive table from Pyspark data frame, using its schema?如何使用其模式从 Pyspark 数据框创建配置单元表?
【发布时间】:2020-06-15 14:22:11
【问题描述】:

我使用以下代码创建了数据框:

  import pyspark
    from pyspark.sql import functions as F

    sc = pyspark.SparkContext()
    spark = pyspark.sql.SparkSession(sc)

    data = [('A', 'B', 1), ('A', 'B', 2), ('A', 'C', 1)]
    columns = ['Column1', 'Column2', 'Column3']
    data = spark.createDataFrame(data, columns)
    data.printSchema()
 root
 |-- Column1: string (nullable = true)
 |-- Column2: string (nullable = true)
 |-- Column3: long (nullable = true)

我想在 pyspark 中使用我的 pySpark 数据框架构创建一个配置单元表?这里我提到了示例列,但我的数据框中有很多列,那么有没有办法自动生成这样的查询?

【问题讨论】:

    标签: python pyspark


    【解决方案1】:

    我相信您的表创建是一次性活动,在这种情况下,spark 和 Hive 表之间的数据类型可能不同。

    如果你有很多列,你可以做的最好的事情..

    打印(data.schema)

    这样你就会得到所有的架构

    【讨论】:

    • 嗨,谢谢您的快速回复,我必须继续获取 csv 文件,并且基于 csv 文件我必须创建 hive table.data.schema 给出“ StructType(List(StructField(Column1, StringType,true),StructField(Column2,StringType,true),StructField(Column3,LongType,true))) ".
    猜你喜欢
    • 2017-07-04
    • 2017-10-10
    • 1970-01-01
    • 1970-01-01
    • 2017-11-14
    • 1970-01-01
    • 2019-02-08
    • 1970-01-01
    • 2018-01-07
    相关资源
    最近更新 更多