@Override public boolean check(Row row) { for (String field : fields) { if (row.isNullAt(row.fieldIndex(field))) { return false; } } return true; }
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; }
@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; } }
public static Object get(Row row, String fieldName) { return row.get(row.fieldIndex(fieldName)); }
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()); }
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))); } }
String nextPath = currentPath + "/" + keyFieldName + "=" + filter.get(filter.fieldIndex(keyFieldName)); nextPaths.add(nextPath);
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; }
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; }
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; }
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); }
if (!plan.isNullAt(plan.fieldIndex(fieldName))) { int fieldIndex = plan.fieldIndex(fieldName); switch (columnSchema.getType()) { case DOUBLE: