Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding QueryParameter support in BigQuery #1451

Merged
merged 5 commits into from
Dec 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion google-cloud-bigquery/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-bigquery</artifactId>
<version>v2-rev303-1.22.0</version>
<version>v2-rev330-1.22.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,15 @@ public static class Type implements Serializable {

private static final long serialVersionUID = 2841484762609576959L;

public enum Value {
BYTES, STRING, INTEGER, FLOAT, BOOLEAN, TIMESTAMP, RECORD
}

private final Value value;
private final LegacySQLTypeName value;
private final List<Field> fields;

private Type(Value value) {
private Type(LegacySQLTypeName value) {
this.value = checkNotNull(value);
this.fields = null;
}

private Type(Value value, List<Field> fields) {
private Type(LegacySQLTypeName value, List<Field> fields) {
checkArgument(fields.size() > 0, "Record must have at least one field");
this.value = value;
this.fields = fields;
Expand All @@ -97,7 +93,7 @@ private Type(Value value, List<Field> fields) {
* Data Types</a>
*/
@Deprecated
public Value value() {
public LegacySQLTypeName value() {
return getValue();
}

Expand All @@ -107,81 +103,81 @@ public Value value() {
* @see <a href="https://cloud.google.com/bigquery/preparing-data-for-bigquery#datatypes">
* Data Types</a>
*/
public Value getValue() {
public LegacySQLTypeName getValue() {
return value;
}

/**
* Returns the list of sub-fields if {@link #value()} is set to {@link Value#RECORD}. Returns
* {@code null} otherwise.
* Returns the list of sub-fields if {@link #value()} is set to {@link
* LegacySQLTypeName#RECORD}. Returns {@code null} otherwise.
*/
@Deprecated
public List<Field> fields() {
return getFields();
}

/**
* Returns the list of sub-fields if {@link #value()} is set to {@link Value#RECORD}. Returns
* {@code null} otherwise.
* Returns the list of sub-fields if {@link #value()} is set to {@link
* LegacySQLTypeName#RECORD}. Returns {@code null} otherwise.
*/
public List<Field> getFields() {
return fields;
}

/**
* Returns a {@link Value#BYTES} field value.
* Returns a {@link LegacySQLTypeName#BYTES} field value.
*/
public static Type bytes() {
return new Type(Value.BYTES);
return new Type(LegacySQLTypeName.BYTES);
}

/**
* Returns a {@link Value#STRING} field value.
* Returns a {@link LegacySQLTypeName#STRING} field value.
*/
public static Type string() {
return new Type(Value.STRING);
return new Type(LegacySQLTypeName.STRING);
}

/**
* Returns an {@link Value#INTEGER} field value.
* Returns an {@link LegacySQLTypeName#INTEGER} field value.
*/
public static Type integer() {
return new Type(Value.INTEGER);
return new Type(LegacySQLTypeName.INTEGER);
}

/**
* Returns a {@link Value#FLOAT} field value.
* Returns a {@link LegacySQLTypeName#FLOAT} field value.
*/
public static Type floatingPoint() {
return new Type(Value.FLOAT);
return new Type(LegacySQLTypeName.FLOAT);
}

/**
* Returns a {@link Value#BOOLEAN} field value.
* Returns a {@link LegacySQLTypeName#BOOLEAN} field value.
*/
public static Type bool() {
return new Type(Value.BOOLEAN);
return new Type(LegacySQLTypeName.BOOLEAN);
}

/**
* Returns a {@link Value#TIMESTAMP} field value.
* Returns a {@link LegacySQLTypeName#TIMESTAMP} field value.
*/
public static Type timestamp() {
return new Type(Value.TIMESTAMP);
return new Type(LegacySQLTypeName.TIMESTAMP);
}

/**
* Returns a {@link Value#RECORD} field value with associated list of sub-fields.
* Returns a {@link LegacySQLTypeName#RECORD} field value with associated list of sub-fields.
*/
public static Type record(Field... fields) {
return new Type(Value.RECORD, ImmutableList.copyOf(fields));
return new Type(LegacySQLTypeName.RECORD, ImmutableList.copyOf(fields));
}

/**
* Returns a {@link Value#RECORD} field value with associated list of sub-fields.
* Returns a {@link LegacySQLTypeName#RECORD} field value with associated list of sub-fields.
*/
public static Type record(List<Field> fields) {
return new Type(Value.RECORD, ImmutableList.copyOf(checkNotNull(fields)));
return new Type(LegacySQLTypeName.RECORD, ImmutableList.copyOf(checkNotNull(fields)));
}

@Override
Expand Down Expand Up @@ -389,17 +385,17 @@ public String getDescription() {
}

/**
* Returns the list of sub-fields if {@link #type()} is a {@link Type.Value#RECORD}. Returns
* {@code null} otherwise.
* Returns the list of sub-fields if {@link #type()} is a {@link LegacySQLTypeName#RECORD}.
* Returns {@code null} otherwise.
*/
@Deprecated
public List<Field> fields() {
return getFields();
}

/**
* Returns the list of sub-fields if {@link #type()} is a {@link Type.Value#RECORD}. Returns
* {@code null} otherwise.
* Returns the list of sub-fields if {@link #type()} is a {@link LegacySQLTypeName#RECORD}.
* Returns {@code null} otherwise.
*/
public List<Field> getFields() {
return type.getFields();
Expand Down Expand Up @@ -474,7 +470,7 @@ public static Builder newBuilder(String name, Type type) {
static Field fromPb(TableFieldSchema fieldSchemaPb) {
Builder fieldBuilder = new Builder();
fieldBuilder.setName(fieldSchemaPb.getName());
Type.Value enumValue = Type.Value.valueOf(fieldSchemaPb.getType());
LegacySQLTypeName enumValue = LegacySQLTypeName.valueOf(fieldSchemaPb.getType());
if (fieldSchemaPb.getMode() != null) {
fieldBuilder.setMode(Mode.valueOf(fieldSchemaPb.getMode()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.bigquery;

/**
* A type used in legacy SQL contexts. NOTE: some contexts use a mix of types; for example,
* for queries that use standard SQL, the return types are the legacy SQL types.
*
* @see <a href="https://cloud.google.com/bigquery/data-types">https://cloud.google.com/bigquery/data-types</a>
*/
public enum LegacySQLTypeName {
/** Variable-length binary data. */
BYTES(StandardSQLTypeName.BYTES),
/** Variable-length character (Unicode) data. */
STRING(StandardSQLTypeName.STRING),
/** A 64-bit signed integer value. */
INTEGER(StandardSQLTypeName.INT64),
/** A 64-bit IEEE binary floating-point value. */
FLOAT(StandardSQLTypeName.FLOAT64),
/** A Boolean value (true or false). */
BOOLEAN(StandardSQLTypeName.BOOL),
/** Represents an absolute point in time, with microsecond precision. */
TIMESTAMP(StandardSQLTypeName.TIMESTAMP),
/** Represents a logical calendar date. Note, support for this type is limited in legacy SQL. */
DATE(StandardSQLTypeName.DATE),
/**
* Represents a time, independent of a specific date, to microsecond precision. Note, support for
* this type is limited in legacy SQL.
*/
TIME(StandardSQLTypeName.TIME),
/**
* Represents a year, month, day, hour, minute, second, and subsecond (microsecond precision).
* Note, support for this type is limited in legacy SQL.
*/
DATETIME(StandardSQLTypeName.DATETIME),
/** A record type with a nested schema. */
RECORD(StandardSQLTypeName.STRUCT);

private StandardSQLTypeName equivalent;

LegacySQLTypeName(StandardSQLTypeName equivalent) {
this.equivalent = equivalent;
}

/**
* Provides the standard SQL type name equivalent to this type name.
*/
public StandardSQLTypeName getStandardType() {
return equivalent;
}
}
Loading