Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,17 @@ private ArrayReverseSort(ScalarFunctionParams functionParams) {

@Override
public void checkLegalityBeforeTypeCoercion() {
DataType argType = child(0).getDataType();
if (argType.isArrayType() && (((ArrayType) argType).getItemType().isComplexType()
|| ((ArrayType) argType).getItemType().isVariantType()
|| ((ArrayType) argType).getItemType().isJsonType())) {
throw new AnalysisException("array_reverse_sort does not support types: " + argType.toSql());
if (children.get(0).getDataType() instanceof ArrayType) {
DataType argType = child(0).getDataType();
// Find the innermost element type for nested arrays
DataType itemType = ((ArrayType) argType).getItemType();
while (itemType.isArrayType()) {
itemType = ((ArrayType) itemType).getItemType();
}
if (itemType.isMapType() || itemType.isStructType()
|| itemType.isVariantType() || itemType.isJsonType()) {
throw new AnalysisException("array_reverse_sort does not support types: " + argType.toSql());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ private ArraySort(ScalarFunctionParams functionParams) {
public void checkLegalityBeforeTypeCoercion() {
if (children.get(0).getDataType() instanceof ArrayType) {
DataType argType = child(0).getDataType();
if (argType.isArrayType() && (((ArrayType) argType).getItemType().isComplexType()
|| ((ArrayType) argType).getItemType().isVariantType()
|| ((ArrayType) argType).getItemType().isJsonType())) {
// Find the innermost element type for nested arrays
DataType itemType = ((ArrayType) argType).getItemType();
while (itemType.isArrayType()) {
itemType = ((ArrayType) itemType).getItemType();
}
if (itemType.isMapType() || itemType.isStructType()
|| itemType.isVariantType() || itemType.isJsonType()) {
throw new AnalysisException("array_sort does not support types: " + argType.toSql());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,17 @@ public ArraySortBy withChildren(List<Expression> children) {

@Override
public void checkLegalityBeforeTypeCoercion() {
DataType argType = child(0).getDataType();
if (argType.isArrayType() && (((ArrayType) argType).getItemType().isComplexType()
|| ((ArrayType) argType).getItemType().isVariantType()
|| ((ArrayType) argType).getItemType().isJsonType())) {
throw new AnalysisException("array_reverse_sort does not support types: " + argType.toSql());
if (children.get(0).getDataType() instanceof ArrayType) {
DataType argType = child(0).getDataType();
// Find the innermost element type for nested arrays
DataType itemType = ((ArrayType) argType).getItemType();
while (itemType.isArrayType()) {
itemType = ((ArrayType) itemType).getItemType();
}
if (itemType.isMapType() || itemType.isStructType()
|| itemType.isVariantType() || itemType.isJsonType()) {
throw new AnalysisException("array_sortby does not support types: " + argType.toSql());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,12 @@ false
["::1", "::2", "::3"]
["::1", "::2", "::3"]

-- !sql --
[[1, 2], [3, 4]]

-- !sql --
[[1, 2], [3, 4]]

-- !sql --
[[3, 4], [1, 2]]

Original file line number Diff line number Diff line change
Expand Up @@ -445,21 +445,6 @@ suite("test_array_function_doc", "p0") {
exception "countequal does not support types: ARRAY<ARRAY<TINYINT>>"
}

test {
sql """ SELECT ARRAY_SORTBY(array(array(1, 2), array(3, 4)), array(1, 2)); """
exception "array_reverse_sort does not support types: ARRAY<ARRAY<TINYINT>>"
}

test {
sql """ SELECT ARRAY_SORT(array(array(1, 2), array(3, 4))); """
exception "array_sort does not support types: ARRAY<ARRAY<TINYINT>>"
}

test {
sql """ SELECT ARRAY_REVERSE_SORT(array(array(1, 2), array(3, 4))); """
exception "array_reverse_sort does not support types: ARRAY<ARRAY<TINYINT>>"
}

qt_sql """ SELECT ARRAY_REMOVE(ARRAY(1, 2, 3, 2, null), 2); """
qt_sql """ SELECT ARRAY_REMOVE(array_int, 2) from ${tableName}; """

Expand Down Expand Up @@ -531,4 +516,8 @@ suite("test_array_function_doc", "p0") {
qt_sql """ SELECT ARRAY_REMOVE(array_datetime, null) from ${tableName}; """
qt_sql """ SELECT ARRAY_REMOVE(array_ipv4, null) from ${tableName}; """
qt_sql """ SELECT ARRAY_REMOVE(array_ipv6, null) from ${tableName}; """

qt_sql """ SELECT ARRAY_SORTBY(x -> x[1], [[1,2],[3,4]]); """
qt_sql """ SELECT ARRAY_SORT([[1,2],[3,4]]); """
qt_sql """ SELECT ARRAY_REVERSE_SORT([[1,2],[3,4]]); """
}
Loading