Package com.snowflake.snowpark_java
Class Row
- java.lang.Object
-
- com.snowflake.snowpark_java.Row
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
public class Row extends java.lang.Object implements java.io.Serializable, java.lang.CloneableRepresents a row returned by the evaluation of aDataFrame.- Since:
- 0.9.0
- See Also:
DataFram, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Row(java.lang.Object[] values)Creates aRowbased on the values in the given array.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Rowclone()Creates a clone of thisRowobject.static Rowcreate(java.lang.Object... values)Creates aRowbased on the given values.booleanequals(java.lang.Object other)Verifies the equality of twoRowobjects.intfieldIndex(java.lang.String fieldName)Returns the index of the field with the specified name.java.lang.Objectget(int index)Retrieves the value of column in theRowat the given index.<T> TgetAs(int index, java.lang.Class<T> clazz)Returns the value at the specified column index and casts it to the desired typeT.<T> TgetAs(java.lang.String fieldName, java.lang.Class<T> clazz)Returns the field value for the specified field name and casts it to the desired typeT.byte[]getBinary(int index)Retrieves the value of the column at the given index as an array of byte.booleangetBoolean(int index)Retrieves the value of the column at the given index as a boolean value.bytegetByte(int index)Retrieves the value of the column at the given index as a byte value.java.sql.DategetDate(int index)Retrieves the value of the column at the given index as a Date value.java.math.BigDecimalgetDecimal(int index)Retrieves the value of the column at the given index as a BigDecimal value.doublegetDouble(int index)Retrieves the value of the column at the given index as a double value.floatgetFloat(int index)Retrieves the value of the column at the given index as a float value.GeographygetGeography(int index)Retrieves the value of the column at the given index as a Geography value.GeometrygetGeometry(int index)Retrieves the value of the column at the given index as a Geometry value.intgetInt(int index)Retrieves the value of the column at the given index as a int value.java.util.List<?>getList(int index)Retrieves the value of the column at the given index as a list of Object.java.util.List<Variant>getListOfVariant(int index)Retrieves the value of the column at the given index as a list of Variant.longgetLong(int index)Retrieves the value of the column at the given index as a long value.java.util.Map<?,?>getMap(int index)Retrieves the value of the column at the given index as a Java Mapjava.util.Map<java.lang.String,Variant>getMapOfVariant(int index)Retrieves the value of the column at the given index as a map of VariantRowgetObject(int index)Retrieves the value of the column at the given index as a RowshortgetShort(int index)Retrieves the value of the column at the given index as a short value.java.lang.StringgetString(int index)Retrieves the value of the column at the given index as a String value.java.sql.TimegetTime(int index)Retrieves the value of the column at the given index as a Time value.java.sql.TimestampgetTimestamp(int index)Retrieves the value of the column at the given index as a Timestamp value.VariantgetVariant(int index)Retrieves the value of the column at the given index as a Variant value.inthashCode()Calculates the hash code of this Row objectbooleanisNullAt(int index)Verifies if the value of the column at the given index is null.java.lang.StringmkString()Creates a string representation of all elements in this Row without any separators.java.lang.StringmkString(java.lang.String sep)Creates a string representation of all elements in this Row using the specified separator.java.lang.StringmkString(java.lang.String start, java.lang.String sep, java.lang.String end)Creates a string representation of all elements in this Row using the specified start string, separator, and end string.intsize()Counts the number of column in thisRow.java.util.List<java.lang.Object>toList()Converts thisRowto aListofObject.java.lang.StringtoString()Generates a string value to represent the content of this row.
-
-
-
Method Detail
-
toList
public java.util.List<java.lang.Object> toList()
Converts thisRowto aListofObject.- Returns:
- A
ListcontainsRowelements. - Since:
- 0.9.0
-
size
public int size()
Counts the number of column in thisRow.- Returns:
- An integer number represents the size of this
Row - Since:
- 0.9.0
-
clone
public Row clone()
Creates a clone of thisRowobject.- Overrides:
clonein classjava.lang.Object- Returns:
- A new
Rowobject containing same elements as thisRow - Since:
- 0.9.0
-
equals
public boolean equals(java.lang.Object other)
Verifies the equality of twoRowobjects.- Overrides:
equalsin classjava.lang.Object- Parameters:
other- TheRowobject to be compared to- Returns:
- true if the given row equals this row.
- Since:
- 0.9.0
-
hashCode
public int hashCode()
Calculates the hash code of this Row object- Overrides:
hashCodein classjava.lang.Object- Returns:
- An int number representing the hash code
- Since:
- 0.9.0
-
get
public java.lang.Object get(int index)
Retrieves the value of column in theRowat the given index.- Parameters:
index- The index of the target column- Returns:
- The value of the column at the given index
-
isNullAt
public boolean isNullAt(int index)
Verifies if the value of the column at the given index is null.- Parameters:
index- The index of target column- Returns:
- true if the value is null at the given index
- Since:
- 0.9.0
-
getBoolean
public boolean getBoolean(int index)
Retrieves the value of the column at the given index as a boolean value.- Parameters:
index- The index of target column- Returns:
- The boolean value of the column at the given index
- Since:
- 0.9.0
-
getByte
public byte getByte(int index)
Retrieves the value of the column at the given index as a byte value.- Parameters:
index- The index of target column- Returns:
- The byte value of the column at the given index
- Since:
- 0.9.0
-
getShort
public short getShort(int index)
Retrieves the value of the column at the given index as a short value.- Parameters:
index- The index of target column- Returns:
- The short value of the column at the given index
- Since:
- 0.9.0
-
getInt
public int getInt(int index)
Retrieves the value of the column at the given index as a int value.- Parameters:
index- The index of target column- Returns:
- The int value of the column at the given index
- Since:
- 0.9.0
-
getLong
public long getLong(int index)
Retrieves the value of the column at the given index as a long value.- Parameters:
index- The index of target column- Returns:
- The long value of the column at the given index
- Since:
- 0.9.0
-
getFloat
public float getFloat(int index)
Retrieves the value of the column at the given index as a float value.- Parameters:
index- The index of target column- Returns:
- The float value of the column at the given index
- Since:
- 0.9.0
-
getDouble
public double getDouble(int index)
Retrieves the value of the column at the given index as a double value.- Parameters:
index- The index of target column- Returns:
- The double value of the column at the given index
- Since:
- 0.9.0
-
getString
public java.lang.String getString(int index)
Retrieves the value of the column at the given index as a String value.- Parameters:
index- The index of target column- Returns:
- The String value of the column at the given index
- Since:
- 0.9.0
-
getBinary
public byte[] getBinary(int index)
Retrieves the value of the column at the given index as an array of byte.- Parameters:
index- The index of target column- Returns:
- An array of byte representing the binary value
- Since:
- 0.9.0
-
getDate
public java.sql.Date getDate(int index)
Retrieves the value of the column at the given index as a Date value.- Parameters:
index- The index of target column- Returns:
- The Date value of the column at the given index
- Since:
- 0.9.0
-
getTime
public java.sql.Time getTime(int index)
Retrieves the value of the column at the given index as a Time value.- Parameters:
index- The index of target column- Returns:
- The Time value of the column at the given index
- Since:
- 0.9.0
-
getTimestamp
public java.sql.Timestamp getTimestamp(int index)
Retrieves the value of the column at the given index as a Timestamp value.- Parameters:
index- The index of target column- Returns:
- The Timestamp value of the column at the given index
- Since:
- 0.9.0
-
getDecimal
public java.math.BigDecimal getDecimal(int index)
Retrieves the value of the column at the given index as a BigDecimal value.- Parameters:
index- The index of target column- Returns:
- The BigDecimal value of the column at the given index
- Since:
- 0.9.0
-
getVariant
public Variant getVariant(int index)
Retrieves the value of the column at the given index as a Variant value.- Parameters:
index- The index of target column- Returns:
- The Variant value of the column at the given index
- Since:
- 0.9.0
-
getGeography
public Geography getGeography(int index)
Retrieves the value of the column at the given index as a Geography value.- Parameters:
index- The index of target column- Returns:
- The Geography value of the column at the given index
- Since:
- 0.9.0
-
getGeometry
public Geometry getGeometry(int index)
Retrieves the value of the column at the given index as a Geometry value.- Parameters:
index- The index of target column- Returns:
- The Geometry value of the column at the given index
- Since:
- 1.12.0
-
getListOfVariant
public java.util.List<Variant> getListOfVariant(int index)
Retrieves the value of the column at the given index as a list of Variant.- Parameters:
index- The index of target column- Returns:
- A list of Variant
- Since:
- 0.9.0
-
getMapOfVariant
public java.util.Map<java.lang.String,Variant> getMapOfVariant(int index)
Retrieves the value of the column at the given index as a map of Variant- Parameters:
index- The index of target column- Returns:
- A map from String to Variant
- Since:
- 0.9.0
-
getList
public java.util.List<?> getList(int index)
Retrieves the value of the column at the given index as a list of Object.- Parameters:
index- The index of target column- Returns:
- A list of Object
- Since:
- 1.13.0
-
getMap
public java.util.Map<?,?> getMap(int index)
Retrieves the value of the column at the given index as a Java Map- Parameters:
index- The index of target column- Returns:
- A Java Map
- Since:
- 1.13.0
-
getObject
public Row getObject(int index)
Retrieves the value of the column at the given index as a Row- Parameters:
index- The index of target column- Returns:
- A Row
- Since:
- 1.13.0
-
fieldIndex
public int fieldIndex(java.lang.String fieldName)
Returns the index of the field with the specified name.- Parameters:
fieldName- the name of the field.- Returns:
- the index of the specified field.
- Throws:
java.lang.UnsupportedOperationException- if schema information is not available.- Since:
- 1.15.0
-
getAs
public <T> T getAs(int index, java.lang.Class<T> clazz) throws java.lang.ClassCastException, java.lang.ArrayIndexOutOfBoundsExceptionReturns the value at the specified column index and casts it to the desired typeT.Example:
Row row = Row.create(1, "Alice", 95.5); row.getAs(0, Integer.class); // Returns 1 as an Int row.getAs(1, String.class); // Returns "Alice" as a String row.getAs(2, Double.class); // Returns 95.5 as a Double- Type Parameters:
T- the expected type of the value at the specified column index.- Parameters:
index- the zero-based column index within the row.clazz- theClassobject representing the typeT.- Returns:
- the value at the specified column index cast to type
T. - Throws:
java.lang.ClassCastException- if the value at the given index cannot be cast to typeT.java.lang.ArrayIndexOutOfBoundsException- if the column index is out of bounds.- Since:
- 1.15.0
-
getAs
public <T> T getAs(java.lang.String fieldName, java.lang.Class<T> clazz)Returns the field value for the specified field name and casts it to the desired typeT.Example:
StructType schema = StructType.create( new StructField("name", DataTypes.StringType), new StructField("val", DataTypes.IntegerType)); Row[] data = { Row.create("Alice", 1) }; DataFrame df = session.createDataFrame(data, schema); Row row = df.collect()[0]; row.getAs("name", String.class); // Returns "Alice" as a String row.getAs("val", Integer.class); // Returns 1 as an Int- Type Parameters:
T- the expected type of the value for the specified field name.- Parameters:
fieldName- the name of the field within the row.clazz- theClassobject representing the typeT.- Returns:
- the field value for the specified field name cast to type
T. - Throws:
java.lang.ClassCastException- if the value of the field cannot be cast to typeT.java.lang.IllegalArgumentException- if the name of the field is not part of the row schema.java.lang.UnsupportedOperationException- if the schema information is not available.- Since:
- 1.15.0
-
mkString
public java.lang.String mkString()
Creates a string representation of all elements in this Row without any separators.Example:
Row row = Row.create(1, "hello", 3.14, null); row.mkString(); // res: String = "1hello3.14null"- Returns:
- a string containing all field values concatenated together
- Since:
- 1.17.0
-
mkString
public java.lang.String mkString(java.lang.String sep)
Creates a string representation of all elements in this Row using the specified separator.Example:
Row row = Row.create(1, "hello", 3.14, null); row.mkString(", "); // res: String = "1, hello, 3.14, null" row.mkString(" | "); // res: String = "1 | hello | 3.14 | null" row.mkString(""); // res: String = "1hello3.14null"- Parameters:
sep- the separator string to insert between field values- Returns:
- a string containing all field values separated by the given separator
- Since:
- 1.17.0
-
mkString
public java.lang.String mkString(java.lang.String start, java.lang.String sep, java.lang.String end)Creates a string representation of all elements in this Row using the specified start string, separator, and end string.Example:
Row row = Row.create(1, "hello", 3.14, null); row.mkString("[", " | ", "]"); // res: String = "[1 | hello | 3.14 | null]" Row emptyRow = Row.create(); emptyRow.mkString("(", ", ", ")"); // res: String = "()"- Parameters:
start- the string to prepend to the resultsep- the separator string to insert between field valuesend- the string to append to the result- Returns:
- a string containing all field values formatted with the specified start, separator, and end
- Since:
- 1.17.0
-
toString
public java.lang.String toString()
Generates a string value to represent the content of this row.- Overrides:
toStringin classjava.lang.Object- Returns:
- A String value representing the content of this row
- Since:
- 0.9.0
-
create
public static Row create(java.lang.Object... values)
Creates aRowbased on the given values.- Parameters:
values- Row elements.- Returns:
- A
Rowobject. - Since:
- 0.9.0
-
-