Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-bli committed Oct 2, 2024
1 parent 6906adc commit 118d609
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class DataFrameAggregateSuite extends TestData {
// Used temporary VIEW which is not supported by owner's mode stored proc yet
test("Window functions inside aggregate functions", JavaStoredProcExcludeOwner) {
def checkWindowError(df: => DataFrame): Unit = {
assertThrows[SnowparkClientException](df.collect())
assertThrows[SnowflakeSQLException](df.collect())
}
checkWindowError(testData2.select(min(avg($"b").over(Window.partitionBy($"a")))))
checkWindowError(testData2.agg(sum($"b"), max(rank().over(Window.orderBy($"a")))))
Expand Down
27 changes: 12 additions & 15 deletions src/test/scala/com/snowflake/snowpark_test/WindowSpecSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,44 +54,41 @@ class WindowSpecSuite extends TestData {
}

test("Window functions inside WHERE and HAVING clauses") {
def checkAnalysisError[T: ClassTag](df: => DataFrame): Unit = {
assertThrows[ClassTag[T]] {
def checkAnalysisError(df: => DataFrame): Unit = {
assertThrows[SnowflakeSQLException] {
df.collect()
}
}

checkAnalysisError[SnowflakeSQLException](
testData2.select("a").where(rank().over(Window.orderBy($"b")) === 1))
checkAnalysisError[SnowflakeSQLException](
testData2.where($"b" === 2 && rank().over(Window.orderBy($"b")) === 1))
checkAnalysisError[SnowflakeSQLException](
checkAnalysisError(testData2.select("a").where(rank().over(Window.orderBy($"b")) === 1))
checkAnalysisError(testData2.where($"b" === 2 && rank().over(Window.orderBy($"b")) === 1))
checkAnalysisError(
testData2
.groupBy($"a")
.agg(avg($"b").as("avgb"))
.where($"a" > $"avgb" && rank().over(Window.orderBy($"a")) === 1))
checkAnalysisError[SnowflakeSQLException](
checkAnalysisError(
testData2
.groupBy($"a")
.agg(max($"b").as("maxb"), sum($"b").as("sumb"))
.where(rank().over(Window.orderBy($"a")) === 1))
checkAnalysisError[SnowflakeSQLException](
checkAnalysisError(
testData2
.groupBy($"a")
.agg(max($"b").as("maxb"), sum($"b").as("sumb"))
.where($"sumb" === 5 && rank().over(Window.orderBy($"a")) === 1))

testData2.createOrReplaceTempView("testData2")
checkAnalysisError[SnowflakeSQLException](
session.sql("SELECT a FROM testData2 WHERE RANK() OVER(ORDER BY b) = 1"))
checkAnalysisError[SnowflakeSQLException](
checkAnalysisError(session.sql("SELECT a FROM testData2 WHERE RANK() OVER(ORDER BY b) = 1"))
checkAnalysisError(
session.sql("SELECT * FROM testData2 WHERE b = 2 AND RANK() OVER(ORDER BY b) = 1"))
checkAnalysisError[SnowflakeSQLException](
checkAnalysisError(
session.sql(
"SELECT * FROM testData2 GROUP BY a HAVING a > AVG(b) AND RANK() OVER(ORDER BY a) = 1"))
checkAnalysisError[SnowflakeSQLException](
checkAnalysisError(
session.sql(
"SELECT a, MAX(b), SUM(b) FROM testData2 GROUP BY a HAVING RANK() OVER(ORDER BY a) = 1"))
checkAnalysisError[SnowflakeSQLException](session.sql(s"""SELECT a, MAX(b)
checkAnalysisError(session.sql(s"""SELECT a, MAX(b)
|FROM testData2
|GROUP BY a
|HAVING SUM(b) = 5 AND RANK() OVER(ORDER BY a) = 1
Expand Down

0 comments on commit 118d609

Please sign in to comment.