/** * Get the corresponding BigQuery {@link StandardSQLTypeName} for supported Beam {@link * FieldType}. */ private static StandardSQLTypeName toStandardSQLTypeName(FieldType fieldType) { StandardSQLTypeName sqlType = BEAM_TO_BIGQUERY_TYPE_MAPPING.get(fieldType.getTypeName()); if (sqlType == StandardSQLTypeName.TIMESTAMP && fieldType.getMetadata() != null) { sqlType = BEAM_TO_BIGQUERY_METADATA_MAPPING.get( new String(fieldType.getMetadata(), StandardCharsets.UTF_8)); } return sqlType; }
@Override public boolean equals(Object o) { if (!(o instanceof FieldType)) { return false; } FieldType other = (FieldType) o; return Objects.equals(getTypeName(), other.getTypeName()) && Objects.equals(getCollectionElementType(), other.getCollectionElementType()) && Objects.equals(getMapKeyType(), other.getMapKeyType()) && Objects.equals(getMapValueType(), other.getMapValueType()) && Objects.equals(getRowSchema(), other.getRowSchema()) && Arrays.equals(getMetadata(), other.getMetadata()); }
private static Object fieldToAvatica(Schema.FieldType type, Object beamValue) { switch (type.getTypeName()) { case DATETIME: if (Arrays.equals(type.getMetadata(), CalciteUtils.TIMESTAMP.getMetadata())) { return ((ReadableInstant) beamValue).getMillis(); } else if (Arrays.equals(type.getMetadata(), CalciteUtils.TIME.getMetadata())) { return (int) ((ReadableInstant) beamValue).getMillis(); } else if (Arrays.equals(type.getMetadata(), CalciteUtils.DATE.getMetadata())) { return (int) (((ReadableInstant) beamValue).getMillis() / MILLIS_PER_DAY); } else { throw new IllegalArgumentException( "Unknown DateTime type " + new String(type.getMetadata(), UTF_8));
/** Returns true if two FieldTypes are equal. */ public boolean typesEqual(FieldType other) { if (!Objects.equals(getTypeName(), other.getTypeName())) { return false; } if (!Arrays.equals(getMetadata(), other.getMetadata())) { return false; } if (getTypeName() == TypeName.ARRAY && !getCollectionElementType().typesEqual(other.getCollectionElementType())) { return false; } if (getTypeName() == TypeName.MAP && (!getMapValueType().typesEqual(other.getMapValueType()) || !getMapKeyType().typesEqual(other.getMapKeyType()))) { return false; } if (getTypeName() == TypeName.ROW && !getRowSchema().typesEqual(other.getRowSchema())) { return false; } return true; }
@Override public int hashCode() { return Arrays.deepHashCode( new Object[] { getTypeName(), getCollectionElementType(), getMapKeyType(), getMapValueType(), getRowSchema(), getMetadata() }); } }