public Field getField(String name) { return getFields().get(indexOf(name)); }
/** * Get a {@link TypeName#BYTES} value by field name, {@link IllegalStateException} is thrown if * schema doesn't match. */ @Nullable public byte[] getBytes(String fieldName) { return getBytes(getSchema().indexOf(fieldName)); }
/** * Get a {@link TypeName#FLOAT} value by field name, {@link IllegalStateException} is thrown if * schema doesn't match. */ @Nullable public Float getFloat(String fieldName) { return getFloat(getSchema().indexOf(fieldName)); }
/** * Get an array value by field name, {@link IllegalStateException} is thrown if schema doesn't * match. */ @Nullable public <T> List<T> getArray(String fieldName) { return getArray(getSchema().indexOf(fieldName)); }
/** * Get a {@link TypeName#DOUBLE} value by field name, {@link IllegalStateException} is thrown if * schema doesn't match. */ @Nullable public Double getDouble(String fieldName) { return getDouble(getSchema().indexOf(fieldName)); }
/** * Get a {@link TypeName#STRING} value by field name, {@link IllegalStateException} is thrown if * schema doesn't match. */ @Nullable public String getString(String fieldName) { return getString(getSchema().indexOf(fieldName)); }
/** * Get a {@link TypeName#DECIMAL} value by field name, {@link IllegalStateException} is thrown if * schema doesn't match. */ @Nullable public BigDecimal getDecimal(String fieldName) { return getDecimal(getSchema().indexOf(fieldName)); }
/** * Get a {@link TypeName#BOOLEAN} value by field name, {@link IllegalStateException} is thrown if * schema doesn't match. */ @Nullable public Boolean getBoolean(String fieldName) { return getBoolean(getSchema().indexOf(fieldName)); }
/** * Get a {@link TypeName#ROW} value by field name, {@link IllegalStateException} is thrown if * schema doesn't match. */ @Nullable public Row getRow(String fieldName) { return getRow(getSchema().indexOf(fieldName)); }
/** Get value by field name, {@link ClassCastException} is thrown if type doesn't match. */ @Nullable @SuppressWarnings("TypeParameterUnusedInFormals") public <T> T getValue(String fieldName) { return getValue(getSchema().indexOf(fieldName)); }
/** * Get a {@link TypeName#BYTE} value by field name, {@link IllegalStateException} is thrown if * schema doesn't match. */ @Nullable public Byte getByte(String fieldName) { return getByte(getSchema().indexOf(fieldName)); }
/** * Get a {@link TypeName#INT16} value by field name, {@link IllegalStateException} is thrown if * schema doesn't match. */ @Nullable public Short getInt16(String fieldName) { return getInt16(getSchema().indexOf(fieldName)); }
/** * Get a {@link TypeName#INT32} value by field name, {@link IllegalStateException} is thrown if * schema doesn't match. */ @Nullable public Integer getInt32(String fieldName) { return getInt32(getSchema().indexOf(fieldName)); }
/** * Get a {@link TypeName#INT64} value by field name, {@link IllegalStateException} is thrown if * schema doesn't match. */ @Nullable public Long getInt64(String fieldName) { return getInt64(getSchema().indexOf(fieldName)); }
/** * Get a {@link TypeName#DATETIME} value by field name, {@link IllegalStateException} is thrown if * schema doesn't match. */ @Nullable public ReadableDateTime getDateTime(String fieldName) { return getDateTime(getSchema().indexOf(fieldName)); }
/** * Get a MAP value by field name, {@link IllegalStateException} is thrown if schema doesn't match. */ @Nullable public <T1, T2> Map<T1, T2> getMap(String fieldName) { return getMap(getSchema().indexOf(fieldName)); }
private Set<Integer> resolveFieldIdsAccessed(Schema schema) { Set<Integer> fieldIds; if (getFieldInsertionOrder()) { fieldIds = Sets.newLinkedHashSet(); } else { fieldIds = Sets.newTreeSet(); } for (int fieldId : getFieldIdsAccessed()) { fieldIds.add(validateFieldId(schema, fieldId)); } if (!getFieldNamesAccessed().isEmpty()) { fieldIds.addAll( StreamSupport.stream(getFieldNamesAccessed().spliterator(), false) .map(name -> schema.indexOf(name)) .collect(Collectors.toList())); } return fieldIds; }
private Map<Integer, FieldAccessDescriptor> resolveNestedFieldsAccessed(Schema schema) { Map<Integer, FieldAccessDescriptor> nestedFields; if (getFieldInsertionOrder()) { nestedFields = Maps.newLinkedHashMap(); } else { nestedFields = Maps.newTreeMap(); } nestedFields.putAll( getNestedFieldsAccessedByName() .entrySet() .stream() .collect( Collectors.toMap( e -> schema.indexOf(e.getKey()), e -> resolvedNestedFieldsHelper(schema.getField(e.getKey()), e.getValue())))); nestedFields.putAll( getNestedFieldsAccessedById() .entrySet() .stream() .collect( Collectors.toMap( e -> validateFieldId(schema, e.getKey()), e -> resolvedNestedFieldsHelper(schema.getField(e.getKey()), e.getValue())))); return nestedFields; }
public static Row castRow(Row input, Schema inputSchema, Schema outputSchema) { if (input == null) { return null; } Row.Builder output = Row.withSchema(outputSchema); for (int i = 0; i < outputSchema.getFieldCount(); i++) { Schema.Field outputField = outputSchema.getField(i); int fromFieldIdx = inputSchema.indexOf(outputField.getName()); Schema.Field inputField = inputSchema.getField(fromFieldIdx); Object inputValue = input.getValue(fromFieldIdx); Object outputValue = castValue(inputValue, inputField.getType(), outputField.getType()); output.addValue(outputValue); } return output.build(); }
assertEquals(0, schema.indexOf("f_byte")); assertEquals("f_byte", schema.getField(0).getName()); assertEquals(FieldType.BYTE, schema.getField(0).getType()); assertEquals(1, schema.indexOf("f_int16")); assertEquals("f_int16", schema.getField(1).getName()); assertEquals(FieldType.INT16, schema.getField(1).getType()); assertEquals(2, schema.indexOf("f_int32")); assertEquals("f_int32", schema.getField(2).getName()); assertEquals(FieldType.INT32, schema.getField(2).getType()); assertEquals(3, schema.indexOf("f_int64")); assertEquals("f_int64", schema.getField(3).getName()); assertEquals(FieldType.INT64, schema.getField(3).getType()); assertEquals(4, schema.indexOf("f_decimal")); assertEquals("f_decimal", schema.getField(4).getName()); assertEquals(FieldType.DECIMAL, schema.getField(4).getType()); assertEquals(5, schema.indexOf("f_float")); assertEquals("f_float", schema.getField(5).getName()); assertEquals(FieldType.FLOAT, schema.getField(5).getType()); assertEquals(6, schema.indexOf("f_double")); assertEquals("f_double", schema.getField(6).getName()); assertEquals(FieldType.DOUBLE, schema.getField(6).getType()); assertEquals(7, schema.indexOf("f_string"));