From 3cfa0498844e1147aa2fca0f696399d1de342f94 Mon Sep 17 00:00:00 2001 From: Bing Li Date: Thu, 1 Aug 2024 15:39:15 -0700 Subject: [PATCH] Move Pivot Tests out of BPTP --- .../DataFrameNonStoredProcSuite.scala | 85 +++++++++++++++++++ .../snowpark_test/DataFrameSuite.scala | 78 ----------------- 2 files changed, 85 insertions(+), 78 deletions(-) create mode 100644 src/test/scala/com/snowflake/snowpark_test/DataFrameNonStoredProcSuite.scala diff --git a/src/test/scala/com/snowflake/snowpark_test/DataFrameNonStoredProcSuite.scala b/src/test/scala/com/snowflake/snowpark_test/DataFrameNonStoredProcSuite.scala new file mode 100644 index 00000000..66a34b0b --- /dev/null +++ b/src/test/scala/com/snowflake/snowpark_test/DataFrameNonStoredProcSuite.scala @@ -0,0 +1,85 @@ +package com.snowflake.snowpark_test + +import com.snowflake.snowpark.TestData +import com.snowflake.snowpark.functions.col + +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) + } +} diff --git a/src/test/scala/com/snowflake/snowpark_test/DataFrameSuite.scala b/src/test/scala/com/snowflake/snowpark_test/DataFrameSuite.scala index df1dcce0..31733928 100644 --- a/src/test/scala/com/snowflake/snowpark_test/DataFrameSuite.scala +++ b/src/test/scala/com/snowflake/snowpark_test/DataFrameSuite.scala @@ -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) ==