我正试图从笔记本电脑上查询远程(on prem)配置单元数据库中的表。我正在使用sparjsql。我可以连接到它并检索最新的分区。
但是,当我尝试检索列(比如pid)时,它会抛出以下错误:
19/10/08 15:01:19 ERROR Table: Unable to get field from serde: org.apache.hadoop.hive.serde2.avro.AvroSerDe
java.lang.RuntimeException: MetaException(message:org.apache.hadoop.hive.serde2.SerDeException Encountered AvroSerdeException determining schema. Returning signal schema to indicate problem: Unable to read schema from given path: maprfs:/user/<database_name>//<table_name>/schema/partition_epoch=<partition_id>/xyz.avsc)
Caused by: java.net.MalformedURLException: unknown protocol: maprfs
at java.net.URL.<init>(URL.java:600)
at java.net.URL.<init>(URL.java:490)
at java.net.URL.<init>(URL.java:439)
at org.apache.hadoop.hive.serde2.avro.AvroSerdeUtils.determineSchemaOrThrowException
我尝试使用describe table命令并尝试打印模式
Dataset<Row> descTable = spark.sql("desc db.tablename");
descTable.printSchema();
打印的架构似乎已关闭,并且没有列出任何字段。而是打印出描述字段的标题
root
|-- col_name: string (nullable = false)
|-- data_type: string (nullable = false)
|-- comment: string (nullable = true)
我期待着这样的事情
pid string from deserializer
当我使用显式字段进行查询时,代码最终会失败
19/10/08 15:01:25 WARN HiveExternalCatalog: The table schema given by Hive metastore(struct<partition_epoch:string>) is different from the schema when this table was created by Spark SQL(struct<all fields and their type>,partition_epoch:string>). We have to fall back to the table schema from Hive metastore which is not case preserving.
19/10/08 15:01:25 ERROR: exception: cannot resolve '`pid`' given input columns: [db.tablename.partition_epoch]; line 1 pos 7;
cannot resolve '`pid`' given input columns: [db.tablename.partition_epoch]; line 1 pos 7;
'Project ['pid]
+- Filter (cast(partition_epoch#9 as int) = 1570500000)
+- SubqueryAlias `db`.`tablename`
+- HiveTableRelation `db`.`tablename`, org.apache.hadoop.hive.serde2.avro.AvroSerDe, [partition_epoch#9]
下面是我用来创建sparksession和查询表的代码
SparkSession spark = SparkSession
.builder()
.master("local[*]")
.appName("myApp")
.config("spark.hadoop.javax.jdo.option.ConnectionURL","jdbc:mysql://url:3306/metastore?createDatabaseIfNotExist=false")
.config("spark.hadoop.javax.jdo.option.ConnectionDriverName","com.mysql.jdbc.Driver")
.config("spark.hadoop.javax.jdo.option.ConnectionUserName","username")
.config("spark.hadoop.javax.jdo.option.ConnectionPassword","password")
.config("hive.metastore.warehouse.dir", "hive")
.enableHiveSupport()
.getOrCreate();
Dataset<Row> productIds = spark.sql("select pid FROM db.tablename WHERE partition_epoch="+partitionEpoch);
System.out.println(productIds.collect());
我在etc/hive/conf下的hive-site.xml中查找hivemeta.uris,但它没有这个信息。
如何解决架构错误并查询表。?
1条答案
按热度按时间5lwkijsr1#
printschema()描述dataframe的模式,而不是表的模式。使用desctable.show()查看您的架构。
验证问题检查表属性spark.sql.sources.schema。表的架构必须与此属性描述的架构相同。