Skip to content

Commit

Permalink
Merge branch 'main' into sfc-gh-sjayabalan-sma-regextract-signum-subi…
Browse files Browse the repository at this point in the history
…ndex-collectlist
  • Loading branch information
sfc-gh-mrojas authored Aug 5, 2024
2 parents e469655 + 71c3d1b commit 6a1471d
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 90 deletions.
1 change: 0 additions & 1 deletion src/test/java/com/snowflake/snowpark_test/TestBase.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.snowflake.snowpark_test;

import com.snowflake.snowpark.TestMethod;
import com.snowflake.snowpark.TestUtils;
import com.snowflake.snowpark_java.JavaToScalaConvertor;
import com.snowflake.snowpark_java.Session;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.snowflake.snowpark;
package com.snowflake.snowpark_test;

@FunctionalInterface
public interface TestMethod {
void run();
void run();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.snowflake.snowpark_test

import com.snowflake.snowpark.{SaveMode, TestData, UpdateResult}
import com.snowflake.snowpark.functions.{col, lit}

class DataFrameNonStoredProcSuite extends TestData {

private def testDataframeStatPivot(): Unit = {
assert(
getShowString(monthlySales.stat.crosstab("empid", "month").sort(col("empid")), 10) ==
"""---------------------------------------------------
||"EMPID" |"'JAN'" |"'FEB'" |"'MAR'" |"'APR'" |
|---------------------------------------------------
||1 |2 |2 |2 |2 |
||2 |2 |2 |2 |2 |
|---------------------------------------------------
|""".stripMargin)

assert(
getShowString(monthlySales.stat.crosstab("month", "empid").sort(col("month")), 10) ==
"""-------------------------------------------------------------------
||"MONTH" |"CAST(1 AS NUMBER(38,0))" |"CAST(2 AS NUMBER(38,0))" |
|-------------------------------------------------------------------
||APR |2 |2 |
||FEB |2 |2 |
||JAN |2 |2 |
||MAR |2 |2 |
|-------------------------------------------------------------------
|""".stripMargin)

assert(
getShowString(date1.stat.crosstab("a", "b").sort(col("a")), 10) ==
"""----------------------------------------------------------------------
||"A" |"CAST(1 AS NUMBER(38,0))" |"CAST(2 AS NUMBER(38,0))" |
|----------------------------------------------------------------------
||2010-12-01 |0 |1 |
||2020-08-01 |1 |0 |
|----------------------------------------------------------------------
|""".stripMargin)

assert(
getShowString(date1.stat.crosstab("b", "a").sort(col("b")), 10) ==
"""-----------------------------------------------------------
||"B" |"TO_DATE('2020-08-01')" |"TO_DATE('2010-12-01')" |
|-----------------------------------------------------------
||1 |1 |0 |
||2 |0 |1 |
|-----------------------------------------------------------
|""".stripMargin)

assert(
getShowString(string7.stat.crosstab("a", "b").sort(col("a")), 10) ==
"""----------------------------------------------------------------
||"A" |"CAST(1 AS NUMBER(38,0))" |"CAST(2 AS NUMBER(38,0))" |
|----------------------------------------------------------------
||NULL |0 |1 |
||str |1 |0 |
|----------------------------------------------------------------
|""".stripMargin)

assert(
getShowString(string7.stat.crosstab("b", "a").sort(col("b")), 10) ==
"""--------------------------
||"B" |"'str'" |"NULL" |
|--------------------------
||1 |1 |0 |
||2 |0 |0 |
|--------------------------
|""".stripMargin)
}

test("df.stat.pivot") {
testWithAlteredSessionParameter(
testDataframeStatPivot(),
"ENABLE_PIVOT_VIEW_WITH_OBJECT_AGG",
"disable",
skipIfParamNotExist = true)

testWithAlteredSessionParameter(
testDataframeStatPivot(),
"ENABLE_PIVOT_VIEW_WITH_OBJECT_AGG",
"enable",
skipIfParamNotExist = true)
}

test("ERROR_ON_NONDETERMINISTIC_UPDATE = true") {
val tableName: String = randomName()
createTable(tableName, "num int")
try {
runQuery(s"insert into $tableName values(1),(2),(3)", session)
withSessionParameters(Seq(("ERROR_ON_NONDETERMINISTIC_UPDATE", "true")), session) {
testData2.write.mode(SaveMode.Overwrite).saveAsTable(tableName)
val updatable = session.table(tableName)
testData2.write.mode(SaveMode.Overwrite).saveAsTable(tableName)
assert(
updatable.update(Map(col("a") -> lit(1), col("b") -> lit(0))) == UpdateResult(6, 0))
}
} finally {
dropTable(tableName)
}

}
}
78 changes: 0 additions & 78 deletions src/test/scala/com/snowflake/snowpark_test/DataFrameSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -469,84 +469,6 @@ trait DataFrameSuite extends TestData with BeforeAndAfterEach {
assert(double2.stat.approxQuantile(Array[String](), Array[Double]()).isEmpty)
}

private def testDataframeStatPivot() : Unit = {
assert(
getShowString(monthlySales.stat.crosstab("empid", "month").sort(col("empid")), 10) ==
"""---------------------------------------------------
||"EMPID" |"'JAN'" |"'FEB'" |"'MAR'" |"'APR'" |
|---------------------------------------------------
||1 |2 |2 |2 |2 |
||2 |2 |2 |2 |2 |
|---------------------------------------------------
|""".stripMargin)

assert(
getShowString(monthlySales.stat.crosstab("month", "empid").sort(col("month")), 10) ==
"""-------------------------------------------------------------------
||"MONTH" |"CAST(1 AS NUMBER(38,0))" |"CAST(2 AS NUMBER(38,0))" |
|-------------------------------------------------------------------
||APR |2 |2 |
||FEB |2 |2 |
||JAN |2 |2 |
||MAR |2 |2 |
|-------------------------------------------------------------------
|""".stripMargin)

assert(
getShowString(date1.stat.crosstab("a", "b").sort(col("a")), 10) ==
"""----------------------------------------------------------------------
||"A" |"CAST(1 AS NUMBER(38,0))" |"CAST(2 AS NUMBER(38,0))" |
|----------------------------------------------------------------------
||2010-12-01 |0 |1 |
||2020-08-01 |1 |0 |
|----------------------------------------------------------------------
|""".stripMargin)

assert(
getShowString(date1.stat.crosstab("b", "a").sort(col("b")), 10) ==
"""-----------------------------------------------------------
||"B" |"TO_DATE('2020-08-01')" |"TO_DATE('2010-12-01')" |
|-----------------------------------------------------------
||1 |1 |0 |
||2 |0 |1 |
|-----------------------------------------------------------
|""".stripMargin)

assert(
getShowString(string7.stat.crosstab("a", "b").sort(col("a")), 10) ==
"""----------------------------------------------------------------
||"A" |"CAST(1 AS NUMBER(38,0))" |"CAST(2 AS NUMBER(38,0))" |
|----------------------------------------------------------------
||NULL |0 |1 |
||str |1 |0 |
|----------------------------------------------------------------
|""".stripMargin)

assert(
getShowString(string7.stat.crosstab("b", "a").sort(col("b")), 10) ==
"""--------------------------
||"B" |"'str'" |"NULL" |
|--------------------------
||1 |1 |0 |
||2 |0 |0 |
|--------------------------
|""".stripMargin)
}

test("df.stat.pivot") {
testWithAlteredSessionParameter(
testDataframeStatPivot(),
"ENABLE_PIVOT_VIEW_WITH_OBJECT_AGG",
"disable",
skipIfParamNotExist = true)

testWithAlteredSessionParameter(
testDataframeStatPivot(),
"ENABLE_PIVOT_VIEW_WITH_OBJECT_AGG",
"enable",
skipIfParamNotExist = true)
}

test("df.stat.sampleBy") {
assert(
getShowString(monthlySales.stat.sampleBy(col("empid"), Map(1 -> 0.0, 2 -> 1.0)), 10) ==
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,5 @@ class UpdatableSuite extends TestData {
dropTable(tableName)
}
}

test("ERROR_ON_NONDETERMINISTIC_UPDATE = true") {
withSessionParameters(Seq(("ERROR_ON_NONDETERMINISTIC_UPDATE", "true")), session) {
testData2.write.mode(SaveMode.Overwrite).saveAsTable(tableName)
val updatable = session.table(tableName)
testData2.write.mode(SaveMode.Overwrite).saveAsTable(tableName)
assert(updatable.update(Map(col("a") -> lit(1), col("b") -> lit(0))) == UpdateResult(6, 0))
}
}
}

0 comments on commit 6a1471d

Please sign in to comment.