Java - 有没有一种无需迭代即可查询 Apache Spark 模式的方法?
Java - Is there a way to query an Apache Spark schema without iterating?
我正在尝试找出是否有一种方法可以直接查询从行数据集派生的 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()
我正在尝试找出是否有一种方法可以直接查询从行数据集派生的 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()