Package com.google.cloud.bigquery
Class FieldValue
- java.lang.Object
-
- com.google.cloud.bigquery.FieldValue
-
- All Implemented Interfaces:
Serializable
public class FieldValue extends Object implements 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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFieldValue.AttributeThe field value's attribute, giving information on the field's content type.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)FieldValue.AttributegetAttribute()Returns the attribute of this Field Value.booleangetBooleanValue()Returns this field's value as aBoolean.byte[]getBytesValue()Returns this field's value as a byte array.doublegetDoubleValue()Returns this field's value as aDouble.longgetLongValue()Returns this field's value as along.BigDecimalgetNumericValue()Returns this field's value as aBigDecimal.org.threeten.extra.PeriodDurationgetPeriodDuration()Returns this field's value as aPeriodDuration.FieldValueListgetRecordValue()Returns this field's value as aFieldValueListinstance.List<FieldValue>getRepeatedValue()Returns this field's value as a list ofFieldValue.StringgetStringValue()Returns this field's value as aString.InstantgetTimestampInstant()Returns this field's value as aString, representing a timestamp as an Instant.longgetTimestampValue()Returns this field's value as along, representing a timestamp in microseconds since epoch (UNIX time).ObjectgetValue()Returns this field's value as anObject.inthashCode()booleanisNull()Returnstrueif this field's value isnull,falseotherwise.static FieldValueof(FieldValue.Attribute attribute, Object value)Creates an instance ofFieldValue, useful for testing.StringtoString()
-
-
-
Method Detail
-
getAttribute
public FieldValue.Attribute 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
public Object getValue()
-
getStringValue
public String 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
-
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
public Instant 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
public BigDecimal 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
-
getRepeatedValue
public List<FieldValue> 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
public FieldValueList 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
-
of
@BetaApi public static FieldValue of(FieldValue.Attribute attribute, Object value)
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.
-
-