Package com.google.cloud.bigquery
Class FieldValue
java.lang.Object
com.google.cloud.bigquery.FieldValue
- All Implemented Interfaces:
Serializable
Google BigQuery Table Field Value class. Objects of this class represent values of a BigQuery
Table Field. A list of values forms a table row. Tables rows can be gotten as the result of a
query or when listing table data.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe field value's attribute, giving information on the field's content type. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanReturns the attribute of this Field Value.booleanReturns this field's value as aBoolean.byte[]Returns this field's value as a byte array.doubleReturns this field's value as aDouble.longReturns this field's value as along.Returns this field's value as aBigDecimal.org.threeten.extra.PeriodDurationReturns this field's value as aPeriodDuration.Returns this field's value as aRange.Returns this field's value as aFieldValueListinstance.Returns this field's value as a list ofFieldValue.Returns this field's value as aString.getStringValueOrDefault(String defaultValue) Returns this field's value as aString, representing a timestamp as an Instant.longReturns this field's value as along, representing a timestamp in microseconds since epoch (UNIX time).getValue()Returns this field's value as anObject.final inthashCode()booleanisNull()Returnstrueif this field's value isnull,falseotherwise.static FieldValueof(FieldValue.Attribute attribute, Object value) Creates an instance ofFieldValue, useful for testing.static FieldValueof(FieldValue.Attribute attribute, Object value, Boolean useInt64Timestamps) toString()
-
Method Details
-
getAttribute
Returns the attribute of this Field Value.- Returns:
FieldValue.Attribute.PRIMITIVEif the field is a primitive type (LegacySQLTypeName.BYTES,LegacySQLTypeName.BOOLEAN,LegacySQLTypeName.STRING,LegacySQLTypeName.FLOAT,LegacySQLTypeName.INTEGER,LegacySQLTypeName.NUMERIC,LegacySQLTypeName.TIMESTAMP,LegacySQLTypeName.GEOGRAPHY) or isnull.Returns
FieldValue.Attribute.REPEATEDif the corresponding field has (Field.Mode.REPEATED) mode. ReturnsFieldValue.Attribute.RECORDif the corresponding field is aLegacySQLTypeName.RECORDtype.
-
isNull
public boolean isNull()Returnstrueif this field's value isnull,falseotherwise. -
getValue
-
getUseInt64Timestamps
-
getStringValue
Returns this field's value as aString. This method should only be used if the corresponding field has primitive type (LegacySQLTypeName.BYTES,LegacySQLTypeName.BOOLEAN,LegacySQLTypeName.STRING,LegacySQLTypeName.FLOAT,LegacySQLTypeName.INTEGER,LegacySQLTypeName.NUMERICLegacySQLTypeName.TIMESTAMP).- Throws:
ClassCastException- if the field is not a primitive typeNullPointerException- ifisNull()returnstrue
-
getStringValueOrDefault
Returns this field's value as aString, or defaultValue ifisNull()returnstrue. SeegetStringValue()for more details.- Throws:
ClassCastException- if the field is not a primitive type
-
getBytesValue
public byte[] getBytesValue()Returns this field's value as a byte array. This method should only be used if the corresponding field has primitive type (LegacySQLTypeName.BYTES.- Throws:
ClassCastException- if the field is not a primitive typeNullPointerException- ifisNull()returnstrueIllegalStateException- if the field value is not encoded in base64
-
getLongValue
public long getLongValue()Returns this field's value as along. This method should only be used if the corresponding field hasLegacySQLTypeName.INTEGERtype.- Throws:
ClassCastException- if the field is not a primitive typeNumberFormatException- if the field's value could not be converted toIntegerNullPointerException- ifisNull()returnstrue
-
getDoubleValue
public double getDoubleValue()Returns this field's value as aDouble. This method should only be used if the corresponding field hasLegacySQLTypeName.FLOATtype.- Throws:
ClassCastException- if the field is not a primitive typeNumberFormatException- if the field's value could not be converted toDoubleNullPointerException- ifisNull()returnstrue
-
getBooleanValue
public boolean getBooleanValue()Returns this field's value as aBoolean. This method should only be used if the corresponding field hasLegacySQLTypeName.BOOLEANtype.- Throws:
ClassCastException- if the field is not a primitive typeIllegalStateException- if the field's value could not be converted toBooleanNullPointerException- ifisNull()returnstrue
-
getTimestampValue
public long getTimestampValue()Returns this field's value as along, representing a timestamp in microseconds since epoch (UNIX time). This method should only be used if the corresponding field hasLegacySQLTypeName.TIMESTAMPtype.- Throws:
ClassCastException- if the field is not a primitive typeNumberFormatException- if the field's value could not be converted toLongNullPointerException- ifisNull()returnstrue
-
getTimestampInstant
Returns this field's value as aString, representing a timestamp as an Instant. This method should only be used if the corresponding field hasLegacySQLTypeName.TIMESTAMPtype.- Throws:
ClassCastException- if the field is not a primitive typeNumberFormatException- if the field's value could not be converted toLongNullPointerException- ifisNull()returnstrue
-
getNumericValue
Returns this field's value as aBigDecimal. This method should only be used if the corresponding field hasLegacySQLTypeName.NUMERICtype.- Throws:
ClassCastException- if the field is not a primitive typeNumberFormatException- if the field's value could not be converted toBigDecimalNullPointerException- ifisNull()returnstrue
-
getRangeValue
Returns this field's value as aRange. This method should only be used * if the corresponding field hasLegacySQLTypeName.RANGEtype.- Throws:
ClassCastException- if the field is not a primitive typeIllegalArgumentException- if the field's value could not be converted toRangeNullPointerException- ifisNull()returnstrue
-
getRepeatedValue
Returns this field's value as a list ofFieldValue. This method should only be used if the corresponding field hasField.Mode.REPEATEDmode (i.e.getAttribute()isFieldValue.Attribute.REPEATED).- Throws:
ClassCastException- if the field has notField.Mode.REPEATEDmodeNullPointerException- ifisNull()returnstrue
-
getPeriodDuration
public org.threeten.extra.PeriodDuration getPeriodDuration()Returns this field's value as aPeriodDuration. This method should be used if the corresponding field hasStandardSQLTypeName.INTERVALtype, or if it is a legal canonical format "[sign]Y-M [sign]D [sign]H:M:S[.F]", e.g. "123-7 -19 0:24:12.000006" or ISO 8601.- Throws:
ClassCastException- if the field is not a primitive typeNullPointerException- ifisNull()returnstrueIllegalArgumentException- if the field cannot be converted to a legal interval
-
getRecordValue
Returns this field's value as aFieldValueListinstance. This method should only be used if the corresponding field hasLegacySQLTypeName.RECORDtype (i.e.getAttribute()isFieldValue.Attribute.RECORD).- Throws:
ClassCastException- if the field is not aLegacySQLTypeName.RECORDtypeNullPointerException- ifisNull()returnstrue
-
toString
-
hashCode
public final int hashCode() -
equals
-
of
Creates an instance ofFieldValue, useful for testing.If the
attributeisFieldValue.Attribute.PRIMITIVE, thevalueshould be the string representation of the underlying value, eg"123"for number123.If the
attributeisFieldValue.Attribute.REPEATEDorFieldValue.Attribute.RECORD, thevalueshould beListofFieldValues orFieldValueList, respectively.This method is unstable. See this discussion for more context.
-
of
@BetaApi public static FieldValue of(FieldValue.Attribute attribute, Object value, Boolean useInt64Timestamps)
-