Java Code Examples for com.google.cloud.bigquery.Field#Mode

The following examples show how to use com.google.cloud.bigquery.Field#Mode . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BigQueryColumnHandle.java    From presto with Apache License 2.0 6 votes vote down vote up
@JsonCreator
public BigQueryColumnHandle(
        @JsonProperty("name") String name,
        @JsonProperty("bigQueryType") BigQueryType bigQueryType,
        @JsonProperty("mode") Field.Mode mode,
        @JsonProperty("subColumns") List<BigQueryColumnHandle> subColumns,
        @JsonProperty("description") String description,
        @JsonProperty("hidden") boolean hidden)
{
    this.name = requireNonNull(name, "column name cannot be null");
    this.bigQueryType = requireNonNull(bigQueryType, () -> format("column type cannot be null for column [%s]", name));
    this.mode = requireNonNull(mode, "Field mode cannot be null");
    this.subColumns = ImmutableList.copyOf(requireNonNull(subColumns, "subColumns is null"));
    this.description = description;
    this.hidden = hidden;
}
 
Example 2
Source File: BigQueryAvroRegistry.java    From components with Apache License 2.0 6 votes vote down vote up
private org.apache.avro.Schema inferSchemaField(Field field) {
    Field.Mode mode = field.getMode();

    // Get the "basic" type of the field.
    org.apache.avro.Schema fieldSchema = inferSchemaFieldWithoutMode(field);

    // BigQuery fields are NULLABLE by default.
    if (Field.Mode.NULLABLE == mode || mode == null) {
        fieldSchema = AvroUtils.wrapAsNullable(fieldSchema);
    } else if (Field.Mode.REPEATED == mode) {
        // Determine if the field is an array.
        // https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#array-type
        fieldSchema = SchemaBuilder.array().items(fieldSchema);
    }
    return fieldSchema;
}
 
Example 3
Source File: Conversions.java    From presto with Apache License 2.0 5 votes vote down vote up
static BigQueryType.Adaptor adapt(Field field)
{
    return new BigQueryType.Adaptor()
    {
        @Override
        public BigQueryType getBigQueryType()
        {
            return BigQueryType.valueOf(field.getType().name());
        }

        @Override
        public ImmutableMap<String, BigQueryType.Adaptor> getBigQuerySubTypes()
        {
            FieldList subFields = field.getSubFields();
            if (subFields == null) {
                return ImmutableMap.of();
            }
            return subFields.stream().collect(toImmutableMap(Field::getName, Conversions::adapt));
        }

        @Override
        public Field.Mode getMode()
        {
            return Conversions.getMode(field);
        }
    };
}
 
Example 4
Source File: BigQueryColumnHandle.java    From presto with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
BigQueryColumnHandle(
        String name,
        BigQueryType bigQueryType,
        Field.Mode mode,
        List<BigQueryColumnHandle> subColumns,
        String description)
{
    this(name, bigQueryType, mode, subColumns, description, false);
}
 
Example 5
Source File: Conversions.java    From presto with Apache License 2.0 4 votes vote down vote up
private static Field.Mode getMode(Field field)
{
    return firstNonNull(field.getMode(), Field.Mode.NULLABLE);
}
 
Example 6
Source File: BigQueryColumnHandle.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
@JsonProperty
public Field.Mode getMode()
{
    return mode;
}
 
Example 7
Source File: ConverterTest.java    From beast with Apache License 2.0 4 votes vote down vote up
public void assertBqField(String name, LegacySQLTypeName ftype, Field.Mode mode, Field bqf) {
    assertEquals(mode, bqf.getMode());
    assertEquals(name, bqf.getName());
    assertEquals(ftype, bqf.getType());
}
 
Example 8
Source File: BigQueryType.java    From presto with Apache License 2.0 votes vote down vote up
Field.Mode getMode();