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
Modifier and TypeClassDescriptionstatic enum
The field value's attribute, giving information on the field's content type. -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Returns the attribute of this Field Value.boolean
Returns this field's value as aBoolean
.byte[]
Returns this field's value as a byte array.double
Returns this field's value as aDouble
.long
Returns this field's value as along
.Returns this field's value as aBigDecimal
.Returns this field's value as aFieldValueList
instance.Returns this field's value as a list ofFieldValue
.Returns this field's value as aString
.Returns this field's value as aString
, representing a timestamp as an Instant.long
Returns this field's value as along
, representing a timestamp in microseconds since epoch (UNIX time).getValue()
Returns this field's value as anObject
.final int
hashCode()
boolean
isNull()
Returnstrue
if this field's value isnull
,false
otherwise.static FieldValue
of
(FieldValue.Attribute attribute, Object value) Creates an instance ofFieldValue
, useful for testing.toString()
-
Method Details
-
getAttribute
Returns the attribute of this Field Value.- Returns:
FieldValue.Attribute.PRIMITIVE
if 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.REPEATED
if the corresponding field has (Field.Mode.REPEATED
) mode. ReturnsFieldValue.Attribute.RECORD
if the corresponding field is aLegacySQLTypeName.RECORD
type.
-
isNull
public boolean isNull()Returnstrue
if this field's value isnull
,false
otherwise. -
getValue
-
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.NUMERIC
LegacySQLTypeName.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()
returnstrue
IllegalStateException
- 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.INTEGER
type.- Throws:
ClassCastException
- if the field is not a primitive typeNumberFormatException
- if the field's value could not be converted toInteger
NullPointerException
- ifisNull()
returnstrue
-
getDoubleValue
public double getDoubleValue()Returns this field's value as aDouble
. This method should only be used if the corresponding field hasLegacySQLTypeName.FLOAT
type.- Throws:
ClassCastException
- if the field is not a primitive typeNumberFormatException
- if the field's value could not be converted toDouble
NullPointerException
- ifisNull()
returnstrue
-
getBooleanValue
public boolean getBooleanValue()Returns this field's value as aBoolean
. This method should only be used if the corresponding field hasLegacySQLTypeName.BOOLEAN
type.- Throws:
ClassCastException
- if the field is not a primitive typeIllegalStateException
- if the field's value could not be converted toBoolean
NullPointerException
- 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.TIMESTAMP
type.- Throws:
ClassCastException
- if the field is not a primitive typeNumberFormatException
- if the field's value could not be converted toLong
NullPointerException
- 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.TIMESTAMP
type.- Throws:
ClassCastException
- if the field is not a primitive typeNumberFormatException
- if the field's value could not be converted toLong
NullPointerException
- ifisNull()
returnstrue
-
getNumericValue
Returns this field's value as aBigDecimal
. This method should only be used if the corresponding field hasLegacySQLTypeName.NUMERIC
type.- Throws:
ClassCastException
- if the field is not a primitive typeNumberFormatException
- if the field's value could not be converted toBigDecimal
NullPointerException
- ifisNull()
returnstrue
-
getRepeatedValue
Returns this field's value as a list ofFieldValue
. This method should only be used if the corresponding field hasField.Mode.REPEATED
mode (i.e.getAttribute()
isFieldValue.Attribute.REPEATED
).- Throws:
ClassCastException
- if the field has notField.Mode.REPEATED
modeNullPointerException
- ifisNull()
returnstrue
-
getRecordValue
Returns this field's value as aFieldValueList
instance. This method should only be used if the corresponding field hasLegacySQLTypeName.RECORD
type (i.e.getAttribute()
isFieldValue.Attribute.RECORD
).- Throws:
ClassCastException
- if the field is not aLegacySQLTypeName.RECORD
typeNullPointerException
- ifisNull()
returnstrue
-
toString
-
hashCode
public final int hashCode() -
equals
-
of
Creates an instance ofFieldValue
, useful for testing.If the
attribute
isFieldValue.Attribute.PRIMITIVE
, thevalue
should be the string representation of the underlying value, eg"123"
for number123
.If the
attribute
isFieldValue.Attribute.REPEATED
orFieldValue.Attribute.RECORD
, thevalue
should beList
ofFieldValue
s orFieldValueList
, respectively.This method is unstable. See this discussion for more context.
-