gpt4 book ai didi

Java - 有没有一种方法可以在不迭代的情况下查询 Apache Spark 模式?

转载 作者:行者123 更新时间:2023-11-30 12:05:05 26 4
gpt4 key购买 nike

我正在尝试找出是否有一种方法可以直接从从行数据集派生的 Spark 架构中查询结构。是否有某种 Java 等同于 Scala 提供的 dataframe.schema("nameOfStruct")?

我已经尝试找到这样一个预建函数,但我唯一能找到的是一种遍历结构列表或创建迭代器的方法。当 Scala 提供了一种更简单的做事方式时,这似乎真的是多余的,特别是如果我不想通过循环检查或找到我想要的 Struct 的确切索引。

//adding the metadata to a column
final Metadata metadata = new MetadataBuilder().putLong("metadataExample", 1).build();
final Dataset<Row> dfWithColumnMetadata = df1.withColumn("column_example", df.col("column_example"), metadata);

/*now I want to find the exact Struct and its metadata without having to loop through
an array or create an iterator. However, the array version is the easiest way I could find.
The con here is that I need to know the exact index of the column.*/
System.out.println(dfWithColumnMetadata.schema().fields()[0].metadata().toString());

有没有办法让我得到像 Scala 的 df.schema("column_example").metadata() 这样的东西?

最佳答案

我认为你可以使用:

dfWithColumnMetadata.schema().apply("column_example").metadata()

关于Java - 有没有一种方法可以在不迭代的情况下查询 Apache Spark 模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56632764/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com