org.apache.spark.sql.Row.fieldIndex()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(4.3k)|赞(0)|评价(0)|浏览(628)

本文整理了Java中org.apache.spark.sql.Row.fieldIndex方法的一些代码示例,展示了Row.fieldIndex的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Row.fieldIndex方法的具体详情如下:
包路径:org.apache.spark.sql.Row
类名称:Row
方法名:fieldIndex

Row.fieldIndex介绍

暂无

代码示例

代码示例来源:origin: cloudera-labs/envelope

@Override
public boolean check(Row row) {
 for (String field : fields) {
  if (row.isNullAt(row.fieldIndex(field))) {
   return false;
  }
 }
 return true;
}

代码示例来源:origin: cloudera-labs/envelope

public static boolean different(Row first, Row second, List<String> valueFieldNames) {
 for (String valueFieldName : valueFieldNames) {
  Object firstValue = first.get(first.fieldIndex(valueFieldName));
  Object secondValue = second.get(second.fieldIndex(valueFieldName));
  if (firstValue != null && secondValue != null && !firstValue.equals(secondValue)) {
   return true;
  }
  if ((firstValue != null && secondValue == null) || (firstValue == null && secondValue != null)) {
   return true;
  }
 }
 return false;
}

代码示例来源:origin: cloudera-labs/envelope

@Override
 public List<Object> call(Row row) throws Exception {
  List<Object> values = new ArrayList<>();
  for (String fieldName : fieldNames) {
   values.add(row.get(row.fieldIndex(fieldName)));
  }
  return values;
 }
}

代码示例来源:origin: cloudera-labs/envelope

public static Object get(Row row, String fieldName) {
 return row.get(row.fieldIndex(fieldName));
}

代码示例来源:origin: cloudera-labs/envelope

public static Row remove(Row row, String fieldName) {
 List<StructField> removedFields = Lists.newArrayList(row.schema().fields());
 removedFields.remove(row.fieldIndex(fieldName));
 StructType removedSchema = new StructType(removedFields.toArray(new StructField[removedFields.size()]));
 
 List<Object> removedValues = Lists.newArrayList(RowUtils.valuesFor(row));
 removedValues.remove(row.fieldIndex(fieldName));
 
 return new RowWithSchema(removedSchema, removedValues.toArray());
}

代码示例来源:origin: uk.gov.gchq.gaffer/spark-library

private Stream<String> getPropertyNames(final Row row) {
    return Arrays.stream(row.schema().fieldNames())
        .filter(f -> !ReservedPropertyNames.contains(f))
        .filter(n -> !row.isNullAt(row.fieldIndex(n)));
  }
}

代码示例来源:origin: cloudera-labs/envelope

String nextPath = currentPath + "/" + keyFieldName + "=" + filter.get(filter.fieldIndex(keyFieldName));
nextPaths.add(nextPath);

代码示例来源:origin: cloudera-labs/envelope

private boolean matchesValueFilter(Row row, Row filter) {
 for (String filterFieldName : filter.schema().fieldNames()) {
  Object rowValue = row.get(row.fieldIndex(filterFieldName));
  Object filterValue = RowUtils.get(filter, filterFieldName);
  
  if (!rowValue.equals(filterValue)) {
   return false;
  }
 }
 
 return true;
}

代码示例来源:origin: cloudera-labs/envelope

private Map<TopicPartition, Long> getLastOffsets() throws Exception {
 Map<TopicPartition, Long> offsetRanges = Maps.newHashMap();
 // Create filter for groupid/topic
 for (String topic : topics) {
  StructType filterSchema = DataTypes.createStructType(Lists.newArrayList(
    DataTypes.createStructField("group_id", DataTypes.StringType, false),
    DataTypes.createStructField("topic", DataTypes.StringType, false)));
  Row groupIDTopicFilter = new RowWithSchema(filterSchema, groupID, topic);
  Iterable<Row> filters = Collections.singleton(groupIDTopicFilter);
  // Get results
  RandomOutput output = getOffsetsOutput(config, true);
  Iterable<Row> results = output.getExistingForFilters(filters);
  // Transform results into map
  for (Row result : results) {
   Integer partition = result.getInt(result.fieldIndex("partition"));
   Long offset = result.getLong(result.fieldIndex("offset"));
   TopicPartition topicPartition = new TopicPartition(topic, partition);
   offsetRanges.put(topicPartition, offset);
  }
 }
 
 return offsetRanges;
}

代码示例来源:origin: cloudera-labs/envelope

public static Row subsetRow(Row row, StructType subsetSchema) {
 Object[] values = new Object[subsetSchema.length()];
 int i = 0;
 for (String fieldName : subsetSchema.fieldNames()) {
  values[i] = row.get(row.fieldIndex(fieldName));
  i++;
 }
 Row subset = new RowWithSchema(subsetSchema, values);
 return subset;
}

代码示例来源:origin: cloudera-labs/envelope

public static Row set(Row row, String fieldName, Object replacement) {
 Object[] values = new Object[row.length()];
 for (int i = 0; i < row.schema().fields().length; i++) {
  if (i == row.fieldIndex(fieldName)) {
   values[i] = replacement;
  } else {
   values[i] = row.get(i);
  }
 }
 return new RowWithSchema(row.schema(), values);
}

代码示例来源:origin: cloudera-labs/envelope

if (!plan.isNullAt(plan.fieldIndex(fieldName))) {
 int fieldIndex = plan.fieldIndex(fieldName);
 switch (columnSchema.getType()) {
  case DOUBLE:

相关文章