如果第一列(左侧列)具有0值并且应该在右侧列中添加NULL,则需要将数据(列)移位到左侧.一旦在任何列中找到非零值,则后一列中的0值应保持原样.
输入数据:-
cust_id month1 month2 month3 month4 month5
c1 100 200 300 400 500
c2 0 0 50 250 350
c3 0 0 100 0 0
c4 100 0 100 0 500
c5 0 0 0 0 0
Run Code Online (Sandbox Code Playgroud)
预期产出结果: -
cust_id month1 month2 month3 month4 month5
c1 100 200 300 400 500
c2 50 250 350 NULL NULL
c3 100 0 0 NULL NULL
c4 100 0 100 0 500
c5 NULL NULL NULL NULL NULL
Run Code Online (Sandbox Code Playgroud)
一个静态的解决方法可能是:
IF month1=0 and …Run Code Online (Sandbox Code Playgroud) 无法通过Hive访问通过Spark(pyspark)创建的Hive表。
df.write.format("orc").mode("overwrite").saveAsTable("db.table")
Run Code Online (Sandbox Code Playgroud)
从Hive访问时出错:
错误:java.io.IOException:java.lang.IllegalArgumentException:bucketId超出范围:-1(状态=,代码= 0)
在Hive中成功创建表,并能够在Spark中读取该表。表元数据可访问(在Hive中),数据文件在表(在hdfs中)目录中。
Hive表的TBLPROPERTIES是:
'bucketing_version'='2',
'spark.sql.create.version'='2.3.1.3.0.0.0-1634',
'spark.sql.sources.provider'='orc',
'spark.sql.sources.schema.numParts'='1',
Run Code Online (Sandbox Code Playgroud)
我还尝试了使用其他解决方法创建表,但在创建表时出错:
df.write.mode("overwrite").saveAsTable("db.table")
Run Code Online (Sandbox Code Playgroud)
要么
df.createOrReplaceTempView("dfTable")
spark.sql("CREATE TABLE db.table AS SELECT * FROM dfTable")
Run Code Online (Sandbox Code Playgroud)
错误:
AnalysisException:u'org.apache.hadoop.hive.ql.metadata.HiveException:MetaException(由于以下原因,message:Table default.src未能通过严格的托管表检查:将该表标记为托管表,但不是事务性表。) ;'
堆栈版本详细信息:
火花2.3
Hive3.1
Hortonworks数据平台HDP3.0
我有一个包含 10609 行的数据框,我想一次将 100 行转换为 JSON 并将它们发送回网络服务。
我曾尝试使用 SQL 的 LIMIT 子句,例如
temptable = spark.sql("select item_code_1 from join_table limit 100")
Run Code Online (Sandbox Code Playgroud)
这将返回前 100 行,但如果我想要接下来的 100 行,我试过这个但没有用。
temptable = spark.sql("select item_code_1 from join_table limit 100, 200")
Run Code Online (Sandbox Code Playgroud)
错误:Py4JJavaError:调用 o22.sql 时发生错误。: org.apache.spark.sql.catalyst.parser.ParseException: 不匹配的输入 ',' 期望(第 1 行,位置 44)
== SQL ==
select item_code_1 from join_table limit 100, 200
Run Code Online (Sandbox Code Playgroud)