Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions common/utils/src/main/resources/error/error-conditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,12 @@
],
"sqlState" : "22546"
},
"HLL_K_MUST_BE_CONSTANT" : {
"message" : [
"Invalid call to <function>; the `K` value must be a constant value, but got a non-constant expression."
],
"sqlState" : "42K0E"
},
"HLL_UNION_DIFFERENT_LG_K" : {
"message" : [
"Sketches have different `lgConfigK` values: <left> and <right>. Set the `allowDifferentLgConfigK` parameter to true to call <function> with different `lgConfigK` values."
Expand Down Expand Up @@ -5730,6 +5736,12 @@
],
"sqlState" : "22546"
},
"THETA_LG_NOM_ENTRIES_MUST_BE_CONSTANT" : {
"message" : [
"Invalid call to <function>; the `lgNomEntries` value must be a constant value, but got a non-constant expression."
],
"sqlState" : "42K0E"
},
"TRAILING_COMMA_IN_SELECT" : {
"message" : [
"Trailing comma detected in SELECT clause. Remove the trailing comma before the FROM clause."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ case class HllSketchAgg(
// Hllsketch config - mark as lazy so that they're not evaluated during tree transformation.

lazy val lgConfigK: Int = {
if (!right.foldable) {
throw QueryExecutionErrors.hllKMustBeConstantError(prettyName)
}
val lgConfigK = right.eval().asInstanceOf[Int]
HllSketchAgg.checkLgK(lgConfigK)
lgConfigK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ case class ThetaSketchAgg(
// ThetaSketch config - mark as lazy so that they're not evaluated during tree transformation.

lazy val lgNomEntries: Int = {
if (!right.foldable) {
throw QueryExecutionErrors.thetaLgNomEntriesMustBeConstantError(prettyName)
}
val lgNomEntriesInput = right.eval().asInstanceOf[Int]
ThetaSketchUtils.checkLgNomLongs(lgNomEntriesInput, prettyName)
lgNomEntriesInput
Expand Down Expand Up @@ -332,6 +335,9 @@ case class ThetaUnionAgg(
// ThetaSketch config - mark as lazy so that they're not evaluated during tree transformation.

lazy val lgNomEntries: Int = {
if (!right.foldable) {
throw QueryExecutionErrors.thetaLgNomEntriesMustBeConstantError(prettyName)
}
val lgNomEntriesInput = right.eval().asInstanceOf[Int]
ThetaSketchUtils.checkLgNomLongs(lgNomEntriesInput, prettyName)
lgNomEntriesInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2804,6 +2804,12 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase with ExecutionE
"value" -> toSQLValue(value, IntegerType)))
}

def hllKMustBeConstantError(function: String): Throwable = {
new SparkRuntimeException(
errorClass = "HLL_K_MUST_BE_CONSTANT",
messageParameters = Map("function" -> toSQLId(function)))
}

def hllInvalidInputSketchBuffer(function: String): Throwable = {
new SparkRuntimeException(
errorClass = "HLL_INVALID_INPUT_SKETCH_BUFFER",
Expand Down Expand Up @@ -3169,4 +3175,10 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase with ExecutionE
"max" -> toSQLValue(max, IntegerType),
"value" -> toSQLValue(value, IntegerType)))
}

def thetaLgNomEntriesMustBeConstantError(function: String): Throwable = {
new SparkRuntimeException(
errorClass = "THETA_LG_NOM_ENTRIES_MUST_BE_CONSTANT",
messageParameters = Map("function" -> toSQLId(function)))
}
}
43 changes: 43 additions & 0 deletions sql/core/src/test/resources/sql-tests/analyzer-results/hll.sql.out
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,49 @@ Aggregate [hll_sketch_agg(col#x, 40, 0, 0) AS hll_sketch_agg(col, 40)#x]
+- LocalRelation [col#x]


-- !query
SELECT hll_sketch_agg(col, CAST(NULL AS INT)) AS k_is_null
FROM VALUES (15), (16), (17) tab(col)
-- !query analysis
Aggregate [hll_sketch_agg(col#x, cast(null as int), 0, 0) AS k_is_null#x]
+- SubqueryAlias tab
+- LocalRelation [col#x]


-- !query
SELECT hll_sketch_agg(col, CAST(col AS INT)) AS k_non_constant
FROM VALUES (15), (16), (17) tab(col)
-- !query analysis
Aggregate [hll_sketch_agg(col#x, cast(col#x as int), 0, 0) AS k_non_constant#x]
+- SubqueryAlias tab
+- LocalRelation [col#x]


-- !query
SELECT hll_sketch_agg(col, '15')
FROM VALUES (50), (60), (60) tab(col)
-- !query analysis
org.apache.spark.sql.catalyst.ExtendedAnalysisException
{
"errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE",
"sqlState" : "42K09",
"messageParameters" : {
"inputSql" : "\"15\"",
"inputType" : "\"STRING\"",
"paramIndex" : "second",
"requiredType" : "\"INT\"",
"sqlExpr" : "\"hll_sketch_agg(col, 15)\""
},
"queryContext" : [ {
"objectType" : "",
"objectName" : "",
"startIndex" : 8,
"stopIndex" : 32,
"fragment" : "hll_sketch_agg(col, '15')"
} ]
}


-- !query
SELECT hll_union(
hll_sketch_agg(col1, 12),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,49 @@ Aggregate [theta_union_agg(sketch#x, 27, 0, 0) AS theta_union_agg(sketch, 27)#x]
+- LocalRelation [col#x]


-- !query
SELECT theta_sketch_agg(col, CAST(NULL AS INT)) AS lg_nom_entries_is_null
FROM VALUES (15), (16), (17) tab(col)
-- !query analysis
Aggregate [theta_sketch_agg(col#x, cast(null as int), 0, 0) AS lg_nom_entries_is_null#x]
+- SubqueryAlias tab
+- LocalRelation [col#x]


-- !query
SELECT theta_sketch_agg(col, CAST(col AS INT)) AS lg_nom_entries_non_constant
FROM VALUES (15), (16), (17) tab(col)
-- !query analysis
Aggregate [theta_sketch_agg(col#x, cast(col#x as int), 0, 0) AS lg_nom_entries_non_constant#x]
+- SubqueryAlias tab
+- LocalRelation [col#x]


-- !query
SELECT theta_sketch_agg(col, '15')
FROM VALUES (50), (60), (60) tab(col)
-- !query analysis
org.apache.spark.sql.catalyst.ExtendedAnalysisException
{
"errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE",
"sqlState" : "42K09",
"messageParameters" : {
"inputSql" : "\"15\"",
"inputType" : "\"STRING\"",
"paramIndex" : "second",
"requiredType" : "\"INT\"",
"sqlExpr" : "\"theta_sketch_agg(col, 15)\""
},
"queryContext" : [ {
"objectType" : "",
"objectName" : "",
"startIndex" : 8,
"stopIndex" : 34,
"fragment" : "theta_sketch_agg(col, '15')"
} ]
}


-- !query
SELECT theta_union(1, 2)
FROM VALUES
Expand Down
9 changes: 9 additions & 0 deletions sql/core/src/test/resources/sql-tests/inputs/hll.sql
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ FROM VALUES (50), (60), (60) tab(col);
SELECT hll_sketch_agg(col, 40)
FROM VALUES (50), (60), (60) tab(col);

SELECT hll_sketch_agg(col, CAST(NULL AS INT)) AS k_is_null
FROM VALUES (15), (16), (17) tab(col);

SELECT hll_sketch_agg(col, CAST(col AS INT)) AS k_non_constant
FROM VALUES (15), (16), (17) tab(col);

SELECT hll_sketch_agg(col, '15')
FROM VALUES (50), (60), (60) tab(col);

SELECT hll_union(
hll_sketch_agg(col1, 12),
hll_sketch_agg(col2, 13))
Expand Down
12 changes: 12 additions & 0 deletions sql/core/src/test/resources/sql-tests/inputs/thetasketch.sql
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,18 @@ FROM (SELECT theta_sketch_agg(col, 12) as sketch
SELECT theta_sketch_agg(col, 20) as sketch
FROM VALUES (1) AS tab(col));

-- lgNomEntries parameter is NULL
SELECT theta_sketch_agg(col, CAST(NULL AS INT)) AS lg_nom_entries_is_null
FROM VALUES (15), (16), (17) tab(col);

-- lgNomEntries parameter is not foldable (non-constant)
SELECT theta_sketch_agg(col, CAST(col AS INT)) AS lg_nom_entries_non_constant
FROM VALUES (15), (16), (17) tab(col);

-- lgNomEntries parameter has wrong type (STRING instead of INT)
SELECT theta_sketch_agg(col, '15')
FROM VALUES (50), (60), (60) tab(col);

-- Test theta_union with integers (1, 2) instead of binary sketch data - should fail
SELECT theta_union(1, 2)
FROM VALUES
Expand Down
62 changes: 62 additions & 0 deletions sql/core/src/test/resources/sql-tests/results/hll.sql.out
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,68 @@ org.apache.spark.SparkRuntimeException
}


-- !query
SELECT hll_sketch_agg(col, CAST(NULL AS INT)) AS k_is_null
FROM VALUES (15), (16), (17) tab(col)
-- !query schema
struct<>
-- !query output
org.apache.spark.SparkRuntimeException
{
"errorClass" : "HLL_INVALID_LG_K",
"sqlState" : "22546",
"messageParameters" : {
"function" : "`hll_sketch_agg`",
"max" : "21",
"min" : "4",
"value" : "0"
}
}


-- !query
SELECT hll_sketch_agg(col, CAST(col AS INT)) AS k_non_constant
FROM VALUES (15), (16), (17) tab(col)
-- !query schema
struct<>
-- !query output
org.apache.spark.SparkRuntimeException
{
"errorClass" : "HLL_K_MUST_BE_CONSTANT",
"sqlState" : "42K0E",
"messageParameters" : {
"function" : "`hll_sketch_agg`"
}
}


-- !query
SELECT hll_sketch_agg(col, '15')
FROM VALUES (50), (60), (60) tab(col)
-- !query schema
struct<>
-- !query output
org.apache.spark.sql.catalyst.ExtendedAnalysisException
{
"errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE",
"sqlState" : "42K09",
"messageParameters" : {
"inputSql" : "\"15\"",
"inputType" : "\"STRING\"",
"paramIndex" : "second",
"requiredType" : "\"INT\"",
"sqlExpr" : "\"hll_sketch_agg(col, 15)\""
},
"queryContext" : [ {
"objectType" : "",
"objectName" : "",
"startIndex" : 8,
"stopIndex" : 32,
"fragment" : "hll_sketch_agg(col, '15')"
} ]
}


-- !query
SELECT hll_union(
hll_sketch_agg(col1, 12),
Expand Down
62 changes: 62 additions & 0 deletions sql/core/src/test/resources/sql-tests/results/thetasketch.sql.out
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,68 @@ org.apache.spark.SparkRuntimeException
}


-- !query
SELECT theta_sketch_agg(col, CAST(NULL AS INT)) AS lg_nom_entries_is_null
FROM VALUES (15), (16), (17) tab(col)
-- !query schema
struct<>
-- !query output
org.apache.spark.SparkRuntimeException
{
"errorClass" : "THETA_INVALID_LG_NOM_ENTRIES",
"sqlState" : "22546",
"messageParameters" : {
"function" : "`theta_sketch_agg`",
"max" : "26",
"min" : "4",
"value" : "0"
}
}


-- !query
SELECT theta_sketch_agg(col, CAST(col AS INT)) AS lg_nom_entries_non_constant
FROM VALUES (15), (16), (17) tab(col)
-- !query schema
struct<>
-- !query output
org.apache.spark.SparkRuntimeException
{
"errorClass" : "THETA_LG_NOM_ENTRIES_MUST_BE_CONSTANT",
"sqlState" : "42K0E",
"messageParameters" : {
"function" : "`theta_sketch_agg`"
}
}


-- !query
SELECT theta_sketch_agg(col, '15')
FROM VALUES (50), (60), (60) tab(col)
-- !query schema
struct<>
-- !query output
org.apache.spark.sql.catalyst.ExtendedAnalysisException
{
"errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE",
"sqlState" : "42K09",
"messageParameters" : {
"inputSql" : "\"15\"",
"inputType" : "\"STRING\"",
"paramIndex" : "second",
"requiredType" : "\"INT\"",
"sqlExpr" : "\"theta_sketch_agg(col, 15)\""
},
"queryContext" : [ {
"objectType" : "",
"objectName" : "",
"startIndex" : 8,
"stopIndex" : 34,
"fragment" : "theta_sketch_agg(col, '15')"
} ]
}


-- !query
SELECT theta_union(1, 2)
FROM VALUES
Expand Down