hortonworks-spark / spark-llap

Apache License 2.0
101 stars 68 forks source link

Can not create empty table using execute query, NullPointerException. #257

Open ghost opened 5 years ago

ghost commented 5 years ago

Code: val df = hive.executeQuery("CREATE TABLE default.test2 (dvc string) STORED AS ORC")

Exception:
java.lang.RuntimeException: java.io.IOException: shadehive.org.apache.hive.service.cli.HiveSQLException: java.io.IOException: java.lang.NullPointerException
  at com.hortonworks.spark.sql.hive.llap.HiveWarehouseDataSourceReader.readSchema(HiveWarehouseDataSourceReader.java:130)
  at org.apache.spark.sql.execution.datasources.v2.DataSourceV2Relation$.apply(DataSourceV2Relation.scala:56)
  at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:224)
  at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:164)
  at com.hortonworks.spark.sql.hive.llap.HiveWarehouseSessionImpl.executeQuery(HiveWarehouseSessionImpl.java:62)
  ... 165 elided
AlusaChen commented 5 years ago

you can try:

hive.executeUpdate("CREATE TABLE default.test2 (dvc string) STORED AS ORC")
val df = hive.table("default.test2")

or

hive.setDatabase("default")
hive.createTable("test2").column("dvc", "string").create()
val df = hive.table("default.test2")
sdanielzafar commented 5 years ago

When I run this I get:

scala> val df = hive.table("test2")
19/04/07 16:08:09 ERROR HiveWarehouseDataSourceReader: Unable to read table schema
java.lang.RuntimeException: java.lang.IllegalArgumentException: Expected test2 to be in the form db.table
mdrijwan123 commented 4 years ago

hive.executeQuery is for reading from the query. If you want to create table use queryUpdate. It's for Alter, Update, Create etc.

More details go to: https://docs.cloudera.com/HDPDocuments/HDP3/HDP-3.1.5/integrating-hive/content/hive-read-write-operations.html