/** * Set the field to the given value. * * @param fieldName name of the field to set * @param value value for the field * @return this builder * @throws UnexpectedFormatException if the field is not in the schema, or the field is not nullable but a null * value is given */ public Builder set(String fieldName, @Nullable Object value) { validateAndGetField(fieldName, value); fields.put(fieldName, value); return this; }
/** * Set the field to the given value. * * @param fieldName name of the field to set * @param value value for the field * @return this builder * @throws UnexpectedFormatException if the field is not in the schema, or the field is not nullable but a null * value is given */ public Builder set(String fieldName, @Nullable Object value) { validateAndGetField(fieldName, value); fields.put(fieldName, value); return this; }
LogicalType logicalType = validateAndGetLogicalType(validateAndGetField(fieldName, localTime), EnumSet.of(LogicalType.TIME_MILLIS, LogicalType.TIME_MICROS));
public Builder convertAndSet(String fieldName, @Nullable Date date, @Nullable DateFormat dateFormat) throws UnexpectedFormatException { Schema.Field field = validateAndGetField(fieldName, date); boolean isNullable = field.getSchema().isNullable(); if (isNullable && date == null) {
LogicalType logicalType = validateAndGetLogicalType(validateAndGetField(fieldName, zonedDateTime), EnumSet.of(LogicalType.TIMESTAMP_MILLIS, LogicalType.TIMESTAMP_MICROS));
public Builder convertAndSet(String fieldName, @Nullable Date date, @Nullable DateFormat dateFormat) throws UnexpectedFormatException { Schema.Field field = validateAndGetField(fieldName, date); boolean isNullable = field.getSchema().isNullable(); if (isNullable && date == null) {
LogicalType logicalType = validateAndGetLogicalType(validateAndGetField(fieldName, localTime), EnumSet.of(LogicalType.TIME_MILLIS, LogicalType.TIME_MICROS));
LogicalType logicalType = validateAndGetLogicalType(validateAndGetField(fieldName, zonedDateTime), EnumSet.of(LogicalType.TIMESTAMP_MILLIS, LogicalType.TIMESTAMP_MICROS));
/** * Sets the date value for {@link LogicalType#DATE} field * * @param fieldName name of the field to set * @param localDate value for the field * @return this builder * @throws UnexpectedFormatException if the field is not in the schema, or the field is not nullable but a null * value is given or if the provided date is an invalid date */ public Builder setDate(String fieldName, @Nullable LocalDate localDate) { validateAndGetLogicalType(validateAndGetField(fieldName, localDate), EnumSet.of(LogicalType.DATE)); if (localDate == null) { fields.put(fieldName, null); return this; } try { fields.put(fieldName, Math.toIntExact(localDate.toEpochDay())); } catch (ArithmeticException e) { // Highest integer is 2,147,483,647 which is Jan 1 2038. throw new UnexpectedFormatException(String.format("Field %s was set to a date that is too large." + "Valid date should be below Jan 1 2038", fieldName)); } return this; }
/** * Sets the date value for {@link LogicalType#DATE} field * * @param fieldName name of the field to set * @param localDate value for the field * @return this builder * @throws UnexpectedFormatException if the field is not in the schema, or the field is not nullable but a null * value is given or if the provided date is an invalid date */ public Builder setDate(String fieldName, @Nullable LocalDate localDate) { validateAndGetLogicalType(validateAndGetField(fieldName, localDate), EnumSet.of(LogicalType.DATE)); if (localDate == null) { fields.put(fieldName, null); return this; } try { fields.put(fieldName, Math.toIntExact(localDate.toEpochDay())); } catch (ArithmeticException e) { // Highest integer is 2,147,483,647 which is Jan 1 2038. throw new UnexpectedFormatException(String.format("Field %s was set to a date that is too large." + "Valid date should be below Jan 1 2038", fieldName)); } return this; }
/** * Convert the given string into the type of the given field, and set the value for that field. A String can be * converted to a boolean, int, long, float, double, bytes, string, or null. * * @param fieldName name of the field to set * @param strVal string value for the field * @return this builder * @throws UnexpectedFormatException if the field is not in the schema, or the field is not nullable but a null * value is given, or the string cannot be converted to the type for the field */ public Builder convertAndSet(String fieldName, @Nullable String strVal) throws UnexpectedFormatException { Schema.Field field = validateAndGetField(fieldName, strVal); fields.put(fieldName, convertString(field.getSchema(), strVal)); return this; }
/** * Convert the given string into the type of the given field, and set the value for that field. A String can be * converted to a boolean, int, long, float, double, bytes, string, or null. * * @param fieldName name of the field to set * @param strVal string value for the field * @return this builder * @throws UnexpectedFormatException if the field is not in the schema, or the field is not nullable but a null * value is given, or the string cannot be converted to the type for the field */ public Builder convertAndSet(String fieldName, @Nullable String strVal) throws UnexpectedFormatException { Schema.Field field = validateAndGetField(fieldName, strVal); fields.put(fieldName, convertString(field.getSchema(), strVal)); return this; }