/** * Gets the default value of the given field, if any. * @param field the field whose default value should be retrieved. * @return the default value associated with the given field, * or null if none is specified in the schema. * @throws IOException */ @SuppressWarnings({ "rawtypes", "unchecked" }) protected Object defaultValue(Field field) throws IOException { return data.deepCopy(field.schema(), data.getDefaultValue(field)); }
/** * Gets the default value of the given field, if any. * @param field the field whose default value should be retrieved. * @return the default value associated with the given field, * or null if none is specified in the schema. * @throws IOException */ @SuppressWarnings({ "rawtypes", "unchecked" }) protected Object defaultValue(Field field) throws IOException { return data.deepCopy(field.schema(), data.getDefaultValue(field)); }
private void setDefault(Schema record, Field f) { String recordName = record.getFullName(); Map<String,Object> recordDefaults = defaults.get(recordName); if (recordDefaults == null) { recordDefaults = new HashMap<>(); defaults.put(recordName, recordDefaults); } recordDefaults.put(f.name(), model.getDefaultValue(f)); }
/** * Gets the default value of the given field, if any. Pass in a conversion * to convert data to logical type class. Please make sure the schema does * have a logical type, otherwise an exception would be thrown out. * @param field the field whose default value should be retrieved. * @param conversion the tool to convert data to logical type class * @return the default value associated with the given field, * or null if none is specified in the schema. * @throws IOException */ @SuppressWarnings({ "rawtypes", "unchecked" }) protected Object defaultValue(Field field, Conversion<?> conversion) throws IOException { Schema schema = field.schema(); LogicalType logicalType = schema.getLogicalType(); Object rawDefaultValue = data.deepCopy(schema, data.getDefaultValue(field)); if (conversion == null || logicalType == null) { return rawDefaultValue; } else { return Conversions.convertToLogicalType(rawDefaultValue, schema, logicalType, conversion); } }
Object value = (field.getObjectProp(USE_DEFAULT) == null) ? generate(field.schema(), random, d+1) : GenericData.get().getDefaultValue(field); record.put(field.name(), value);
/** * Gets the default value of the given field, if any. * @param field the field whose default value should be retrieved. * @return the default value associated with the given field, * or null if none is specified in the schema. * @throws IOException */ @SuppressWarnings({ "rawtypes", "unchecked" }) protected Object defaultValue(Field field) throws IOException { return data.deepCopy(field.schema(), data.getDefaultValue(field)); }
/** * Gets the default value of the given field, if any. * @param field the field whose default value should be retrieved. * @return the default value associated with the given field, * or null if none is specified in the schema. * @throws IOException */ @SuppressWarnings({ "rawtypes", "unchecked" }) protected Object defaultValue(Field field) throws IOException { return data.deepCopy(field.schema(), data.getDefaultValue(field)); }
private Object convertField(JsonNode datum, Schema.Field field) { try { Object value = convertToAvro(datum, field.schema()); if (value != null || nullOk(field.schema())) { return value; } else { return model.getDefaultValue(field); } } catch (JasvornoConverterException e) { // add the field name to the error message throw new JasvornoConverterException(String.format("Cannot convert field %s", field.name()), e); } catch (AvroRuntimeException e) { throw new JasvornoConverterException(String.format("Field '%s': cannot make '%s' value: '%s'", field.name(), field.schema(), String.valueOf(datum)), e); } }
private static Object convertField(GenericData model, JsonNode datum, Schema.Field field) { try { Object value = convertToAvro(model, datum, field.schema()); if (value != null || SchemaUtil.nullOk(field.schema())) { return value; } else { return model.getDefaultValue(field); } } catch (DatasetRecordException e) { // add the field name to the error message throw new DatasetRecordException(String.format( "Cannot convert field %s", field.name()), e); } catch (AvroRuntimeException e) { throw new DatasetRecordException(String.format( "Field %s: cannot make %s value: '%s'", field.name(), field.schema(), String.valueOf(datum)), e); } }
/** * Gets the default value of the given field, if any. Pass in a conversion * to convert data to logical type class. Please make sure the schema does * have a logical type, otherwise an exception would be thrown out. * @param field the field whose default value should be retrieved. * @param conversion the tool to convert data to logical type class * @return the default value associated with the given field, * or null if none is specified in the schema. * @throws IOException */ @SuppressWarnings({ "rawtypes", "unchecked" }) protected Object defaultValue(Field field, Conversion<?> conversion) throws IOException { Schema schema = field.schema(); LogicalType logicalType = schema.getLogicalType(); Object rawDefaultValue = data.deepCopy(schema, data.getDefaultValue(field)); if (conversion == null || logicalType == null) { return rawDefaultValue; } else { return Conversions.convertToLogicalType(rawDefaultValue, schema, logicalType, conversion); } }
continue; // skip null since Parquet does not write nulls if (field.defaultValue() == null || model.getDefaultValue(field) == null) { continue; // field has no default recordDefaults.put(field, model.getDefaultValue(field));
continue; // skip null since Parquet does not write nulls if (field.defaultValue() == null || this.model.getDefaultValue(field) == null) { continue; // field has no default recordDefaults.put(field, this.model.getDefaultValue(field));