如何从HDF读取配置单元数据

2024-05-15 10:43:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我在HDFS有蜂箱仓库hdfs://localhost:8020/用户/配置单元/仓库。在

我在hdfs里面有一个mydb数据库hdfs://localhost:8020/用户/配置单元/仓库/马来西亚第纳尔在

如何使用Pyspark创建表并在其中插入数据

请提出建议


Tags: 数据用户数据库localhosthdfs建议仓库pyspark
1条回答
网友
1楼 · 发布于 2024-05-15 10:43:31

使用配置单元上下文,您将能够在配置单元中创建表,请参阅下面的代码来实现该功能。在

import findspark
findspark.init()
import pyspark
from pyspark.sql import HiveContext

//hivecontext
sqlCtx= HiveContext(sc)

//Loading a csv file into dataframe
spark_df = sqlCtx.read.format('com.databricks.spark.csv').options(header='true', inferschema='true').load("./data/documents_topics.csv")

//registering temp table
spark_df.registerTempTable("TABLE_Y")

//Creating table out of an existing temp created from data frame table
sqlCtx.sql("CREATE TABLE TABLE_X AS SELECT * from TABLE_Y")

//creating a brand new table in Hive
sqlCtx.sql("CREATE TABLE SomeSchema.TABLE_X (customername string, id string, ts timestamp) STORED AS DESIREDFORMAT")

希望你能理解代码中的注释,如果遇到问题请告诉我。在

相关问题 更多 >