给定:
数据集:
+--------------------+
| count|
+--------------------+
| 1.0|
| 2.0|
| 3.0|
+--------------------+
代码:
String field = "count";
Dataset<Row> histogram = dataset
.groupBy(field)
.count()
.persist(StrorageLevel.MEMORY_ONLY_SER());
Column cnt = histogram.col("count"); // trying to get .count() result
直方图架构:
root
|-- count: double (nullable = true) // input field `count`
|-- count: long (nullable = false) // .count() result
异常(exception):
org.apache.spark.sql.AnalysisException: Reference 'count' is ambiguous, could be: count#101, count#108L.;
问题:
虽然我理解为什么会发生这种情况,但我不知道如何解决这个问题。数据集是从数据库中的表创建的,可以包含任意数量、任意名称的列,包括 count
, avg
和其他“保留”词。
感谢任何帮助。
最佳答案
dataset.createOrReplaceTempView("V1");
dataset = spark.sql("select count as count_O from v1");
Dataset<Row> histogram = dataset.groupBy("count_O").count().persist(StrorageLevel.MEMORY_ONLY_SER());
Column cnt = histogram.col("count");
关于java - 分析异常: Reference 'count' is ambiguous,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48339978/