Variant (Snowpark Java API Reference 1.19.1)

Package com.snowflake.snowpark_java.types

## Class Variant

- java.lang.Object
- - com.snowflake.snowpark_java.types.Variant

- All Implemented Interfaces:
    `java.io.Serializable`

      public class Variant
      extends java.lang.Object
      implements java.io.Serializable

  Representation of Snowflake Variant data
  Since:
    0.8.0
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Variant​(boolean value)` | Creates a Variant from boolean value.
    `Variant​(byte[] bytes)` | Creates a Variant from binary value.
    `Variant​(double num)` | Creates a Variant from double value.
    `Variant​(float num)` | Creates a Variant from float value.
    `Variant​(int num)` | Creates a Variant from int value.
    `Variant​(long num)` | Creates a Variant from long value.
    `Variant​(short num)` | Creates a Variant from short value.
    `Variant​(java.lang.Object obj)` | Creates a Variant from Object value.
    `Variant​(java.lang.Object[] arr)` | Creates a Variant from an array.
    `Variant​(java.lang.String str)` | Creates a Variant from String value.
    `Variant​(java.math.BigDecimal num)` | Creates a Variant from BigDecimal value.
    `Variant​(java.math.BigInteger num)` | Creates a Variant from BigInteger value.
    `Variant​(java.sql.Date date)` | Creates a Variant from Date value.
    `Variant​(java.sql.Time time)` | Creates a Variant from Time value.
    `Variant​(java.sql.Timestamp timestamp)` | Creates a Variant from Timestamp value.
    `Variant​(java.util.List<java.lang.Object> list)` | Creates a Variant from a list.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `Variant[]` | `asArray()` | Converts the variant as array of Variant.
    `java.math.BigDecimal` | `asBigDecimal()` | Converts the variant as BigDecimal value.
    `java.math.BigInteger` | `asBigInteger()` | Converts the variant as BigInteger value.
    `byte[]` | `asBinary()` | Converts the variant as binary value.
    `boolean` | `asBoolean()` | Converts the variant as boolean value.
    `java.sql.Date` | `asDate()` | Converts the variant as Date value.
    `double` | `asDouble()` | Converts the variant as double value.
    `float` | `asFloat()` | Converts the variant as float value.
    `int` | `asInt()` | Converts the variant as int value.
    `com.fasterxml.jackson.databind.JsonNode` | `asJsonNode()` | Return the variant value as a JsonNode.
    `java.lang.String` | `asJsonString()` | Converts the variant as valid Json String.
    `java.util.List<Variant>` | `asList()` | Converts the variant as list of Variant.
    `long` | `asLong()` | Converts the variant as long value.
    `java.util.Map<java.lang.String,​Variant>` | `asMap()` | Converts the variant as map of Variant.
    `short` | `asShort()` | Converts the variant as short value.
    `java.lang.String` | `asString()` | Converts the variant as String value.
    `java.sql.Time` | `asTime()` | Converts the variant as Time value.
    `java.sql.Timestamp` | `asTimestamp()` | Converts the variant as Timestamp value.
    `boolean` | `equals​(java.lang.Object other)` | Checks whether two Variants are equal.
    `int` | `hashCode()` | Calculates the hash code of this Variant Object.
    `java.lang.String` | `toString()` | An alias of `asString()`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### Variant

          public Variant​(float num)

      Creates a Variant from float value.
      Parameters:
        `num` - A float number
      Since:
        0.8.0

    - #### Variant

          public Variant​(double num)

      Creates a Variant from double value.
      Parameters:
        `num` - A double number
      Since:
        0.8.0

    - #### Variant

          public Variant​(long num)

      Creates a Variant from long value.
      Parameters:
        `num` - A long number
      Since:
        0.8.0

    - #### Variant

          public Variant​(int num)

      Creates a Variant from int value.
      Parameters:
        `num` - An int number
      Since:
        0.8.0

    - #### Variant

          public Variant​(short num)

      Creates a Variant from short value.
      Parameters:
        `num` - A short number
      Since:
        0.8.0

    - #### Variant

          public Variant​(java.math.BigDecimal num)

      Creates a Variant from BigDecimal value.
      Parameters:
        `num` - A BigDecimal number
      Since:
        0.8.0

    - #### Variant

          public Variant​(java.math.BigInteger num)

      Creates a Variant from BigInteger value.
      Parameters:
        `num` - A BigInteger number
      Since:
        0.8.0

    - #### Variant

          public Variant​(boolean value)

      Creates a Variant from boolean value.
      Parameters:
        `value` - A boolean value
      Since:
        0.8.0

    - #### Variant

          public Variant​(java.lang.String str)

      Creates a Variant from String value.
      Parameters:
        `str` - A string value
      Since:
        0.8.0

    - #### Variant

          public Variant​(byte[] bytes)

      Creates a Variant from binary value.
      Parameters:
        `bytes` - An array of byte representing binary data
      Since:
        0.8.0

    - #### Variant

          public Variant​(java.sql.Time time)

      Creates a Variant from Time value.
      Parameters:
        `time` - A Time object
      Since:
        0.8.0

    - #### Variant

          public Variant​(java.sql.Date date)

      Creates a Variant from Date value.
      Parameters:
        `date` - A Date object
      Since:
        0.8.0

    - #### Variant

          public Variant​(java.sql.Timestamp timestamp)

      Creates a Variant from Timestamp value.
      Parameters:
        `timestamp` - A Timestamp object
      Since:
        0.8.0

    - #### Variant

          public Variant​(java.util.List<java.lang.Object> list)

      Creates a Variant from a list.
      Parameters:
        `list` - A list of data
      Since:
        0.8.0

    - #### Variant

          public Variant​(java.lang.Object[] arr)

      Creates a Variant from an array.
      Parameters:
        `arr` - An array of data
      Since:
        0.8.0

    - #### Variant

          public Variant​(java.lang.Object obj)

      Creates a Variant from Object value.
      Parameters:
        `obj` - Any Java object
      Since:
        0.8.0

  - ### Method Detail

    - #### asFloat

          public float asFloat()

      Converts the variant as float value.
      Returns:
        A float number
      Since:
        0.8.0

    - #### asDouble

          public double asDouble()

      Converts the variant as double value.
      Returns:
        A double number
      Since:
        0.8.0

    - #### asShort

          public short asShort()

      Converts the variant as short value.
      Returns:
        A short number
      Since:
        0.8.0

    - #### asInt

          public int asInt()

      Converts the variant as int value.
      Returns:
        An int number
      Since:
        0.8.0

    - #### asLong

          public long asLong()

      Converts the variant as long value.
      Returns:
        A long number
      Since:
        0.8.0

    - #### asBigDecimal

          public java.math.BigDecimal asBigDecimal()

      Converts the variant as BigDecimal value.
      Returns:
        A BigDecimal number
      Since:
        0.8.0

    - #### asBigInteger

          public java.math.BigInteger asBigInteger()

      Converts the variant as BigInteger value.
      Returns:
        A BigInteger number
      Since:
        0.8.0

    - #### asString

          public java.lang.String asString()

      Converts the variant as String value.
      Returns:
        A String number
      Since:
        0.8.0

    - #### asJsonString

          public java.lang.String asJsonString()

      Converts the variant as valid Json String.
      Returns:
        A valid json string
      Since:
        0.8.0

    - #### asJsonNode

          public com.fasterxml.jackson.databind.JsonNode asJsonNode()

      Return the variant value as a JsonNode. This function allows to read the JSON object directly as JsonNode from variant column rather parsing it as String

          - to get the first value from array for key "a"

           Variant jv = new Variant("{\"a\": [1, 2], \"b\": \"c\"}");
           System.out.println(jv.asJsonNode().get("a").get(0));

           output
           1

      Returns:
        A valid JsonNode
      Since:
        1.14.0

    - #### asBinary

          public byte[] asBinary()

      Converts the variant as binary value.
      Returns:
        An array of byte representing binary data
      Since:
        0.8.0

    - #### asTime

          public java.sql.Time asTime()

      Converts the variant as Time value.
      Returns:
        A Time data
      Since:
        0.8.0

    - #### asDate

          public java.sql.Date asDate()

      Converts the variant as Date value.
      Returns:
        A Date data
      Since:
        0.8.0

    - #### asTimestamp

          public java.sql.Timestamp asTimestamp()

      Converts the variant as Timestamp value.
      Returns:
        A Timestamp data
      Since:
        0.8.0

    - #### asBoolean

          public boolean asBoolean()

      Converts the variant as boolean value.
      Returns:
        a boolean value
      Since:
        0.8.0

    - #### asArray

          public Variant[] asArray()

      Converts the variant as array of Variant.
      Returns:
        An array of Variant
      Since:
        0.8.0

    - #### asList

          public java.util.List<Variant> asList()

      Converts the variant as list of Variant.
      Returns:
        A list of Variant
      Since:
        0.8.0

    - #### asMap

          public java.util.Map<java.lang.String,​Variant> asMap()

      Converts the variant as map of Variant.
      Returns:
        A map from String to Variant
      Since:
        0.8.0

    - #### equals

          public boolean equals​(java.lang.Object other)

      Checks whether two Variants are equal.
      Overrides:
        `equals` in class `java.lang.Object`
      Returns:
        true if they are equal.
      Since:
        0.8.0

    - #### hashCode

          public int hashCode()

      Calculates the hash code of this Variant Object.
      Overrides:
        `hashCode` in class `java.lang.Object`
      Returns:
        An int number representing the hash code value
      Since:
        0.9.0

    - #### toString

          public java.lang.String toString()

      An alias of `asString()`
      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        A string data
      Since:
        0.8.0