From cea0f39cea96d06b73e862f79b54ddcf52473dd0 Mon Sep 17 00:00:00 2001 From: Chang chen Date: Tue, 13 Jan 2026 08:14:06 +0000 Subject: [PATCH 01/19] [Fix] Update artifact download path for velox-native-lib due to https://github.com/apache/incubator-gluten/pull/11120 --- .github/workflows/velox_backend_x86.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/velox_backend_x86.yml b/.github/workflows/velox_backend_x86.yml index d8e89feb271..12bc7acabe9 100644 --- a/.github/workflows/velox_backend_x86.yml +++ b/.github/workflows/velox_backend_x86.yml @@ -1508,7 +1508,7 @@ jobs: uses: actions/download-artifact@v4 with: name: velox-native-lib-centos-7-${{github.sha}} - path: ./cpp/build/releases + path: ./cpp/build/ - name: Download Arrow Jars uses: actions/download-artifact@v4 with: @@ -1565,7 +1565,7 @@ jobs: uses: actions/download-artifact@v4 with: name: velox-native-lib-centos-7-${{github.sha}} - path: ./cpp/build/releases + path: ./cpp/build/ - name: Download Arrow Jars uses: actions/download-artifact@v4 with: From c0b78485e1f16d72b268ac25e08ec6fff7095392 Mon Sep 17 00:00:00 2001 From: Chang chen Date: Thu, 8 Jan 2026 14:09:10 +0800 Subject: [PATCH 02/19] Move GlutenStreamingQuerySuite to correct package --- .../org/apache/gluten/utils/velox/VeloxTestSettings.scala | 1 + .../{execution => streaming}/GlutenStreamingQuerySuite.scala | 4 ++-- .../org/apache/gluten/utils/velox/VeloxTestSettings.scala | 1 + .../{execution => streaming}/GlutenStreamingQuerySuite.scala | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) rename gluten-ut/spark40/src/test/scala/org/apache/spark/sql/{execution => streaming}/GlutenStreamingQuerySuite.scala (94%) rename gluten-ut/spark41/src/test/scala/org/apache/spark/sql/{execution => streaming}/GlutenStreamingQuerySuite.scala (94%) diff --git a/gluten-ut/spark40/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala b/gluten-ut/spark40/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala index 2edb2611e47..614a6b70c12 100644 --- a/gluten-ut/spark40/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala +++ b/gluten-ut/spark40/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala @@ -39,6 +39,7 @@ import org.apache.spark.sql.extension.{GlutenCollapseProjectExecTransformerSuite import org.apache.spark.sql.gluten.{GlutenFallbackStrategiesSuite, GlutenFallbackSuite} import org.apache.spark.sql.hive.execution.GlutenHiveSQLQuerySuite import org.apache.spark.sql.sources._ +import org.apache.spark.sql.streaming.GlutenStreamingQuerySuite // Some settings' line length exceeds 100 // scalastyle:off line.size.limit diff --git a/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/execution/GlutenStreamingQuerySuite.scala b/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/streaming/GlutenStreamingQuerySuite.scala similarity index 94% rename from gluten-ut/spark40/src/test/scala/org/apache/spark/sql/execution/GlutenStreamingQuerySuite.scala rename to gluten-ut/spark40/src/test/scala/org/apache/spark/sql/streaming/GlutenStreamingQuerySuite.scala index bda9c97eb5d..7f7000c33cf 100644 --- a/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/execution/GlutenStreamingQuerySuite.scala +++ b/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/streaming/GlutenStreamingQuerySuite.scala @@ -14,12 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.spark.sql.execution +package org.apache.spark.sql.streaming import org.apache.spark.sql.GlutenSQLTestsTrait +import org.apache.spark.sql.execution.ColumnarShuffleExchangeExec import org.apache.spark.sql.execution.exchange.REQUIRED_BY_STATEFUL_OPERATOR import org.apache.spark.sql.execution.streaming.MemoryStream -import org.apache.spark.sql.streaming._ class GlutenStreamingQuerySuite extends StreamingQuerySuite with GlutenSQLTestsTrait { diff --git a/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala b/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala index 04d64a1d8c8..fb69ffe068a 100644 --- a/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala +++ b/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala @@ -39,6 +39,7 @@ import org.apache.spark.sql.extension.{GlutenCollapseProjectExecTransformerSuite import org.apache.spark.sql.gluten.{GlutenFallbackStrategiesSuite, GlutenFallbackSuite} import org.apache.spark.sql.hive.execution.GlutenHiveSQLQuerySuite import org.apache.spark.sql.sources._ +import org.apache.spark.sql.streaming.GlutenStreamingQuerySuite // Some settings' line length exceeds 100 // scalastyle:off line.size.limit diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/GlutenStreamingQuerySuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/streaming/GlutenStreamingQuerySuite.scala similarity index 94% rename from gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/GlutenStreamingQuerySuite.scala rename to gluten-ut/spark41/src/test/scala/org/apache/spark/sql/streaming/GlutenStreamingQuerySuite.scala index d59c0469376..87e7924ce79 100644 --- a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/GlutenStreamingQuerySuite.scala +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/streaming/GlutenStreamingQuerySuite.scala @@ -14,12 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.spark.sql.execution +package org.apache.spark.sql.streaming import org.apache.spark.sql.GlutenSQLTestsTrait +import org.apache.spark.sql.execution.ColumnarShuffleExchangeExec import org.apache.spark.sql.execution.exchange.REQUIRED_BY_STATEFUL_OPERATOR import org.apache.spark.sql.execution.streaming.runtime.MemoryStream -import org.apache.spark.sql.streaming._ class GlutenStreamingQuerySuite extends StreamingQuerySuite with GlutenSQLTestsTrait { From 26b2a5f9637f727b0c51ea33503669ed9f913c48 Mon Sep 17 00:00:00 2001 From: Chang chen Date: Thu, 8 Jan 2026 16:54:33 +0800 Subject: [PATCH 03/19] Add Spark 4.1 new test suites for Gluten --- .../sql/GlutenAddMetadataColumnsSuite.scala | 19 ++++++++++++++ .../GlutenAlwaysPersistedConfigsSuite.scala | 21 ++++++++++++++++ .../spark/sql/GlutenApproxTopKSuite.scala | 19 ++++++++++++++ .../sql/GlutenCacheTableInKryoSuite.scala | 19 ++++++++++++++ .../sql/GlutenGeographyDataFrameSuite.scala | 19 ++++++++++++++ .../sql/GlutenGeometryDataFrameSuite.scala | 19 ++++++++++++++ ...utenLegacyParameterSubstitutionSuite.scala | 21 ++++++++++++++++ .../sql/GlutenMapStatusEndToEndSuite.scala | 19 ++++++++++++++ ...erLiteralsWithOrdinalsDataframeSuite.scala | 21 ++++++++++++++++ ...eIntegerLiteralsWithOrdinalsSqlSuite.scala | 21 ++++++++++++++++ .../spark/sql/GlutenSTExpressionsSuite.scala | 19 ++++++++++++++ .../spark/sql/GlutenSTFunctionsSuite.scala | 19 ++++++++++++++ .../GlutenStringLiteralCoalescingSuite.scala | 21 ++++++++++++++++ .../sql/GlutenUnsafeRowChecksumSuite.scala | 19 ++++++++++++++ .../expressions/GlutenAttributeMapSuite.scala | 21 ++++++++++++++++ .../GlutenBindReferencesSuite.scala | 21 ++++++++++++++++ .../GlutenConstraintExpressionSuite.scala | 21 ++++++++++++++++ .../GlutenTimeExpressionsSuite.scala | 21 ++++++++++++++++ .../aggregate/GlutenApproxTopKSuite.scala | 21 ++++++++++++++++ .../GlutenThetasketchesAggSuite.scala | 21 ++++++++++++++++ .../GlutenShowNamespacesParserSuite.scala | 25 +++++++++++++++++++ .../GlutenVariantInferShreddingSuite.scala | 23 +++++++++++++++++ ...DSV2JoinPushDownAliasGenerationSuite.scala | 23 +++++++++++++++++ .../python/GlutenPythonWorkerLogsSuite.scala | 21 ++++++++++++++++ ...utenStreamRealTimeModeAllowlistSuite.scala | 23 +++++++++++++++++ .../GlutenStreamRealTimeModeE2ESuite.scala | 23 +++++++++++++++++ .../GlutenStreamRealTimeModeSuite.scala | 21 ++++++++++++++++ 27 files changed, 561 insertions(+) create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenAddMetadataColumnsSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenAlwaysPersistedConfigsSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenApproxTopKSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenCacheTableInKryoSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenGeographyDataFrameSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenGeometryDataFrameSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenLegacyParameterSubstitutionSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenMapStatusEndToEndSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenReplaceIntegerLiteralsWithOrdinalsDataframeSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenReplaceIntegerLiteralsWithOrdinalsSqlSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenSTExpressionsSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenSTFunctionsSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenStringLiteralCoalescingSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenUnsafeRowChecksumSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenAttributeMapSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenBindReferencesSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenConstraintExpressionSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenTimeExpressionsSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/aggregate/GlutenApproxTopKSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/aggregate/GlutenThetasketchesAggSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/GlutenShowNamespacesParserSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/GlutenVariantInferShreddingSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/datasources/v2/GlutenDSV2JoinPushDownAliasGenerationSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/python/GlutenPythonWorkerLogsSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/streaming/GlutenStreamRealTimeModeAllowlistSuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/streaming/GlutenStreamRealTimeModeE2ESuite.scala create mode 100644 gluten-ut/spark41/src/test/scala/org/apache/spark/sql/streaming/GlutenStreamRealTimeModeSuite.scala diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenAddMetadataColumnsSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenAddMetadataColumnsSuite.scala new file mode 100644 index 00000000000..8c2392bec97 --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenAddMetadataColumnsSuite.scala @@ -0,0 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql + +class GlutenAddMetadataColumnsSuite extends AddMetadataColumnsSuite with GlutenSQLTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenAlwaysPersistedConfigsSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenAlwaysPersistedConfigsSuite.scala new file mode 100644 index 00000000000..dea721d8a88 --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenAlwaysPersistedConfigsSuite.scala @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql + +class GlutenAlwaysPersistedConfigsSuite + extends AlwaysPersistedConfigsSuite + with GlutenSQLTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenApproxTopKSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenApproxTopKSuite.scala new file mode 100644 index 00000000000..aa8761797a8 --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenApproxTopKSuite.scala @@ -0,0 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql + +class GlutenApproxTopKSuite extends ApproxTopKSuite with GlutenSQLTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenCacheTableInKryoSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenCacheTableInKryoSuite.scala new file mode 100644 index 00000000000..5ab5e588d94 --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenCacheTableInKryoSuite.scala @@ -0,0 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql + +class GlutenCacheTableInKryoSuite extends CacheTableInKryoSuite with GlutenSQLTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenGeographyDataFrameSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenGeographyDataFrameSuite.scala new file mode 100644 index 00000000000..e458d6d9660 --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenGeographyDataFrameSuite.scala @@ -0,0 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql + +class GlutenGeographyDataFrameSuite extends GeographyDataFrameSuite with GlutenSQLTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenGeometryDataFrameSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenGeometryDataFrameSuite.scala new file mode 100644 index 00000000000..c853941ee56 --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenGeometryDataFrameSuite.scala @@ -0,0 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql + +class GlutenGeometryDataFrameSuite extends GeometryDataFrameSuite with GlutenSQLTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenLegacyParameterSubstitutionSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenLegacyParameterSubstitutionSuite.scala new file mode 100644 index 00000000000..84c0dc7d2d0 --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenLegacyParameterSubstitutionSuite.scala @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql + +class GlutenLegacyParameterSubstitutionSuite + extends LegacyParameterSubstitutionSuite + with GlutenSQLTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenMapStatusEndToEndSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenMapStatusEndToEndSuite.scala new file mode 100644 index 00000000000..5f0c3e25153 --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenMapStatusEndToEndSuite.scala @@ -0,0 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql + +class GlutenMapStatusEndToEndSuite extends MapStatusEndToEndSuite with GlutenTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenReplaceIntegerLiteralsWithOrdinalsDataframeSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenReplaceIntegerLiteralsWithOrdinalsDataframeSuite.scala new file mode 100644 index 00000000000..ce9d241b64d --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenReplaceIntegerLiteralsWithOrdinalsDataframeSuite.scala @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql + +class GlutenReplaceIntegerLiteralsWithOrdinalsDataframeSuite + extends ReplaceIntegerLiteralsWithOrdinalsDataframeSuite + with GlutenSQLTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenReplaceIntegerLiteralsWithOrdinalsSqlSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenReplaceIntegerLiteralsWithOrdinalsSqlSuite.scala new file mode 100644 index 00000000000..59120bf6708 --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenReplaceIntegerLiteralsWithOrdinalsSqlSuite.scala @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql + +class GlutenReplaceIntegerLiteralsWithOrdinalsSqlSuite + extends ReplaceIntegerLiteralsWithOrdinalsSqlSuite + with GlutenSQLTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenSTExpressionsSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenSTExpressionsSuite.scala new file mode 100644 index 00000000000..e8d3c888929 --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenSTExpressionsSuite.scala @@ -0,0 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql + +class GlutenSTExpressionsSuite extends STExpressionsSuite with GlutenSQLTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenSTFunctionsSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenSTFunctionsSuite.scala new file mode 100644 index 00000000000..78049e65dff --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenSTFunctionsSuite.scala @@ -0,0 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql + +class GlutenSTFunctionsSuite extends STFunctionsSuite with GlutenSQLTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenStringLiteralCoalescingSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenStringLiteralCoalescingSuite.scala new file mode 100644 index 00000000000..8cbd8b754b5 --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenStringLiteralCoalescingSuite.scala @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql + +class GlutenStringLiteralCoalescingSuite + extends StringLiteralCoalescingSuite + with GlutenSQLTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenUnsafeRowChecksumSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenUnsafeRowChecksumSuite.scala new file mode 100644 index 00000000000..5cd00ae3521 --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenUnsafeRowChecksumSuite.scala @@ -0,0 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql + +class GlutenUnsafeRowChecksumSuite extends UnsafeRowChecksumSuite with GlutenTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenAttributeMapSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenAttributeMapSuite.scala new file mode 100644 index 00000000000..7003bd98ef7 --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenAttributeMapSuite.scala @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql.catalyst.expressions + +import org.apache.spark.sql.GlutenTestsTrait + +class GlutenAttributeMapSuite extends AttributeMapSuite with GlutenTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenBindReferencesSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenBindReferencesSuite.scala new file mode 100644 index 00000000000..098b03d3e84 --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenBindReferencesSuite.scala @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql.catalyst.expressions + +import org.apache.spark.sql.GlutenTestsTrait + +class GlutenBindReferencesSuite extends BindReferencesSuite with GlutenTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenConstraintExpressionSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenConstraintExpressionSuite.scala new file mode 100644 index 00000000000..58949f3bedd --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenConstraintExpressionSuite.scala @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql.catalyst.expressions + +import org.apache.spark.sql.GlutenTestsTrait + +class GlutenConstraintExpressionSuite extends ConstraintExpressionSuite with GlutenTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenTimeExpressionsSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenTimeExpressionsSuite.scala new file mode 100644 index 00000000000..12a42e7e619 --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenTimeExpressionsSuite.scala @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql.catalyst.expressions + +import org.apache.spark.sql.GlutenTestsTrait + +class GlutenTimeExpressionsSuite extends TimeExpressionsSuite with GlutenTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/aggregate/GlutenApproxTopKSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/aggregate/GlutenApproxTopKSuite.scala new file mode 100644 index 00000000000..efb3727b416 --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/aggregate/GlutenApproxTopKSuite.scala @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql.catalyst.expressions.aggregate + +import org.apache.spark.sql.GlutenTestsTrait + +class GlutenApproxTopKSuite extends ApproxTopKSuite with GlutenTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/aggregate/GlutenThetasketchesAggSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/aggregate/GlutenThetasketchesAggSuite.scala new file mode 100644 index 00000000000..cbe51ebd186 --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/catalyst/expressions/aggregate/GlutenThetasketchesAggSuite.scala @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql.catalyst.expressions.aggregate + +import org.apache.spark.sql.GlutenTestsTrait + +class GlutenThetasketchesAggSuite extends ThetasketchesAggSuite with GlutenTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/GlutenShowNamespacesParserSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/GlutenShowNamespacesParserSuite.scala new file mode 100644 index 00000000000..43bb0fb03cb --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/GlutenShowNamespacesParserSuite.scala @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql.execution + +import org.apache.spark.sql.GlutenTestsTrait + +class GlutenShowNamespacesParserSuite extends ShowNamespacesParserSuite with GlutenTestsTrait { + override protected def initializeSession(): Unit = { + super[GlutenTestsTrait].initializeSession() + } +} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/GlutenVariantInferShreddingSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/GlutenVariantInferShreddingSuite.scala new file mode 100644 index 00000000000..b954b587fd0 --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/GlutenVariantInferShreddingSuite.scala @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql.execution.datasources.parquet + +import org.apache.spark.sql.GlutenSQLTestsTrait + +class GlutenVariantInferShreddingSuite + extends VariantInferShreddingSuite + with GlutenSQLTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/datasources/v2/GlutenDSV2JoinPushDownAliasGenerationSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/datasources/v2/GlutenDSV2JoinPushDownAliasGenerationSuite.scala new file mode 100644 index 00000000000..5c919c6fa7e --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/datasources/v2/GlutenDSV2JoinPushDownAliasGenerationSuite.scala @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql.execution.datasources.v2 + +import org.apache.spark.sql.GlutenTestsTrait + +class GlutenDSV2JoinPushDownAliasGenerationSuite + extends DSV2JoinPushDownAliasGenerationSuite + with GlutenTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/python/GlutenPythonWorkerLogsSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/python/GlutenPythonWorkerLogsSuite.scala new file mode 100644 index 00000000000..31261d97b1c --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/python/GlutenPythonWorkerLogsSuite.scala @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql.execution.python + +import org.apache.spark.sql.GlutenSQLTestsTrait + +class GlutenPythonWorkerLogsSuite extends PythonWorkerLogsSuite with GlutenSQLTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/streaming/GlutenStreamRealTimeModeAllowlistSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/streaming/GlutenStreamRealTimeModeAllowlistSuite.scala new file mode 100644 index 00000000000..2aaf0d8eea1 --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/streaming/GlutenStreamRealTimeModeAllowlistSuite.scala @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql.streaming + +import org.apache.spark.sql.GlutenSQLTestsTrait + +class GlutenStreamRealTimeModeAllowlistSuite + extends StreamRealTimeModeAllowlistSuite + with GlutenSQLTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/streaming/GlutenStreamRealTimeModeE2ESuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/streaming/GlutenStreamRealTimeModeE2ESuite.scala new file mode 100644 index 00000000000..c9effaf52ab --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/streaming/GlutenStreamRealTimeModeE2ESuite.scala @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql.streaming + +import org.apache.spark.sql.GlutenSQLTestsTrait + +class GlutenStreamRealTimeModeE2ESuite + extends StreamRealTimeModeE2ESuite + with GlutenSQLTestsTrait {} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/streaming/GlutenStreamRealTimeModeSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/streaming/GlutenStreamRealTimeModeSuite.scala new file mode 100644 index 00000000000..de80b65b642 --- /dev/null +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/streaming/GlutenStreamRealTimeModeSuite.scala @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql.streaming + +import org.apache.spark.sql.GlutenSQLTestsTrait + +class GlutenStreamRealTimeModeSuite extends StreamRealTimeModeSuite with GlutenSQLTestsTrait {} From 19aab2e1669e5a5392966f3baa4a8faae6c11db5 Mon Sep 17 00:00:00 2001 From: Chang chen Date: Thu, 8 Jan 2026 18:03:38 +0800 Subject: [PATCH 04/19] Enable new and existing Gluten test suites for Spark 4.1 UT --- .../utils/velox/VeloxTestSettings.scala | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala b/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala index fb69ffe068a..a8aed75f80b 100644 --- a/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala +++ b/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala @@ -21,6 +21,7 @@ import org.apache.gluten.utils.{BackendTestSettings, SQLQueryTestSettings} import org.apache.spark.GlutenSortShuffleSuite import org.apache.spark.sql._ import org.apache.spark.sql.catalyst.expressions._ +import org.apache.spark.sql.catalyst.expressions.aggregate import org.apache.spark.sql.connector._ import org.apache.spark.sql.errors.{GlutenQueryCompilationErrorsDSv2Suite, GlutenQueryCompilationErrorsSuite, GlutenQueryExecutionErrorsSuite, GlutenQueryParsingErrorsSuite} import org.apache.spark.sql.execution._ @@ -31,7 +32,7 @@ import org.apache.spark.sql.execution.datasources.json.{GlutenJsonLegacyTimePars import org.apache.spark.sql.execution.datasources.orc._ import org.apache.spark.sql.execution.datasources.parquet._ import org.apache.spark.sql.execution.datasources.text.{GlutenTextV1Suite, GlutenTextV2Suite} -import org.apache.spark.sql.execution.datasources.v2.{GlutenDataSourceV2StrategySuite, GlutenFileTableSuite, GlutenV2PredicateSuite} +import org.apache.spark.sql.execution.datasources.v2._ import org.apache.spark.sql.execution.exchange.{GlutenEnsureRequirementsSuite, GlutenValidateRequirementsSuite} import org.apache.spark.sql.execution.joins._ import org.apache.spark.sql.execution.python._ @@ -39,7 +40,7 @@ import org.apache.spark.sql.extension.{GlutenCollapseProjectExecTransformerSuite import org.apache.spark.sql.gluten.{GlutenFallbackStrategiesSuite, GlutenFallbackSuite} import org.apache.spark.sql.hive.execution.GlutenHiveSQLQuerySuite import org.apache.spark.sql.sources._ -import org.apache.spark.sql.streaming.GlutenStreamingQuerySuite +import org.apache.spark.sql.streaming._ // Some settings' line length exceeds 100 // scalastyle:off line.size.limit @@ -95,6 +96,8 @@ class VeloxTestSettings extends BackendTestSettings { enableSuite[GlutenQueryParsingErrorsSuite] enableSuite[GlutenArithmeticExpressionSuite] .exclude("SPARK-45786: Decimal multiply, divide, remainder, quot") + enableSuite[GlutenAttributeMapSuite] + enableSuite[GlutenBindReferencesSuite] enableSuite[GlutenBitwiseExpressionsSuite] enableSuite[GlutenCastWithAnsiOffSuite] .exclude( @@ -127,6 +130,7 @@ class VeloxTestSettings extends BackendTestSettings { .exclude("Shuffle") .excludeGlutenTest("Shuffle") enableSuite[GlutenConditionalExpressionSuite] + enableSuite[GlutenConstraintExpressionSuite] enableSuite[GlutenDateExpressionsSuite] // Has exception in fallback execution when we use resultDF.collect in evaluation. .exclude("TIMESTAMP_MICROS") @@ -155,6 +159,8 @@ class VeloxTestSettings extends BackendTestSettings { enableSuite[GlutenDecimalPrecisionSuite] enableSuite[GlutenGeneratorExpressionSuite] enableSuite[GlutenHashExpressionsSuite] + enableSuite[aggregate.GlutenApproxTopKSuite] + enableSuite[aggregate.GlutenThetasketchesAggSuite] enableSuite[GlutenHigherOrderFunctionsSuite] enableSuite[GlutenIntervalExpressionsSuite] enableSuite[GlutenJsonExpressionsSuite] @@ -205,6 +211,7 @@ class VeloxTestSettings extends BackendTestSettings { enableSuite[GlutenSortShuffleSuite] enableSuite[GlutenSortOrderExpressionsSuite] enableSuite[GlutenStringExpressionsSuite] + enableSuite[GlutenTimeExpressionsSuite] enableSuite[GlutenTryEvalSuite] enableSuite[VeloxAdaptiveQueryExecSuite] .includeAllGlutenTests() @@ -534,9 +541,11 @@ class VeloxTestSettings extends BackendTestSettings { // Rewrite for file locating. .exclude("Read Parquet file generated by parquet-thrift") enableSuite[GlutenParquetVectorizedSuite] + enableSuite[GlutenVariantInferShreddingSuite] enableSuite[GlutenTextV1Suite] enableSuite[GlutenTextV2Suite] enableSuite[GlutenDataSourceV2StrategySuite] + enableSuite[GlutenDSV2JoinPushDownAliasGenerationSuite] enableSuite[GlutenFileTableSuite] enableSuite[GlutenV2PredicateSuite] enableSuite[GlutenBucketingUtilsSuite] @@ -608,6 +617,7 @@ class VeloxTestSettings extends BackendTestSettings { enableSuite[GlutenReuseExchangeAndSubquerySuite] enableSuite[GlutenSameResultSuite] enableSuite[GlutenSortSuite] + enableSuite[GlutenShowNamespacesParserSuite] enableSuite[GlutenSQLAggregateFunctionSuite] // spill not supported yet. enableSuite[GlutenSQLWindowFunctionSuite] @@ -673,12 +683,16 @@ class VeloxTestSettings extends BackendTestSettings { enableSuite[GlutenSaveLoadSuite] enableSuite[GlutenTableScanSuite] enableSuite[GlutenApproxCountDistinctForIntervalsQuerySuite] + enableSuite[GlutenAddMetadataColumnsSuite] + enableSuite[GlutenAlwaysPersistedConfigsSuite] + enableSuite[GlutenApproxTopKSuite] // sql.GlutenApproxTopKSuite enableSuite[GlutenApproximatePercentileQuerySuite] enableSuite[GlutenCachedTableSuite] .exclude("A cached table preserves the partitioning and ordering of its cached SparkPlan") .exclude("InMemoryRelation statistics") // Extra ColumnarToRow is needed to transform vanilla columnar data to gluten columnar data. .exclude("SPARK-37369: Avoid redundant ColumnarToRow transition on InMemoryTableScan") + enableSuite[GlutenCacheTableInKryoSuite] enableSuite[GlutenFileSourceCharVarcharTestSuite] enableSuite[GlutenDSV2CharVarcharTestSuite] enableSuite[GlutenColumnExpressionSuite] @@ -833,6 +847,8 @@ class VeloxTestSettings extends BackendTestSettings { enableSuite[GlutenFileScanSuite] enableSuite[GlutenGeneratorFunctionSuite] .exclude("SPARK-45171: Handle evaluated nondeterministic expression") + enableSuite[GlutenGeographyDataFrameSuite] + enableSuite[GlutenGeometryDataFrameSuite] enableSuite[GlutenInjectRuntimeFilterSuite] // FIXME: yan .exclude("Merge runtime bloom filters") @@ -843,6 +859,7 @@ class VeloxTestSettings extends BackendTestSettings { // TODO: fix on Spark-4.1 introduced by https://github.com/apache/spark/pull/47856 .exclude("SPARK-49386: test SortMergeJoin (with spill by size threshold)") enableSuite[GlutenMathFunctionsSuite] + enableSuite[GlutenMapStatusEndToEndSuite] enableSuite[GlutenMetadataCacheSuite] .exclude("SPARK-16336,SPARK-27961 Suggest fixing FileNotFoundException") enableSuite[GlutenMiscFunctionsSuite] @@ -851,6 +868,8 @@ class VeloxTestSettings extends BackendTestSettings { enableSuite[GlutenProcessingTimeSuite] enableSuite[GlutenProductAggSuite] enableSuite[GlutenReplaceNullWithFalseInPredicateEndToEndSuite] + enableSuite[GlutenReplaceIntegerLiteralsWithOrdinalsDataframeSuite] + enableSuite[GlutenReplaceIntegerLiteralsWithOrdinalsSqlSuite] enableSuite[GlutenScalaReflectionRelationSuite] enableSuite[GlutenSerializationSuite] enableSuite[GlutenFileSourceSQLInsertTestSuite] @@ -885,6 +904,9 @@ class VeloxTestSettings extends BackendTestSettings { .exclude("SPARK-33687: analyze all tables in a specific database") .exclude("column stats collection for null columns") .exclude("analyze column command - result verification") + enableSuite[GlutenSTExpressionsSuite] + enableSuite[GlutenSTFunctionsSuite] + enableSuite[GlutenStringLiteralCoalescingSuite] enableSuite[GlutenSubquerySuite] .excludeByPrefix( "SPARK-26893" // Rewrite this test because it checks Spark's physical operators. @@ -900,6 +922,7 @@ class VeloxTestSettings extends BackendTestSettings { .exclude("SPARK-51738: IN subquery with struct type") enableSuite[GlutenTypedImperativeAggregateSuite] enableSuite[GlutenUnwrapCastInComparisonEndToEndSuite] + enableSuite[GlutenUnsafeRowChecksumSuite] enableSuite[GlutenXPathFunctionsSuite] enableSuite[GlutenFallbackSuite] enableSuite[GlutenHiveSQLQuerySuite] @@ -910,6 +933,7 @@ class VeloxTestSettings extends BackendTestSettings { enableSuite[GlutenDataFrameToSchemaSuite] enableSuite[GlutenDatasetUnpivotSuite] enableSuite[GlutenLateralColumnAliasSuite] + enableSuite[GlutenLegacyParameterSubstitutionSuite] enableSuite[GlutenParametersSuite] enableSuite[GlutenResolveDefaultColumnsSuite] enableSuite[GlutenSubqueryHintPropagationSuite] @@ -946,6 +970,7 @@ class VeloxTestSettings extends BackendTestSettings { .exclude("Nested Python UDF: push down deterministic FilterExec predicates") .exclude("Python UDF: no push down on non-deterministic") .exclude("Python UDF: push down on deterministic predicates after the first non-deterministic") + enableSuite[GlutenPythonWorkerLogsSuite] enableSuite[GlutenExtractPythonUDFsSuite] // Replaced with test that check for native operations .exclude("Python UDF should not break column pruning/filter pushdown -- Parquet V1") @@ -964,6 +989,9 @@ class VeloxTestSettings extends BackendTestSettings { // TODO: fix on Spark-4.1 introduced by https://github.com/apache/spark/pull/52645 .exclude("SPARK-53942: changing the number of stateless shuffle partitions via config") .exclude("SPARK-53942: stateful shuffle partitions are retained from old checkpoint") + enableSuite[GlutenStreamRealTimeModeAllowlistSuite] + enableSuite[GlutenStreamRealTimeModeE2ESuite] + enableSuite[GlutenStreamRealTimeModeSuite] enableSuite[GlutenQueryExecutionSuite] // Rewritten to set root logger level to INFO so that logs can be parsed .exclude("Logging plan changes for execution") From 5a8034c6b1de9fd321e1fdab15e3daaeb3bcbf35 Mon Sep 17 00:00:00 2001 From: Chang chen Date: Thu, 8 Jan 2026 18:19:32 +0800 Subject: [PATCH 05/19] Update workflow trigger paths to exclude Spark 4.0 and 4.1 shims directories for clickhouse backend --- .github/workflows/clickhouse_be_trigger.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/clickhouse_be_trigger.yml b/.github/workflows/clickhouse_be_trigger.yml index 9e44b1faf08..1bd803e20e4 100644 --- a/.github/workflows/clickhouse_be_trigger.yml +++ b/.github/workflows/clickhouse_be_trigger.yml @@ -19,7 +19,6 @@ name: Clickhouse Backend Trigger on: pull_request_target: paths: - - '.github/workflows/clickhouse_be_trigger.yml' - 'pom.xml' - 'backends-clickhouse/**' - 'gluten-celeborn/**' @@ -34,6 +33,11 @@ on: - 'gluten-ras/**' - 'gluten-ui/**' - 'gluten-kafka/**' + paths-ignore: + - 'shims/spark40/**' + - 'shims/spark41/**' + - 'gluten-ut/spark40/**' + - 'gluten-ut/spark41/**' jobs: add-comment: @@ -63,3 +67,4 @@ jobs: issue_number: issueNumber, body: body }); + From e7fb255369c6e136694e66d017fab7a93422c84a Mon Sep 17 00:00:00 2001 From: Chang chen Date: Fri, 9 Jan 2026 02:09:01 +0000 Subject: [PATCH 06/19] Add support for Spark 4.1 in build script --- dev/buildbundle-veloxbe.sh | 13 ++++++++++--- dev/builddeps-veloxbe.sh | 17 ++++++++++------- tools/workload/benchmark_velox/build-gluten.sh | 4 +++- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/dev/buildbundle-veloxbe.sh b/dev/buildbundle-veloxbe.sh index be70b6f8d4c..c5c6c5147c7 100755 --- a/dev/buildbundle-veloxbe.sh +++ b/dev/buildbundle-veloxbe.sh @@ -23,7 +23,10 @@ MVN_CMD="${BASEDIR}/../build/mvn" function build_for_spark { spark_version=$1 - if [ $spark_version = "4.0" ]; then + # Extract major version (e.g., "3.2" -> "3", "4.0" -> "4") + major_version=$(echo $spark_version | cut -d'.' -f1) + + if [ "$major_version" -ge 4 ]; then ${MVN_CMD} clean install -Pbackends-velox -Pspark-$spark_version -Pjava-17 -Pscala-2.13 -DskipTests else ${MVN_CMD} clean install -Pbackends-velox -Pspark-$spark_version -DskipTests @@ -46,10 +49,14 @@ cd $GLUTEN_DIR check_supported # SPARK_VERSION is defined in builddeps-veloxbe.sh +# SUPPORTED_SPARK_VERSIONS array is also defined in builddeps-veloxbe.sh if [ "$SPARK_VERSION" = "ALL" ]; then - for spark_version in 3.2 3.3 3.4 3.5 4.0 + # Filter out "ALL" from the supported versions list + for spark_version in "${SUPPORTED_SPARK_VERSIONS[@]}" do - build_for_spark $spark_version + if [ "$spark_version" != "ALL" ]; then + build_for_spark $spark_version + fi done else build_for_spark $SPARK_VERSION diff --git a/dev/builddeps-veloxbe.sh b/dev/builddeps-veloxbe.sh index dc738283867..0796b926dd4 100755 --- a/dev/builddeps-veloxbe.sh +++ b/dev/builddeps-veloxbe.sh @@ -140,15 +140,15 @@ do shift # Remove argument name from processing ;; --build_arrow=*) - BUILD_ARROW=("${arg#*=}") + BUILD_ARROW="${arg#*=}" shift # Remove argument name from processing ;; --num_threads=*) - NUM_THREADS=("${arg#*=}") + NUM_THREADS="${arg#*=}" shift # Remove argument name from processing ;; --spark_version=*) - SPARK_VERSION=("${arg#*=}") + SPARK_VERSION="${arg#*=}" shift # Remove argument name from processing ;; *) @@ -193,13 +193,16 @@ if [ "$ENABLE_VCPKG" = "ON" ]; then source ./dev/vcpkg/env.sh ${BUILD_OPTIONS} fi -if [ "$SPARK_VERSION" = "3.2" ] || [ "$SPARK_VERSION" = "3.3" ] \ - || [ "$SPARK_VERSION" = "3.4" ] || [ "$SPARK_VERSION" = "3.5" ] \ - || [ "$SPARK_VERSION" = "4.0" ] \ - || [ "$SPARK_VERSION" = "ALL" ]; then +# Supported Spark versions +SUPPORTED_SPARK_VERSIONS=("3.2" "3.3" "3.4" "3.5" "4.0" "4.1" "ALL") + +# Check if SPARK_VERSION is in the supported list +pattern=" $SPARK_VERSION " +if [[ " ${SUPPORTED_SPARK_VERSIONS[*]} " =~ $pattern ]]; then echo "Building for Spark $SPARK_VERSION" else echo "Invalid Spark version: $SPARK_VERSION" + echo "Supported versions: ${SUPPORTED_SPARK_VERSIONS[*]}" exit 1 fi diff --git a/tools/workload/benchmark_velox/build-gluten.sh b/tools/workload/benchmark_velox/build-gluten.sh index 95872b9ed8b..52e3f31e521 100755 --- a/tools/workload/benchmark_velox/build-gluten.sh +++ b/tools/workload/benchmark_velox/build-gluten.sh @@ -29,7 +29,8 @@ sudo rm -rf ${GLUTEN_HOME}/ep/build-velox/build/velox_ep/ || true spark_version=$(head -n1 $SPARK_HOME/RELEASE | awk '{print $2}') short_version=${spark_version%.*} -sed -i "s/3.2 3.3 3.4 3.5/$short_version/" $GLUTEN_HOME/dev/buildbundle-veloxbe.sh +# Set SPARK_VERSION environment variable instead of modifying the script +export SPARK_VERSION=$short_version # Update local docker image to make more cache hit for vcpkg lib binary. sudo docker pull apache/gluten:vcpkg-centos-7 @@ -41,6 +42,7 @@ sudo docker run --rm \ -v ${HOME}/.ccache:/root/.ccache \ -e http_proxy \ -e https_proxy \ + -e SPARK_VERSION=$short_version \ --workdir /root/gluten \ apache/gluten:vcpkg-centos-7 \ ./dev/package-vcpkg.sh From a04985eeaf88bdefba9affebeaeea9ed81f24704 Mon Sep 17 00:00:00 2001 From: Chang chen Date: Fri, 9 Jan 2026 08:06:51 +0000 Subject: [PATCH 07/19] Merge Spark 4.1.0 sql-tests into Gluten Spark 4.1 (three-way merge) Three-way merge performed using Git: - Base: Spark 4.0.1 (29434ea766b) - Left: Spark 4.1.0 (e221b56be7b) - Right: Gluten Spark 4.1 backends-velox Summary: - Auto-merged: 165 files - New tests added: 31 files (collations, edge cases, recursion, spatial, etc.) - Modified tests: 134 files - Deleted tests: 2 files (collations.sql -> split into 4 files, timestamp-ntz.sql) Conflicts resolved: - inputs/timestamp-ntz.sql: Right deleted + Left modified -> DELETED (per resolution rule) New test suites from Spark 4.1.0: - Collations (4 files): aliases, basic, padding-trim, string-functions - Edge cases (6 files): alias-resolution, extract-value, join-resolution, etc. - Advanced features: cte-recursion, generators, kllquantiles, thetasketch, time - Name resolution: order-by-alias, session-variable-precedence, runtime-replaceable - Spatial functions: st-functions (ANSI and non-ANSI variants) - Various resolution edge cases Total files after merge: 671 (up from 613) --- .../inputs/alias-resolution-edge-cases.sql | 17 + .../backends-velox/sql-tests/inputs/array.sql | 8 + .../sql-tests/inputs/binary.sql | 6 + .../backends-velox/sql-tests/inputs/cast.sql | 50 + .../sql-tests/inputs/collations-aliases.sql | 95 + .../sql-tests/inputs/collations-basic.sql | 215 + .../inputs/collations-padding-trim.sql | 81 + .../inputs/collations-string-functions.sql | 197 + .../sql-tests/inputs/collations.sql | 527 -- .../sql-tests/inputs/csv-functions.sql | 1 + .../sql-tests/inputs/cte-recursion.sql | 826 ++ .../backends-velox/sql-tests/inputs/cte.sql | 111 + .../sql-tests/inputs/describe.sql | 7 + .../inputs/double-quoted-identifiers.sql | 5 +- .../sql-tests/inputs/execute-immediate.sql | 160 +- .../sql-tests/inputs/explain.sql | 9 + .../extract-value-resolution-edge-cases.sql | 10 + .../sql-tests/inputs/generators.sql | 79 + .../sql-tests/inputs/group-by-alias.sql | 36 + .../sql-tests/inputs/group-by-all.sql | 32 +- .../sql-tests/inputs/group-by-ordinal.sql | 21 + .../sql-tests/inputs/group-by.sql | 13 +- .../sql-tests/inputs/grouping_set.sql | 4 + ...rder-by-recursive-type-name-resolution.sql | 143 + .../sql-tests/inputs/having.sql | 75 + .../inputs/higher-order-functions.sql | 64 +- .../backends-velox/sql-tests/inputs/hll.sql | 41 + .../inputs/identifier-clause-legacy.sql | 2 + .../sql-tests/inputs/identifier-clause.sql | 218 +- .../sql-tests/inputs/interval.sql | 5 + .../inputs/join-resolution-edge-cases.sql | 26 + .../sql-tests/inputs/kllquantiles.sql | 473 ++ .../sql-tests/inputs/literals.sql | 10 + .../sql-tests/inputs/misc-functions.sql | 3 + ...and-having-with-conflicting-attributes.sql | 134 + .../sql-tests/inputs/nonansi/st-functions.sql | 1 + .../sql-tests/inputs/order-by-alias.sql | 43 + ...d-having-on-top-of-aggregate-with-join.sql | 244 + .../sql-tests/inputs/order-by-ordinal.sql | 19 + .../sql-tests/inputs/order-by.sql | 38 + .../sql-tests/inputs/postgreSQL/with.sql | 647 +- ...eplacing-missing-expression-with-alias.sql | 33 + .../inputs/runtime-replaceable-edge-cases.sql | 2 + .../scripting/randomly_generated_scripts.sql | 6883 ++++++++++++++++ .../inputs/session-variable-precedence.sql | 17 + .../inputs/sql-session-variables.sql | 29 + .../sql-tests/inputs/sql-udf.sql | 46 + .../sql-tests/inputs/st-functions.sql | 100 + .../sql-tests/inputs/string-functions.sql | 13 + .../sql-tests/inputs/struct.sql | 9 +- .../inputs/subquery/resolution-edge-cases.sql | 70 + .../sql-tests/inputs/thetasketch.sql | 540 ++ .../backends-velox/sql-tests/inputs/time.sql | 303 + .../sql-tests/inputs/timestamp-ltz.sql | 24 + .../sql-tests/inputs/timestamp.sql | 45 + .../sql-tests/inputs/timezone.sql | 7 + .../sql-tests/inputs/try_arithmetic.sql | 4 + .../inputs/type-coercion-edge-cases.sql | 12 + .../inputs/typeCoercion/native/mapZipWith.sql | 22 +- .../union-per-child-output-deduplication.sql | 81 + .../inputs/union-resolution-edge-cases.sql | 30 + .../backends-velox/sql-tests/inputs/union.sql | 9 + .../sql-tests/inputs/using-join.sql | 6 + .../inputs/variant-field-extractions.sql | 74 + .../sql-tests/inputs/view-conf.sql | 25 + .../inputs/window-with-aggregates.sql | 186 + .../sql-tests/inputs/xml-functions.sql | 1 + .../alias-resolution-edge-cases.sql.out | 90 + .../sql-tests/results/array.sql.out | 208 + .../sql-tests/results/binary.sql.out | 20 + .../sql-tests/results/binary_base64.sql.out | 20 + .../sql-tests/results/binary_basic.sql.out | 20 + .../sql-tests/results/binary_hex.sql.out | 20 + .../results/binary_hex_discrete.sql.out | 20 + .../sql-tests/results/cast.sql.out | 362 +- .../results/collations-aliases.sql.out | 408 + .../results/collations-basic.sql.out | 1770 +++++ .../results/collations-padding-trim.sql.out | 1225 +++ .../collations-string-functions.sql.out | 2858 +++++++ .../sql-tests/results/collations.sql.out | 5834 -------------- .../sql-tests/results/csv-functions.sql.out | 26 + .../sql-tests/results/cte-recursion.sql.out | 2245 ++++++ .../sql-tests/results/cte.sql.out | 198 + .../sql-tests/results/date.sql.out | 12 +- .../datetime-formatting-invalid.sql.out | 66 +- .../datetime-formatting-legacy.sql.out | 66 +- .../sql-tests/results/datetime-legacy.sql.out | 428 +- .../results/datetime-parsing-invalid.sql.out | 4 +- .../decimalArithmeticOperations.sql.out | 4 +- .../sql-tests/results/describe.sql.out | 52 + .../double-quoted-identifiers-enabled.sql.out | 22 + .../results/double-quoted-identifiers.sql.out | 16 + .../results/execute-immediate.sql.out | 537 +- .../sql-tests/results/explain-aqe.sql.out | 51 +- .../sql-tests/results/explain.sql.out | 51 +- ...xtract-value-resolution-edge-cases.sql.out | 39 + .../sql-tests/results/generators.sql.out | 1158 +++ .../sql-tests/results/group-by-alias.sql.out | 118 + .../sql-tests/results/group-by-all.sql.out | 85 + .../results/group-by-ordinal.sql.out | 29 + .../sql-tests/results/group-by.sql.out | 106 + .../sql-tests/results/grouping_set.sql.out | 31 + ...-by-recursive-type-name-resolution.sql.out | 429 + .../sql-tests/results/having.sql.out | 299 + .../results/higher-order-functions.sql.out | 834 ++ .../sql-tests/results/hll.sql.out | 198 + .../results/identifier-clause-legacy.sql.out | 2875 +++++++ .../results/identifier-clause.sql.out | 1344 +++- .../sql-tests/results/interval.sql.out | 26 +- .../join-resolution-edge-cases.sql.out | 168 + .../results/keywords-enforced.sql.out | 18 + .../sql-tests/results/keywords.sql.out | 18 + .../sql-tests/results/kllquantiles.sql.out | 1443 ++++ .../sql-tests/results/literals.sql.out | 64 +- .../sql-tests/results/misc-functions.sql.out | 16 +- ...having-with-conflicting-attributes.sql.out | 764 ++ .../sql-tests/results/nonansi/array.sql.out | 208 + .../sql-tests/results/nonansi/cast.sql.out | 284 +- .../sql-tests/results/nonansi/date.sql.out | 6 +- .../nonansi/double-quoted-identifiers.sql.out | 16 + .../nonansi/higher-order-functions.sql.out | 834 ++ .../results/nonansi/interval.sql.out | 26 +- .../results/nonansi/keywords.sql.out | 18 + .../results/nonansi/literals.sql.out | 64 +- .../results/nonansi/st-functions.sql.out | 487 ++ .../results/nonansi/string-functions.sql.out | 88 + .../results/nonansi/timestamp.sql.out | 412 +- .../results/nonansi/try_arithmetic.sql.out | 32 + .../nonansi/try_arithmetic.sql.out.java21 | 32 + .../sql-tests/results/operators.sql.out | 6 +- .../sql-tests/results/order-by-alias.sql.out | 263 + ...ving-on-top-of-aggregate-with-join.sql.out | 2513 ++++++ .../results/order-by-ordinal.sql.out | 298 + .../sql-tests/results/order-by.sql.out | 320 + ...rse-query-correctness-old-behavior.sql.out | 80 +- .../results/parse-query-correctness.sql.out | 24 +- .../sql-tests/results/postgreSQL/date.sql.out | 6 +- .../sql-tests/results/postgreSQL/with.sql.out | 1410 +++- ...cing-missing-expression-with-alias.sql.out | 178 + .../runtime-replaceable-edge-cases.sql.out | 24 + .../randomly_generated_scripts.sql.out | 7002 +++++++++++++++++ .../session-variable-precedence.sql.out | 79 + .../results/sql-session-variables.sql.out | 182 + .../sql-tests/results/sql-udf.sql.out | 330 + .../sql-tests/results/st-functions.sql.out | 487 ++ .../results/string-functions.sql.out | 88 + .../sql-tests/results/struct.sql.out | 40 + .../subquery/resolution-edge-cases.sql.out | 179 + .../subquery/subquery-nested-data.sql.out | 12 +- .../sql-tests/results/thetasketch.sql.out | 1356 ++++ .../sql-tests/results/time.sql.out | 2379 ++++++ .../sql-tests/results/timestamp-ltz.sql.out | 184 + .../sql-tests/results/timestamp-ntz.sql.out | 154 +- .../sql-tests/results/timestamp.sql.out | 418 +- .../timestampNTZ/timestamp-ansi.sql.out | 427 +- .../results/timestampNTZ/timestamp.sql.out | 421 +- .../sql-tests/results/timezone.sql.out | 24 + .../sql-tests/results/try_arithmetic.sql.out | 32 + .../results/type-coercion-edge-cases.sql.out | 63 + .../typeCoercion/native/mapZipWith.sql.out | 40 +- ...ion-per-child-output-deduplication.sql.out | 167 + .../union-resolution-edge-cases.sql.out | 119 + .../sql-tests/results/union.sql.out | 28 + .../sql-tests/results/using-join.sql.out | 11 + .../results/variant-field-extractions.sql.out | 343 + .../sql-tests/results/view-conf.sql.out | 105 + .../results/window-with-aggregates.sql.out | 526 ++ .../sql-tests/results/xml-functions.sql.out | 26 + 168 files changed, 55661 insertions(+), 7152 deletions(-) create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/alias-resolution-edge-cases.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/collations-aliases.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/collations-basic.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/collations-padding-trim.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/collations-string-functions.sql delete mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/collations.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/cte-recursion.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/extract-value-resolution-edge-cases.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/generators.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/having-and-order-by-recursive-type-name-resolution.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/identifier-clause-legacy.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/join-resolution-edge-cases.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/kllquantiles.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/name-precedence-in-order-by-and-having-with-conflicting-attributes.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/nonansi/st-functions.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/order-by-alias.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/order-by-and-having-on-top-of-aggregate-with-join.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/replacing-missing-expression-with-alias.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/runtime-replaceable-edge-cases.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/scripting/randomly_generated_scripts.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/session-variable-precedence.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/st-functions.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/subquery/resolution-edge-cases.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/thetasketch.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/time.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/type-coercion-edge-cases.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/union-per-child-output-deduplication.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/union-resolution-edge-cases.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/variant-field-extractions.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/view-conf.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/window-with-aggregates.sql create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/alias-resolution-edge-cases.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/collations-aliases.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/collations-basic.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/collations-padding-trim.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/collations-string-functions.sql.out delete mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/collations.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/cte-recursion.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/extract-value-resolution-edge-cases.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/generators.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/having-and-order-by-recursive-type-name-resolution.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/identifier-clause-legacy.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/join-resolution-edge-cases.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/kllquantiles.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/name-precedence-in-order-by-and-having-with-conflicting-attributes.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/st-functions.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/order-by-alias.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/order-by-and-having-on-top-of-aggregate-with-join.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/replacing-missing-expression-with-alias.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/runtime-replaceable-edge-cases.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/scripting/randomly_generated_scripts.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/session-variable-precedence.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/st-functions.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/subquery/resolution-edge-cases.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/thetasketch.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/time.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/type-coercion-edge-cases.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/union-per-child-output-deduplication.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/union-resolution-edge-cases.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/variant-field-extractions.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/view-conf.sql.out create mode 100644 gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/window-with-aggregates.sql.out diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/alias-resolution-edge-cases.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/alias-resolution-edge-cases.sql new file mode 100644 index 00000000000..55e32b8f6bf --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/alias-resolution-edge-cases.sql @@ -0,0 +1,17 @@ +CREATE TABLE t1(col1 INT, col2 STRING); +CREATE TABLE t2(col1 STRUCT, a STRING); + +-- Update references to match fixed-point plan when realiasing expressions in LCA resolution +SELECT LEN(LOWER('X')) AS a, 1 AS b, b AS c GROUP BY LOWER('X') ORDER BY LOWER('X'); +SELECT LEN(LOWER('X')) AS a, 1 AS b, b AS c GROUP BY LOWER('X') HAVING LOWER('X') = 'x'; + +-- LCA referencing nested field +SELECT col1.field, field FROM VALUES(named_struct('field', 1)); +SELECT col1.field, field FROM VALUES(map('field', 1)); + +-- LCA attributes shouldn't be counted in UNRESOLVED_GROUP_BY_ALL validation +SELECT COUNT(col1) as alias, SUM(col1) + alias FROM t1 GROUP BY ALL; +SELECT COUNT(col1) as alias, SUM(col1) + alias, SUM(col1) + col1 FROM t1 GROUP BY ALL; + +DROP TABLE t1; +DROP TABLE t2; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/array.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/array.sql index 865dc8bac4e..e923c3cdc36 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/array.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/array.sql @@ -129,6 +129,14 @@ select get(array(1, 2, 3), 0); select get(array(1, 2, 3), 3); select get(array(1, 2, 3), null); select get(array(1, 2, 3), -1); +select get(1, 0); +select get(1, -1); +select get('1', 0); +select get('1', -1); +select get(null, 0); +select get(null, -1); +select get(null, null); +select get(CAST (null AS string), 0); -- function array_insert() select array_insert(array(1, 2, 3), 3, 4); diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/binary.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/binary.sql index 8da97e46634..b30c57a7e87 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/binary.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/binary.sql @@ -6,3 +6,9 @@ SELECT CAST('Spark' as BINARY); SELECT array( X'', X'4561736F6E2059616F20323031382D31312D31373A31333A33333A3333', CAST('Spark' as BINARY)); SELECT to_csv(named_struct('n', 1, 'info', X'4561736F6E2059616F20323031382D31312D31373A31333A33333A3333')); select to_xml(named_struct('name', binary('Eason'), 'birth', 2018, 'org', binary('Kindergarten Cop'))); +SELECT from_xml( + to_xml(named_struct('name', binary('Eason'), 'birth', 2018, 'org', binary('Kindergarten Cop'))), + 'name STRING, birth INT, org STRING'); +SELECT from_xml( + to_xml(named_struct('name', binary('Eason'), 'birth', 2018, 'org', binary('Kindergarten Cop'))), + 'name binary, birth INT, org binary'); diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/cast.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/cast.sql index 2bf53f9730b..9d191dff670 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/cast.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/cast.sql @@ -147,6 +147,27 @@ select cast(80.654321BD as interval hour to minute); select cast(-10.123456BD as interval year to month); select cast(10.654321BD as interval month); +-- cast TIME to integral types +SELECT CAST(TIME '00:01:52' AS tinyint); +SELECT CAST(TIME '00:01:52' AS smallint); +SELECT CAST(TIME '00:01:52' AS int); +SELECT CAST(TIME '00:01:52' AS bigint); + +-- cast TIME to integral types with potential overflow +SELECT CAST(TIME '23:59:59' AS tinyint); +SELECT CAST(TIME '23:59:59' AS smallint); +SELECT CAST(TIME '23:59:59' AS int); +SELECT CAST(TIME '23:59:59' AS bigint); + +-- cast TIME with fractional seconds (should floor) +SELECT CAST(TIME '00:00:17.5' AS tinyint); +SELECT CAST(TIME '00:00:17.5' AS int); +SELECT CAST(TIME '00:00:17.9' AS int); + +-- cast TIME edge cases +SELECT CAST(TIME '00:00:00' AS tinyint); +SELECT CAST(TIME '00:00:00' AS int); + -- cast double colon syntax tests SELECT '1.23' :: int; SELECT 'abc' :: int; @@ -168,6 +189,12 @@ select -10L :: interval second; select interval '08:11:10.001' hour to second :: decimal(10, 4); select 10.123456BD :: interval day to second; +-- cast TIME using double colon syntax +SELECT TIME '00:01:52' :: tinyint; +SELECT TIME '00:01:52' :: int; +SELECT TIME '23:59:59' :: tinyint; +SELECT TIME '23:59:59' :: int; + SELECT '1.23' :: int :: long; SELECT '2147483648' :: long :: int; SELECT CAST('2147483648' :: long AS int); @@ -177,3 +204,26 @@ SELECT map(1, '123', 2, '456')[1] :: int; SELECT '2147483648' :: BINT; SELECT '2147483648' :: SELECT; SELECT FALSE IS NOT NULL :: string; + +-- SPARK-52619: cast TIME to DECIMAL with sufficient precision and scale. +SELECT CAST(time '00:00:00' AS decimal(1, 0)); +SELECT CAST(time '12:00:00' AS decimal(7, 2)); +SELECT CAST(time '01:30:45' AS decimal(8, 3)); +SELECT CAST(time '23:59:59' AS decimal(9, 4)); +SELECT CAST(time '01:02:03' AS decimal(15, 9)); +SELECT CAST(time '10:20:30' AS decimal(20, 10)); +SELECT CAST(time '23:59:59.001' AS decimal(8, 3)); +SELECT CAST(time '23:59:59.999999' AS decimal(11, 6)); +SELECT CAST(time '23:59:59.999999999' AS decimal(14, 9)); +SELECT CAST(time '23:59:59.999999999' AS decimal(20, 10)); + +-- SPARK-52619: cast TIME to DECIMAL with insufficient precision. +SELECT CAST(time '00:01:00' AS decimal(1, 0)); +SELECT CAST(time '01:00:00' AS decimal(3, 0)); +SELECT CAST(time '10:00:00' AS decimal(5, 2)); + +-- SPARK-52619: cast TIME to DECIMAL with insufficient scale. +SELECT CAST(time '23:59:59.9' AS decimal(6, 0)); +SELECT CAST(time '23:59:59.999' AS decimal(8, 2)); +SELECT CAST(time '23:59:59.999999' AS decimal(11, 5)); +SELECT CAST(time '23:59:59.999999999' AS decimal(14, 8)); diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/collations-aliases.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/collations-aliases.sql new file mode 100644 index 00000000000..307c77333eb --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/collations-aliases.sql @@ -0,0 +1,95 @@ +-- test cases for implicit aliases to collated expression trees are correctly generated + +create table t1(s string, utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet; +insert into t1 values ('Spark', 'Spark', 'SQL'); +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaAAaA'); +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaaAaA'); +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaaAaAaaAaaAaAaaAaaAaA'); +insert into t1 values ('bbAbaAbA', 'bbAbAAbA', 'a'); +insert into t1 values ('İo', 'İo', 'İo'); +insert into t1 values ('İo', 'İo', 'İo '); +insert into t1 values ('İo', 'İo ', 'İo'); +insert into t1 values ('İo', 'İo', 'i̇o'); +insert into t1 values ('efd2', 'efd2', 'efd2'); +insert into t1 values ('Hello, world! Nice day.', 'Hello, world! Nice day.', 'Hello, world! Nice day.'); +insert into t1 values ('Something else. Nothing here.', 'Something else. Nothing here.', 'Something else. Nothing here.'); +insert into t1 values ('kitten', 'kitten', 'sitTing'); +insert into t1 values ('abc', 'abc', 'abc'); +insert into t1 values ('abcdcba', 'abcdcba', 'aBcDCbA'); + +-- Simple select +select concat_ws(' ', utf8_lcase, utf8_lcase) from t1; + +-- Select by implicit alias +select `concat_ws(' ' collate UTF8_LCASE, utf8_lcase, utf8_lcase)` from ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 +); + +-- Select by star +select * from ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 +); + +-- Select by qualified star +select subq1.* from ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 +) AS subq1; + +-- Implicit alias in CTE output +with cte as ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 +) +select * from cte; + +-- Implicit alias in EXISTS subquery output +select * from values (1) where exists ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 +); + +-- Implicit alias in scalar subquery output +select ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 limit 1 +); + +-- Scalar subquery with CTE with implicit alias +select ( + with cte as ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 + ) + select * from cte limit 1 +); + +-- Outer reference to implicit alias +select * from ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 limit 1 +) +where ( + `concat_ws(' ' collate UTF8_LCASE, utf8_lcase, utf8_lcase)` == 'aaa' +); + +-- Implicit alias reference in Sort +select lower(`concat_ws(' ' collate UTF8_LCASE, utf8_lcase, utf8_lcase)`) from ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 + group by 1 + order by 1 +); + +-- Implciit alias from aggregate in Sort +select lower(`concat_ws(' ' collate UTF8_LCASE, utf8_lcase, utf8_lcase)`) from ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 + group by 1 + order by max(concat_ws(' ', utf8_lcase, utf8_lcase)) +); + +-- Implicit alias in view schema +create temporary view v1 as ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 +); + +select * from v1; + +select `concat_ws(' ' collate UTF8_LCASE, utf8_lcase, utf8_lcase)` from v1; + +drop view v1; + +drop table t1; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/collations-basic.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/collations-basic.sql new file mode 100644 index 00000000000..6ff3ef4f4ad --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/collations-basic.sql @@ -0,0 +1,215 @@ +-- test cases for collation support + +-- Create a test table with data +create table t1(utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet; +insert into t1 values('aaa', 'aaa'); +insert into t1 values('AAA', 'AAA'); +insert into t1 values('bbb', 'bbb'); +insert into t1 values('BBB', 'BBB'); + +-- describe +describe table t1; + +-- group by and count utf8_binary +select count(*) from t1 group by utf8_binary; + +-- group by and count utf8_lcase +select count(*) from t1 group by utf8_lcase; + +-- filter equal utf8_binary +select * from t1 where utf8_binary = 'aaa'; + +-- filter equal utf8_lcase +select * from t1 where utf8_lcase = 'aaa' collate utf8_lcase; + +-- filter less then utf8_binary +select * from t1 where utf8_binary < 'bbb'; + +-- filter less then utf8_lcase +select * from t1 where utf8_lcase < 'bbb' collate utf8_lcase; + +-- inner join +select l.utf8_binary, r.utf8_lcase from t1 l join t1 r on l.utf8_lcase = r.utf8_lcase; + +-- create second table for anti-join +create table t2(utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet; +insert into t2 values('aaa', 'aaa'); +insert into t2 values('bbb', 'bbb'); + +-- anti-join on lcase +select * from t1 anti join t2 on t1.utf8_lcase = t2.utf8_lcase; + +drop table t2; +drop table t1; + +-- set operations +select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') except select col1 collate utf8_lcase from values ('aaa'), ('bbb'); +select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') except all select col1 collate utf8_lcase from values ('aaa'), ('bbb'); +select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') union select col1 collate utf8_lcase from values ('aaa'), ('bbb'); +select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') union all select col1 collate utf8_lcase from values ('aaa'), ('bbb'); +select col1 collate utf8_lcase from values ('aaa'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') intersect select col1 collate utf8_lcase from values ('aaa'), ('bbb'); + +-- set operations with conflicting collations +select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') except select col1 collate unicode_ci from values ('aaa'), ('bbb'); +select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') except all select col1 collate unicode_ci from values ('aaa'), ('bbb'); +select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') union select col1 collate unicode_ci from values ('aaa'), ('bbb'); +select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') union all select col1 collate unicode_ci from values ('aaa'), ('bbb'); +select col1 collate utf8_lcase from values ('aaa'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') intersect select col1 collate unicode_ci from values ('aaa'), ('bbb'); + +-- create table with struct field +create table t1 (c1 struct) USING PARQUET; + +insert into t1 values (named_struct('utf8_binary', 'aaa', 'utf8_lcase', 'aaa')); +insert into t1 values (named_struct('utf8_binary', 'AAA', 'utf8_lcase', 'AAA')); + +-- aggregate against nested field utf8_binary +select count(*) from t1 group by c1.utf8_binary; + +-- aggregate against nested field utf8_lcase +select count(*) from t1 group by c1.utf8_lcase; + +drop table t1; + +-- array function tests +select array_contains(ARRAY('aaa' collate utf8_lcase),'AAA' collate utf8_lcase); +select array_position(ARRAY('aaa' collate utf8_lcase, 'bbb' collate utf8_lcase),'BBB' collate utf8_lcase); + +-- utility +select nullif('aaa' COLLATE utf8_lcase, 'AAA' COLLATE utf8_lcase); +select least('aaa' COLLATE utf8_lcase, 'AAA' collate utf8_lcase, 'a' collate utf8_lcase); + +-- array operations +select arrays_overlap(array('aaa' collate utf8_lcase), array('AAA' collate utf8_lcase)); +select array_distinct(array('aaa' collate utf8_lcase, 'AAA' collate utf8_lcase)); +select array_union(array('aaa' collate utf8_lcase), array('AAA' collate utf8_lcase)); +select array_intersect(array('aaa' collate utf8_lcase), array('AAA' collate utf8_lcase)); +select array_except(array('aaa' collate utf8_lcase), array('AAA' collate utf8_lcase)); + +-- ICU collations (all statements return true) +select 'a' collate unicode < 'A'; +select 'a' collate unicode_ci = 'A'; +select 'a' collate unicode_ai = 'å'; +select 'a' collate unicode_ci_ai = 'Å'; +select 'a' collate en < 'A'; +select 'a' collate en_ci = 'A'; +select 'a' collate en_ai = 'å'; +select 'a' collate en_ci_ai = 'Å'; +select 'Kypper' collate sv < 'Köpfe'; +select 'Kypper' collate de > 'Köpfe'; +select 'I' collate tr_ci = 'ı'; + +-- create table for str_to_map +create table t3 (text string collate utf8_binary, pairDelim string collate utf8_lcase, keyValueDelim string collate utf8_binary) using parquet; + +insert into t3 values('a:1,b:2,c:3', ',', ':'); + +select str_to_map(text, pairDelim, keyValueDelim) from t3; +select str_to_map(text collate utf8_binary, pairDelim collate utf8_lcase, keyValueDelim collate utf8_binary) from t3; +select str_to_map(text collate utf8_binary, pairDelim collate utf8_binary, keyValueDelim collate utf8_binary) from t3; +select str_to_map(text collate unicode_ai, pairDelim collate unicode_ai, keyValueDelim collate unicode_ai) from t3; + +drop table t3; + +create table t1(s string, utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet; +insert into t1 values ('Spark', 'Spark', 'SQL'); +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaAAaA'); +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaaAaA'); +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaaAaAaaAaaAaAaaAaaAaA'); +insert into t1 values ('bbAbaAbA', 'bbAbAAbA', 'a'); +insert into t1 values ('İo', 'İo', 'İo'); +insert into t1 values ('İo', 'İo', 'İo '); +insert into t1 values ('İo', 'İo ', 'İo'); +insert into t1 values ('İo', 'İo', 'i̇o'); +insert into t1 values ('efd2', 'efd2', 'efd2'); +insert into t1 values ('Hello, world! Nice day.', 'Hello, world! Nice day.', 'Hello, world! Nice day.'); +insert into t1 values ('Something else. Nothing here.', 'Something else. Nothing here.', 'Something else. Nothing here.'); +insert into t1 values ('kitten', 'kitten', 'sitTing'); +insert into t1 values ('abc', 'abc', 'abc'); +insert into t1 values ('abcdcba', 'abcdcba', 'aBcDCbA'); + +create table t2(ascii double) using parquet; +insert into t2 values (97.52143); +insert into t2 values (66.421); + +create table t3(utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet; +insert into t3 values ('aaAaAAaA', 'aaAaaAaA'); +insert into t3 values ('efd2', 'efd2'); + +create table t4(num long) using parquet; +insert into t4 values (97); +insert into t4 values (66); + +-- Elt +select elt(2, s, utf8_binary) from t1; +select elt(2, utf8_binary, utf8_lcase, s) from t1; +select elt(1, utf8_binary collate utf8_binary, utf8_lcase collate utf8_lcase) from t1; +select elt(1, utf8_binary collate utf8_binary, utf8_lcase collate utf8_binary) from t1; +select elt(1, utf8_binary collate utf8_binary, utf8_lcase) from t1; +select elt(1, utf8_binary, 'word'), elt(1, utf8_lcase, 'word') from t1; +select elt(1, utf8_binary, 'word' collate utf8_lcase), elt(1, utf8_lcase, 'word' collate utf8_binary) from t1; + +-- Ascii & UnBase64 string expressions +select ascii(utf8_binary), ascii(utf8_lcase) from t1; +select ascii(utf8_binary collate utf8_lcase), ascii(utf8_lcase collate utf8_binary) from t1; +select unbase64(utf8_binary), unbase64(utf8_lcase) from t3; +select unbase64(utf8_binary collate utf8_lcase), unbase64(utf8_lcase collate utf8_binary) from t3; + +-- Base64, Decode +select base64(utf8_binary), base64(utf8_lcase) from t1; +select base64(utf8_binary collate utf8_lcase), base64(utf8_lcase collate utf8_binary) from t1; +select decode(encode(utf8_binary, 'utf-8'), 'utf-8'), decode(encode(utf8_lcase, 'utf-8'), 'utf-8') from t1; +select decode(encode(utf8_binary collate utf8_lcase, 'utf-8'), 'utf-8'), decode(encode(utf8_lcase collate utf8_binary, 'utf-8'), 'utf-8') from t1; + +-- FormatNumber +select format_number(ascii, '###.###') from t2; +select format_number(ascii, '###.###' collate utf8_lcase) from t2; + +-- Encode, ToBinary +select encode(utf8_binary, 'utf-8'), encode(utf8_lcase, 'utf-8') from t1; +select encode(utf8_binary collate utf8_lcase, 'utf-8'), encode(utf8_lcase collate utf8_binary, 'utf-8') from t1; +select to_binary(utf8_binary, 'utf-8'), to_binary(utf8_lcase, 'utf-8') from t1; +select to_binary(utf8_binary collate utf8_lcase, 'utf-8'), to_binary(utf8_lcase collate utf8_binary, 'utf-8') from t1; + +-- SoundEx +select soundex(utf8_binary), soundex(utf8_lcase) from t1; +select soundex(utf8_binary collate utf8_lcase), soundex(utf8_lcase collate utf8_binary) from t1; + +-- Luhncheck +select luhn_check(num) from t4; + +-- Levenshtein +select levenshtein(utf8_binary, utf8_lcase) from t1; +select levenshtein(s, utf8_binary) from t1; +select levenshtein(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1; +select levenshtein(utf8_binary, utf8_lcase collate utf8_binary) from t1; +select levenshtein(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t1; +select levenshtein(utf8_binary, 'a'), levenshtein(utf8_lcase, 'a') from t1; +select levenshtein(utf8_binary, 'AaAA' collate utf8_lcase, 3), levenshtein(utf8_lcase, 'AAa' collate utf8_binary, 4) from t1; + +-- IsValidUTF8 +select is_valid_utf8(utf8_binary), is_valid_utf8(utf8_lcase) from t1; +select is_valid_utf8(utf8_binary collate utf8_lcase), is_valid_utf8(utf8_lcase collate utf8_binary) from t1; +select is_valid_utf8(utf8_binary collate utf8_lcase_rtrim), is_valid_utf8(utf8_lcase collate utf8_binary_rtrim) from t1; + +-- MakeValidUTF8 +select make_valid_utf8(utf8_binary), make_valid_utf8(utf8_lcase) from t1; +select make_valid_utf8(utf8_binary collate utf8_lcase), make_valid_utf8(utf8_lcase collate utf8_binary) from t1; +select make_valid_utf8(utf8_binary collate utf8_lcase_rtrim), make_valid_utf8(utf8_lcase collate utf8_binary_rtrim) from t1; + +-- ValidateUTF8 +select validate_utf8(utf8_binary), validate_utf8(utf8_lcase) from t1; +select validate_utf8(utf8_binary collate utf8_lcase), validate_utf8(utf8_lcase collate utf8_binary) from t1; +select validate_utf8(utf8_binary collate utf8_lcase_rtrim), validate_utf8(utf8_lcase collate utf8_binary_rtrim) from t1; + +-- TryValidateUTF8 +select try_validate_utf8(utf8_binary), try_validate_utf8(utf8_lcase) from t1; +select try_validate_utf8(utf8_binary collate utf8_lcase), try_validate_utf8(utf8_lcase collate utf8_binary) from t1; +select try_validate_utf8(utf8_binary collate utf8_lcase_rtrim), try_validate_utf8(utf8_lcase collate utf8_binary_rtrim) from t1; + +-- Apply CollationTypeCoercion to condition expressions +SELECT CASE WHEN utf8_lcase = 'XX' THEN 'XX' ELSE utf8_lcase END FROM t1; + +drop table t1; +drop table t2; +drop table t3; +drop table t4; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/collations-padding-trim.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/collations-padding-trim.sql new file mode 100644 index 00000000000..b86438d117d --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/collations-padding-trim.sql @@ -0,0 +1,81 @@ +-- test cases for padding and trimming with collations + +create table t1(s string, utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet; +insert into t1 values ('Spark', 'Spark', 'SQL'); +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaAAaA'); +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaaAaA'); +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaaAaAaaAaaAaAaaAaaAaA'); +insert into t1 values ('bbAbaAbA', 'bbAbAAbA', 'a'); +insert into t1 values ('İo', 'İo', 'İo'); +insert into t1 values ('İo', 'İo', 'İo '); +insert into t1 values ('İo', 'İo ', 'İo'); +insert into t1 values ('İo', 'İo', 'i̇o'); +insert into t1 values ('efd2', 'efd2', 'efd2'); +insert into t1 values ('Hello, world! Nice day.', 'Hello, world! Nice day.', 'Hello, world! Nice day.'); +insert into t1 values ('Something else. Nothing here.', 'Something else. Nothing here.', 'Something else. Nothing here.'); +insert into t1 values ('kitten', 'kitten', 'sitTing'); +insert into t1 values ('abc', 'abc', 'abc'); +insert into t1 values ('abcdcba', 'abcdcba', 'aBcDCbA'); + +-- StringRPad +select rpad(utf8_binary, 8, utf8_lcase) from t1; +select rpad(s, 8, utf8_binary) from t1; +select rpad(utf8_binary collate utf8_binary, 8, s collate utf8_lcase) from t1; +select rpad(utf8_binary, 8, utf8_lcase collate utf8_binary) from t1; +select rpad(utf8_binary collate utf8_lcase, 8, utf8_lcase collate utf8_lcase) from t1; +select lpad(utf8_binary collate utf8_binary_rtrim, 8, utf8_lcase collate utf8_binary_rtrim) from t1; +select rpad(utf8_binary, 8, 'a'), rpad(utf8_lcase, 8, 'a') from t1; +select rpad(utf8_binary, 8, 'AaAA' collate utf8_lcase), rpad(utf8_lcase, 8, 'AAa' collate utf8_binary) from t1; + +-- StringLPad +select lpad(utf8_binary, 8, utf8_lcase) from t1; +select lpad(s, 8, utf8_binary) from t1; +select lpad(utf8_binary collate utf8_binary, 8, s collate utf8_lcase) from t1; +select lpad(utf8_binary, 8, utf8_lcase collate utf8_binary) from t1; +select lpad(utf8_binary collate utf8_lcase, 8, utf8_lcase collate utf8_lcase) from t1; +select lpad(utf8_binary collate utf8_binary_rtrim, 8, utf8_lcase collate utf8_binary_rtrim) from t1; +select lpad(utf8_binary, 8, 'a'), lpad(utf8_lcase, 8, 'a') from t1; +select lpad(utf8_binary, 8, 'AaAA' collate utf8_lcase), lpad(utf8_lcase, 8, 'AAa' collate utf8_binary) from t1; + +-- StringTrim +select TRIM(utf8_binary, utf8_lcase) from t1; +select TRIM(s, utf8_binary) from t1; +select TRIM(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1; +select TRIM(utf8_binary, utf8_lcase collate utf8_binary) from t1; +select TRIM(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t1; +select TRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t1; +select TRIM(utf8_binary collate utf8_binary_rtrim, utf8_lcase collate utf8_binary_rtrim) from t1; +select TRIM('ABc', utf8_binary), TRIM('ABc', utf8_lcase) from t1; +select TRIM('ABc' collate utf8_lcase, utf8_binary), TRIM('AAa' collate utf8_binary, utf8_lcase) from t1; +-- StringTrimBoth +select BTRIM(utf8_binary, utf8_lcase) from t1; +select BTRIM(s, utf8_binary) from t1; +select BTRIM(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1; +select BTRIM(utf8_binary, utf8_lcase collate utf8_binary) from t1; +select BTRIM(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t1; +select BTRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t1; +select BTRIM(utf8_binary collate utf8_binary_rtrim, utf8_lcase collate utf8_binary_rtrim) from t1; +select BTRIM('ABc', utf8_binary), BTRIM('ABc', utf8_lcase) from t1; +select BTRIM('ABc' collate utf8_lcase, utf8_binary), BTRIM('AAa' collate utf8_binary, utf8_lcase) from t1; +-- StringTrimLeft +select LTRIM(utf8_binary, utf8_lcase) from t1; +select LTRIM(s, utf8_binary) from t1; +select LTRIM(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1; +select LTRIM(utf8_binary, utf8_lcase collate utf8_binary) from t1; +select LTRIM(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t1; +select LTRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t1; +select LTRIM(utf8_binary collate utf8_binary_rtrim, utf8_lcase collate utf8_binary_rtrim) from t1; +select LTRIM('ABc', utf8_binary), LTRIM('ABc', utf8_lcase) from t1; +select LTRIM('ABc' collate utf8_lcase, utf8_binary), LTRIM('AAa' collate utf8_binary, utf8_lcase) from t1; +-- StringTrimRight +select RTRIM(utf8_binary, utf8_lcase) from t1; +select RTRIM(s, utf8_binary) from t1; +select RTRIM(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1; +select RTRIM(utf8_binary, utf8_lcase collate utf8_binary) from t1; +select RTRIM(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t1; +select RTRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t1; +select RTRIM(utf8_binary collate utf8_binary_rtrim, utf8_lcase collate utf8_binary_rtrim) from t1; +select RTRIM('ABc', utf8_binary), RTRIM('ABc', utf8_lcase) from t1; +select RTRIM('ABc' collate utf8_lcase, utf8_binary), RTRIM('AAa' collate utf8_binary, utf8_lcase) from t1; + +drop table t1; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/collations-string-functions.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/collations-string-functions.sql new file mode 100644 index 00000000000..0fb73f9978a --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/collations-string-functions.sql @@ -0,0 +1,197 @@ +-- test cases for string functions with collations + +create table t1(s string, utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet; +insert into t1 values ('Spark', 'Spark', 'SQL'); +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaAAaA'); +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaaAaA'); +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaaAaAaaAaaAaAaaAaaAaA'); +insert into t1 values ('bbAbaAbA', 'bbAbAAbA', 'a'); +insert into t1 values ('İo', 'İo', 'İo'); +insert into t1 values ('İo', 'İo', 'İo '); +insert into t1 values ('İo', 'İo ', 'İo'); +insert into t1 values ('İo', 'İo', 'i̇o'); +insert into t1 values ('efd2', 'efd2', 'efd2'); +insert into t1 values ('Hello, world! Nice day.', 'Hello, world! Nice day.', 'Hello, world! Nice day.'); +insert into t1 values ('Something else. Nothing here.', 'Something else. Nothing here.', 'Something else. Nothing here.'); +insert into t1 values ('kitten', 'kitten', 'sitTing'); +insert into t1 values ('abc', 'abc', 'abc'); +insert into t1 values ('abcdcba', 'abcdcba', 'aBcDCbA'); + +create table t2(ascii long) using parquet; +insert into t2 values (97); +insert into t2 values (66); + +create table t3(format string collate utf8_binary, utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet; +insert into t3 values ('%s%s', 'abCdE', 'abCdE'); + +-- ConcatWs +select concat_ws(' ', utf8_lcase, utf8_lcase) from t1; +select concat_ws(' ', utf8_binary, utf8_lcase) from t1; +select concat_ws(' ' collate utf8_binary, utf8_binary, 'SQL' collate utf8_lcase) from t1; +select concat_ws(' ' collate utf8_lcase, utf8_binary, 'SQL' collate utf8_lcase) from t1; +select concat_ws(',', utf8_lcase, 'word'), concat_ws(',', utf8_binary, 'word') from t1; +select concat_ws(',', utf8_lcase, 'word' collate utf8_binary), concat_ws(',', utf8_binary, 'word' collate utf8_lcase) from t1; + +-- SplitPart +select split_part(utf8_binary, utf8_lcase, 3) from t1; +select split_part(s, utf8_binary, 1) from t1; +select split_part(utf8_binary collate utf8_binary, s collate utf8_lcase, 1) from t1; +select split_part(utf8_binary, utf8_lcase collate utf8_binary, 2) from t1; +select split_part(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase, 2) from t1; +select split_part(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 2) from t1; +select split_part(utf8_binary, 'a', 3), split_part(utf8_lcase, 'a', 3) from t1; +select split_part(utf8_binary, 'a' collate utf8_lcase, 3), split_part(utf8_lcase, 'a' collate utf8_binary, 3) from t1; +select split_part(utf8_binary, 'a ' collate utf8_lcase_rtrim, 3), split_part(utf8_lcase, 'a' collate utf8_binary, 3) from t1; + +-- Contains +select contains(utf8_binary, utf8_lcase) from t1; +select contains(s, utf8_binary) from t1; +select contains(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1; +select contains(utf8_binary, utf8_lcase collate utf8_binary) from t1; +select contains(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t1; +select contains(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t1; +select contains(utf8_binary, 'a'), contains(utf8_lcase, 'a') from t1; +select contains(utf8_binary, 'AaAA' collate utf8_lcase), contains(utf8_lcase, 'AAa' collate utf8_binary) from t1; +select contains(utf8_binary, 'AaAA ' collate utf8_lcase_rtrim), contains(utf8_lcase, 'AAa ' collate utf8_binary_rtrim) from t1; + +-- SubstringIndex +select substring_index(utf8_binary, utf8_lcase, 2) from t1; +select substring_index(s, utf8_binary,1) from t1; +select substring_index(utf8_binary collate utf8_binary, s collate utf8_lcase, 3) from t1; +select substring_index(utf8_binary, utf8_lcase collate utf8_binary, 2) from t1; +select substring_index(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase, 2) from t1; +select substring_index(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 2) from t1; +select substring_index(utf8_binary, 'a', 2), substring_index(utf8_lcase, 'a', 2) from t1; +select substring_index(utf8_binary, 'AaAA' collate utf8_lcase, 2), substring_index(utf8_lcase, 'AAa' collate utf8_binary, 2) from t1; +select substring_index(utf8_binary, 'AaAA ' collate utf8_lcase_rtrim, 2), substring_index(utf8_lcase, 'AAa' collate utf8_binary, 2) from t1; + +-- StringInStr +select instr(utf8_binary, utf8_lcase) from t1; +select instr(s, utf8_binary) from t1; +select instr(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1; +select instr(utf8_binary, utf8_lcase collate utf8_binary) from t1; +select instr(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t1; +select instr(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t1; +select instr(utf8_binary, 'a'), instr(utf8_lcase, 'a') from t1; +select instr(utf8_binary, 'AaAA' collate utf8_lcase), instr(utf8_lcase, 'AAa' collate utf8_binary) from t1; + +-- FindInSet +select find_in_set(utf8_binary, utf8_lcase) from t1; +select find_in_set(s, utf8_binary) from t1; +select find_in_set(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1; +select find_in_set(utf8_binary, utf8_lcase collate utf8_binary) from t1; +select find_in_set(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t1; +select find_in_set(utf8_binary, 'aaAaaAaA,i̇o'), find_in_set(utf8_lcase, 'aaAaaAaA,i̇o') from t1; +select find_in_set(utf8_binary, 'aaAaaAaA,i̇o' collate utf8_lcase), find_in_set(utf8_lcase, 'aaAaaAaA,i̇o' collate utf8_binary) from t1; +select find_in_set(utf8_binary, 'aaAaaAaA,i̇o ' collate utf8_lcase_rtrim), find_in_set(utf8_lcase, 'aaAaaAaA,i̇o' collate utf8_binary) from t1; +-- StartsWith +select startswith(utf8_binary, utf8_lcase) from t1; +select startswith(s, utf8_binary) from t1; +select startswith(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1; +select startswith(utf8_binary, utf8_lcase collate utf8_binary) from t1; +select startswith(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t1; +select startswith(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t1; +select startswith(utf8_binary, 'aaAaaAaA'), startswith(utf8_lcase, 'aaAaaAaA') from t1; +select startswith(utf8_binary, 'aaAaaAaA' collate utf8_lcase), startswith(utf8_lcase, 'aaAaaAaA' collate utf8_binary) from t1; +select startswith(utf8_binary, 'aaAaaAaA ' collate utf8_lcase_rtrim), startswith(utf8_lcase, 'aaAaaAaA' collate utf8_binary) from t1; + +-- StringTranslate +select translate(utf8_lcase, utf8_lcase, '12345') from t1; +select translate(utf8_binary, utf8_lcase, '12345') from t1; +select translate(utf8_binary, 'aBc' collate utf8_lcase, '12345' collate utf8_binary) from t1; +select translate(utf8_binary, 'SQL' collate utf8_lcase, '12345' collate utf8_lcase) from t1; +select translate(utf8_binary, 'SQL' collate unicode_ai, '12345' collate unicode_ai) from t1; +select translate(utf8_lcase, 'aaAaaAaA', '12345'), translate(utf8_binary, 'aaAaaAaA', '12345') from t1; +select translate(utf8_lcase, 'aBc' collate utf8_binary, '12345'), translate(utf8_binary, 'aBc' collate utf8_lcase, '12345') from t1; +select translate(utf8_lcase, 'aBc ' collate utf8_binary_rtrim, '12345'), translate(utf8_binary, 'aBc' collate utf8_lcase, '12345') from t1; + +-- Replace +select replace(utf8_binary, utf8_lcase, 'abc') from t1; +select replace(s, utf8_binary, 'abc') from t1; +select replace(utf8_binary collate utf8_binary, s collate utf8_lcase, 'abc') from t1; +select replace(utf8_binary, utf8_lcase collate utf8_binary, 'abc') from t1; +select replace(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase, 'abc') from t1; +select replace(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 'abc') from t1; +select replace(utf8_binary, 'aaAaaAaA', 'abc'), replace(utf8_lcase, 'aaAaaAaA', 'abc') from t1; +select replace(utf8_binary, 'aaAaaAaA' collate utf8_lcase, 'abc'), replace(utf8_lcase, 'aaAaaAaA' collate utf8_binary, 'abc') from t1; +select replace(utf8_binary, 'aaAaaAaA ' collate utf8_lcase_rtrim, 'abc'), replace(utf8_lcase, 'aaAaaAaA' collate utf8_binary, 'abc') from t1; + +-- EndsWith +select endswith(utf8_binary, utf8_lcase) from t1; +select endswith(s, utf8_binary) from t1; +select endswith(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1; +select endswith(utf8_binary, utf8_lcase collate utf8_binary) from t1; +select endswith(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t1; +select endswith(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t1; +select endswith(utf8_binary, 'aaAaaAaA'), endswith(utf8_lcase, 'aaAaaAaA') from t1; +select endswith(utf8_binary, 'aaAaaAaA' collate utf8_lcase), endswith(utf8_lcase, 'aaAaaAaA' collate utf8_binary) from t1; +select endswith(utf8_binary, 'aaAaaAaA ' collate utf8_lcase_rtrim), endswith(utf8_lcase, 'aaAaaAaA' collate utf8_binary) from t1; + +-- StringRepeat +select repeat(utf8_binary, 3), repeat(utf8_lcase, 2) from t1; +select repeat(utf8_binary collate utf8_lcase, 3), repeat(utf8_lcase collate utf8_binary, 2) from t1; + +-- Chr +select chr(ascii) from t2; + +-- Sentences +select sentences(utf8_binary), sentences(utf8_lcase) from t1; +select sentences(utf8_binary collate utf8_lcase), sentences(utf8_lcase collate utf8_binary) from t1; + +-- Upper +select upper(utf8_binary), upper(utf8_lcase) from t1; +select upper(utf8_binary collate utf8_lcase), upper(utf8_lcase collate utf8_binary) from t1; + +-- Lower +select lower(utf8_binary), lower(utf8_lcase) from t1; +select lower(utf8_binary collate utf8_lcase), lower(utf8_lcase collate utf8_binary) from t1; + +-- InitCap +select initcap(utf8_binary), initcap(utf8_lcase) from t1; +select initcap(utf8_binary collate utf8_lcase), initcap(utf8_lcase collate utf8_binary) from t1; + +-- Overlay +select overlay(utf8_binary, utf8_lcase, 2) from t1; +select overlay(s, utf8_binary,1) from t1; +select overlay(utf8_binary collate utf8_binary, s collate utf8_lcase, 3) from t1; +select overlay(utf8_binary, utf8_lcase collate utf8_binary, 2) from t1; +select overlay(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase, 2) from t1; +select overlay(utf8_binary, 'a', 2), overlay(utf8_lcase, 'a', 2) from t1; +select overlay(utf8_binary, 'AaAA' collate utf8_lcase, 2), overlay(utf8_lcase, 'AAa' collate utf8_binary, 2) from t1; + +-- FormatString +select format_string(format, utf8_binary, utf8_lcase) from t3; +select format_string(format collate utf8_lcase, utf8_lcase, utf8_binary collate utf8_lcase, 3), format_string(format, utf8_lcase collate utf8_binary, utf8_binary) from t3; +select format_string(format, utf8_binary, utf8_lcase) from t3; + +-- Length, BitLength & OctetLength +select length(utf8_binary), length(utf8_lcase) from t1; +select length(utf8_binary collate utf8_lcase), length(utf8_lcase collate utf8_binary) from t1; +select bit_length(utf8_binary), bit_length(utf8_lcase) from t1; +select bit_length(utf8_binary collate utf8_lcase), bit_length(utf8_lcase collate utf8_binary) from t1; +select octet_length(utf8_binary), octet_length(utf8_lcase) from t1; +select octet_length(utf8_binary collate utf8_lcase), octet_length(utf8_lcase collate utf8_binary) from t1; +select octet_length(utf8_binary collate utf8_lcase_rtrim), octet_length(utf8_lcase collate utf8_binary_rtrim) from t1; + +-- Left/Right/Substr +select substr(utf8_binary, 2, 2), substr(utf8_lcase, 2, 2) from t1; +select substr(utf8_binary collate utf8_lcase, 2, 2), substr(utf8_lcase collate utf8_binary, 2, 2) from t1; +select right(utf8_binary, 2), right(utf8_lcase, 2) from t1; +select right(utf8_binary collate utf8_lcase, 2), right(utf8_lcase collate utf8_binary, 2) from t1; +select left(utf8_binary, '2' collate utf8_lcase), left(utf8_lcase, 2) from t1; +select left(utf8_binary collate utf8_lcase, 2), left(utf8_lcase collate utf8_binary, 2) from t1; + +-- Locate +select locate(utf8_binary, utf8_lcase) from t1; +select locate(s, utf8_binary) from t1; +select locate(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1; +select locate(utf8_binary, utf8_lcase collate utf8_binary) from t1; +select locate(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase, 3) from t1; +select locate(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 3) from t1; +select locate(utf8_binary, 'a'), locate(utf8_lcase, 'a') from t1; +select locate(utf8_binary, 'AaAA' collate utf8_lcase, 4), locate(utf8_lcase, 'AAa' collate utf8_binary, 4) from t1; +select locate(utf8_binary, 'AaAA ' collate utf8_binary_rtrim, 4), locate(utf8_lcase, 'AAa ' collate utf8_binary, 4) from t1; + +drop table t1; +drop table t2; +drop table t3; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/collations.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/collations.sql deleted file mode 100644 index 17815ed5dde..00000000000 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/collations.sql +++ /dev/null @@ -1,527 +0,0 @@ --- test cases for collation support - --- Create a test table with data -create table t1(utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet; -insert into t1 values('aaa', 'aaa'); -insert into t1 values('AAA', 'AAA'); -insert into t1 values('bbb', 'bbb'); -insert into t1 values('BBB', 'BBB'); - --- describe -describe table t1; - --- group by and count utf8_binary -select count(*) from t1 group by utf8_binary; - --- group by and count utf8_lcase -select count(*) from t1 group by utf8_lcase; - --- filter equal utf8_binary -select * from t1 where utf8_binary = 'aaa'; - --- filter equal utf8_lcase -select * from t1 where utf8_lcase = 'aaa' collate utf8_lcase; - --- filter less then utf8_binary -select * from t1 where utf8_binary < 'bbb'; - --- filter less then utf8_lcase -select * from t1 where utf8_lcase < 'bbb' collate utf8_lcase; - --- inner join -select l.utf8_binary, r.utf8_lcase from t1 l join t1 r on l.utf8_lcase = r.utf8_lcase; - --- create second table for anti-join -create table t2(utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet; -insert into t2 values('aaa', 'aaa'); -insert into t2 values('bbb', 'bbb'); - --- anti-join on lcase -select * from t1 anti join t2 on t1.utf8_lcase = t2.utf8_lcase; - -drop table t2; -drop table t1; - --- set operations -select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') except select col1 collate utf8_lcase from values ('aaa'), ('bbb'); -select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') except all select col1 collate utf8_lcase from values ('aaa'), ('bbb'); -select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') union select col1 collate utf8_lcase from values ('aaa'), ('bbb'); -select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') union all select col1 collate utf8_lcase from values ('aaa'), ('bbb'); -select col1 collate utf8_lcase from values ('aaa'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') intersect select col1 collate utf8_lcase from values ('aaa'), ('bbb'); - --- set operations with conflicting collations -select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') except select col1 collate unicode_ci from values ('aaa'), ('bbb'); -select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') except all select col1 collate unicode_ci from values ('aaa'), ('bbb'); -select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') union select col1 collate unicode_ci from values ('aaa'), ('bbb'); -select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') union all select col1 collate unicode_ci from values ('aaa'), ('bbb'); -select col1 collate utf8_lcase from values ('aaa'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') intersect select col1 collate unicode_ci from values ('aaa'), ('bbb'); - --- create table with struct field -create table t1 (c1 struct) USING PARQUET; - -insert into t1 values (named_struct('utf8_binary', 'aaa', 'utf8_lcase', 'aaa')); -insert into t1 values (named_struct('utf8_binary', 'AAA', 'utf8_lcase', 'AAA')); - --- aggregate against nested field utf8_binary -select count(*) from t1 group by c1.utf8_binary; - --- aggregate against nested field utf8_lcase -select count(*) from t1 group by c1.utf8_lcase; - -drop table t1; - --- array function tests -select array_contains(ARRAY('aaa' collate utf8_lcase),'AAA' collate utf8_lcase); -select array_position(ARRAY('aaa' collate utf8_lcase, 'bbb' collate utf8_lcase),'BBB' collate utf8_lcase); - --- utility -select nullif('aaa' COLLATE utf8_lcase, 'AAA' COLLATE utf8_lcase); -select least('aaa' COLLATE utf8_lcase, 'AAA' collate utf8_lcase, 'a' collate utf8_lcase); - --- array operations -select arrays_overlap(array('aaa' collate utf8_lcase), array('AAA' collate utf8_lcase)); -select array_distinct(array('aaa' collate utf8_lcase, 'AAA' collate utf8_lcase)); -select array_union(array('aaa' collate utf8_lcase), array('AAA' collate utf8_lcase)); -select array_intersect(array('aaa' collate utf8_lcase), array('AAA' collate utf8_lcase)); -select array_except(array('aaa' collate utf8_lcase), array('AAA' collate utf8_lcase)); - --- ICU collations (all statements return true) -select 'a' collate unicode < 'A'; -select 'a' collate unicode_ci = 'A'; -select 'a' collate unicode_ai = 'å'; -select 'a' collate unicode_ci_ai = 'Å'; -select 'a' collate en < 'A'; -select 'a' collate en_ci = 'A'; -select 'a' collate en_ai = 'å'; -select 'a' collate en_ci_ai = 'Å'; -select 'Kypper' collate sv < 'Köpfe'; -select 'Kypper' collate de > 'Köpfe'; -select 'I' collate tr_ci = 'ı'; - --- create table for str_to_map -create table t4 (text string collate utf8_binary, pairDelim string collate utf8_lcase, keyValueDelim string collate utf8_binary) using parquet; - -insert into t4 values('a:1,b:2,c:3', ',', ':'); - -select str_to_map(text, pairDelim, keyValueDelim) from t4; -select str_to_map(text collate utf8_binary, pairDelim collate utf8_lcase, keyValueDelim collate utf8_binary) from t4; -select str_to_map(text collate utf8_binary, pairDelim collate utf8_binary, keyValueDelim collate utf8_binary) from t4; -select str_to_map(text collate unicode_ai, pairDelim collate unicode_ai, keyValueDelim collate unicode_ai) from t4; - -drop table t4; - -create table t5(s string, utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet; -insert into t5 values ('Spark', 'Spark', 'SQL'); -insert into t5 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaAAaA'); -insert into t5 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaaAaA'); -insert into t5 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaaAaAaaAaaAaAaaAaaAaA'); -insert into t5 values ('bbAbaAbA', 'bbAbAAbA', 'a'); -insert into t5 values ('İo', 'İo', 'İo'); -insert into t5 values ('İo', 'İo', 'İo '); -insert into t5 values ('İo', 'İo ', 'İo'); -insert into t5 values ('İo', 'İo', 'i̇o'); -insert into t5 values ('efd2', 'efd2', 'efd2'); -insert into t5 values ('Hello, world! Nice day.', 'Hello, world! Nice day.', 'Hello, world! Nice day.'); -insert into t5 values ('Something else. Nothing here.', 'Something else. Nothing here.', 'Something else. Nothing here.'); -insert into t5 values ('kitten', 'kitten', 'sitTing'); -insert into t5 values ('abc', 'abc', 'abc'); -insert into t5 values ('abcdcba', 'abcdcba', 'aBcDCbA'); - -create table t6(ascii long) using parquet; -insert into t6 values (97); -insert into t6 values (66); - -create table t7(ascii double) using parquet; -insert into t7 values (97.52143); -insert into t7 values (66.421); - -create table t8(format string collate utf8_binary, utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet; -insert into t8 values ('%s%s', 'abCdE', 'abCdE'); - -create table t9(num long) using parquet; -insert into t9 values (97); -insert into t9 values (66); - -create table t10(utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet; -insert into t10 values ('aaAaAAaA', 'aaAaaAaA'); -insert into t10 values ('efd2', 'efd2'); - --- ConcatWs -select concat_ws(' ', utf8_lcase, utf8_lcase) from t5; -select concat_ws(' ', utf8_binary, utf8_lcase) from t5; -select concat_ws(' ' collate utf8_binary, utf8_binary, 'SQL' collate utf8_lcase) from t5; -select concat_ws(' ' collate utf8_lcase, utf8_binary, 'SQL' collate utf8_lcase) from t5; -select concat_ws(',', utf8_lcase, 'word'), concat_ws(',', utf8_binary, 'word') from t5; -select concat_ws(',', utf8_lcase, 'word' collate utf8_binary), concat_ws(',', utf8_binary, 'word' collate utf8_lcase) from t5; - --- Elt -select elt(2, s, utf8_binary) from t5; -select elt(2, utf8_binary, utf8_lcase, s) from t5; -select elt(1, utf8_binary collate utf8_binary, utf8_lcase collate utf8_lcase) from t5; -select elt(1, utf8_binary collate utf8_binary, utf8_lcase collate utf8_binary) from t5; -select elt(1, utf8_binary collate utf8_binary, utf8_lcase) from t5; -select elt(1, utf8_binary, 'word'), elt(1, utf8_lcase, 'word') from t5; -select elt(1, utf8_binary, 'word' collate utf8_lcase), elt(1, utf8_lcase, 'word' collate utf8_binary) from t5; - --- SplitPart -select split_part(utf8_binary, utf8_lcase, 3) from t5; -select split_part(s, utf8_binary, 1) from t5; -select split_part(utf8_binary collate utf8_binary, s collate utf8_lcase, 1) from t5; -select split_part(utf8_binary, utf8_lcase collate utf8_binary, 2) from t5; -select split_part(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase, 2) from t5; -select split_part(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 2) from t5; -select split_part(utf8_binary, 'a', 3), split_part(utf8_lcase, 'a', 3) from t5; -select split_part(utf8_binary, 'a' collate utf8_lcase, 3), split_part(utf8_lcase, 'a' collate utf8_binary, 3) from t5; -select split_part(utf8_binary, 'a ' collate utf8_lcase_rtrim, 3), split_part(utf8_lcase, 'a' collate utf8_binary, 3) from t5; - --- Contains -select contains(utf8_binary, utf8_lcase) from t5; -select contains(s, utf8_binary) from t5; -select contains(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5; -select contains(utf8_binary, utf8_lcase collate utf8_binary) from t5; -select contains(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t5; -select contains(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t5; -select contains(utf8_binary, 'a'), contains(utf8_lcase, 'a') from t5; -select contains(utf8_binary, 'AaAA' collate utf8_lcase), contains(utf8_lcase, 'AAa' collate utf8_binary) from t5; -select contains(utf8_binary, 'AaAA ' collate utf8_lcase_rtrim), contains(utf8_lcase, 'AAa ' collate utf8_binary_rtrim) from t5; - --- SubstringIndex -select substring_index(utf8_binary, utf8_lcase, 2) from t5; -select substring_index(s, utf8_binary,1) from t5; -select substring_index(utf8_binary collate utf8_binary, s collate utf8_lcase, 3) from t5; -select substring_index(utf8_binary, utf8_lcase collate utf8_binary, 2) from t5; -select substring_index(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase, 2) from t5; -select substring_index(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 2) from t5; -select substring_index(utf8_binary, 'a', 2), substring_index(utf8_lcase, 'a', 2) from t5; -select substring_index(utf8_binary, 'AaAA' collate utf8_lcase, 2), substring_index(utf8_lcase, 'AAa' collate utf8_binary, 2) from t5; -select substring_index(utf8_binary, 'AaAA ' collate utf8_lcase_rtrim, 2), substring_index(utf8_lcase, 'AAa' collate utf8_binary, 2) from t5; - --- StringInStr -select instr(utf8_binary, utf8_lcase) from t5; -select instr(s, utf8_binary) from t5; -select instr(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5; -select instr(utf8_binary, utf8_lcase collate utf8_binary) from t5; -select instr(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t5; -select instr(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t5; -select instr(utf8_binary, 'a'), instr(utf8_lcase, 'a') from t5; -select instr(utf8_binary, 'AaAA' collate utf8_lcase), instr(utf8_lcase, 'AAa' collate utf8_binary) from t5; - --- FindInSet -select find_in_set(utf8_binary, utf8_lcase) from t5; -select find_in_set(s, utf8_binary) from t5; -select find_in_set(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5; -select find_in_set(utf8_binary, utf8_lcase collate utf8_binary) from t5; -select find_in_set(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t5; -select find_in_set(utf8_binary, 'aaAaaAaA,i̇o'), find_in_set(utf8_lcase, 'aaAaaAaA,i̇o') from t5; -select find_in_set(utf8_binary, 'aaAaaAaA,i̇o' collate utf8_lcase), find_in_set(utf8_lcase, 'aaAaaAaA,i̇o' collate utf8_binary) from t5; -select find_in_set(utf8_binary, 'aaAaaAaA,i̇o ' collate utf8_lcase_rtrim), find_in_set(utf8_lcase, 'aaAaaAaA,i̇o' collate utf8_binary) from t5; --- StartsWith -select startswith(utf8_binary, utf8_lcase) from t5; -select startswith(s, utf8_binary) from t5; -select startswith(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5; -select startswith(utf8_binary, utf8_lcase collate utf8_binary) from t5; -select startswith(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t5; -select startswith(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t5; -select startswith(utf8_binary, 'aaAaaAaA'), startswith(utf8_lcase, 'aaAaaAaA') from t5; -select startswith(utf8_binary, 'aaAaaAaA' collate utf8_lcase), startswith(utf8_lcase, 'aaAaaAaA' collate utf8_binary) from t5; -select startswith(utf8_binary, 'aaAaaAaA ' collate utf8_lcase_rtrim), startswith(utf8_lcase, 'aaAaaAaA' collate utf8_binary) from t5; - --- StringTranslate -select translate(utf8_lcase, utf8_lcase, '12345') from t5; -select translate(utf8_binary, utf8_lcase, '12345') from t5; -select translate(utf8_binary, 'aBc' collate utf8_lcase, '12345' collate utf8_binary) from t5; -select translate(utf8_binary, 'SQL' collate utf8_lcase, '12345' collate utf8_lcase) from t5; -select translate(utf8_binary, 'SQL' collate unicode_ai, '12345' collate unicode_ai) from t5; -select translate(utf8_lcase, 'aaAaaAaA', '12345'), translate(utf8_binary, 'aaAaaAaA', '12345') from t5; -select translate(utf8_lcase, 'aBc' collate utf8_binary, '12345'), translate(utf8_binary, 'aBc' collate utf8_lcase, '12345') from t5; -select translate(utf8_lcase, 'aBc ' collate utf8_binary_rtrim, '12345'), translate(utf8_binary, 'aBc' collate utf8_lcase, '12345') from t5; - --- Replace -select replace(utf8_binary, utf8_lcase, 'abc') from t5; -select replace(s, utf8_binary, 'abc') from t5; -select replace(utf8_binary collate utf8_binary, s collate utf8_lcase, 'abc') from t5; -select replace(utf8_binary, utf8_lcase collate utf8_binary, 'abc') from t5; -select replace(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase, 'abc') from t5; -select replace(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 'abc') from t5; -select replace(utf8_binary, 'aaAaaAaA', 'abc'), replace(utf8_lcase, 'aaAaaAaA', 'abc') from t5; -select replace(utf8_binary, 'aaAaaAaA' collate utf8_lcase, 'abc'), replace(utf8_lcase, 'aaAaaAaA' collate utf8_binary, 'abc') from t5; -select replace(utf8_binary, 'aaAaaAaA ' collate utf8_lcase_rtrim, 'abc'), replace(utf8_lcase, 'aaAaaAaA' collate utf8_binary, 'abc') from t5; - --- EndsWith -select endswith(utf8_binary, utf8_lcase) from t5; -select endswith(s, utf8_binary) from t5; -select endswith(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5; -select endswith(utf8_binary, utf8_lcase collate utf8_binary) from t5; -select endswith(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t5; -select endswith(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t5; -select endswith(utf8_binary, 'aaAaaAaA'), endswith(utf8_lcase, 'aaAaaAaA') from t5; -select endswith(utf8_binary, 'aaAaaAaA' collate utf8_lcase), endswith(utf8_lcase, 'aaAaaAaA' collate utf8_binary) from t5; -select endswith(utf8_binary, 'aaAaaAaA ' collate utf8_lcase_rtrim), endswith(utf8_lcase, 'aaAaaAaA' collate utf8_binary) from t5; - --- StringRepeat -select repeat(utf8_binary, 3), repeat(utf8_lcase, 2) from t5; -select repeat(utf8_binary collate utf8_lcase, 3), repeat(utf8_lcase collate utf8_binary, 2) from t5; - --- Ascii & UnBase64 string expressions -select ascii(utf8_binary), ascii(utf8_lcase) from t5; -select ascii(utf8_binary collate utf8_lcase), ascii(utf8_lcase collate utf8_binary) from t5; -select unbase64(utf8_binary), unbase64(utf8_lcase) from t10; -select unbase64(utf8_binary collate utf8_lcase), unbase64(utf8_lcase collate utf8_binary) from t10; - --- Chr -select chr(ascii) from t6; - --- Base64, Decode -select base64(utf8_binary), base64(utf8_lcase) from t5; -select base64(utf8_binary collate utf8_lcase), base64(utf8_lcase collate utf8_binary) from t5; -select decode(encode(utf8_binary, 'utf-8'), 'utf-8'), decode(encode(utf8_lcase, 'utf-8'), 'utf-8') from t5; -select decode(encode(utf8_binary collate utf8_lcase, 'utf-8'), 'utf-8'), decode(encode(utf8_lcase collate utf8_binary, 'utf-8'), 'utf-8') from t5; - --- FormatNumber -select format_number(ascii, '###.###') from t7; -select format_number(ascii, '###.###' collate utf8_lcase) from t7; - --- Encode, ToBinary -select encode(utf8_binary, 'utf-8'), encode(utf8_lcase, 'utf-8') from t5; -select encode(utf8_binary collate utf8_lcase, 'utf-8'), encode(utf8_lcase collate utf8_binary, 'utf-8') from t5; -select to_binary(utf8_binary, 'utf-8'), to_binary(utf8_lcase, 'utf-8') from t5; -select to_binary(utf8_binary collate utf8_lcase, 'utf-8'), to_binary(utf8_lcase collate utf8_binary, 'utf-8') from t5; - --- Sentences -select sentences(utf8_binary), sentences(utf8_lcase) from t5; -select sentences(utf8_binary collate utf8_lcase), sentences(utf8_lcase collate utf8_binary) from t5; - --- Upper -select upper(utf8_binary), upper(utf8_lcase) from t5; -select upper(utf8_binary collate utf8_lcase), upper(utf8_lcase collate utf8_binary) from t5; - --- Lower -select lower(utf8_binary), lower(utf8_lcase) from t5; -select lower(utf8_binary collate utf8_lcase), lower(utf8_lcase collate utf8_binary) from t5; - --- InitCap -select initcap(utf8_binary), initcap(utf8_lcase) from t5; -select initcap(utf8_binary collate utf8_lcase), initcap(utf8_lcase collate utf8_binary) from t5; - --- Overlay -select overlay(utf8_binary, utf8_lcase, 2) from t5; -select overlay(s, utf8_binary,1) from t5; -select overlay(utf8_binary collate utf8_binary, s collate utf8_lcase, 3) from t5; -select overlay(utf8_binary, utf8_lcase collate utf8_binary, 2) from t5; -select overlay(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase, 2) from t5; -select overlay(utf8_binary, 'a', 2), overlay(utf8_lcase, 'a', 2) from t5; -select overlay(utf8_binary, 'AaAA' collate utf8_lcase, 2), overlay(utf8_lcase, 'AAa' collate utf8_binary, 2) from t5; - --- FormatString -select format_string(format, utf8_binary, utf8_lcase) from t8; -select format_string(format collate utf8_lcase, utf8_lcase, utf8_binary collate utf8_lcase, 3), format_string(format, utf8_lcase collate utf8_binary, utf8_binary) from t8; -select format_string(format, utf8_binary, utf8_lcase) from t8; - --- SoundEx -select soundex(utf8_binary), soundex(utf8_lcase) from t5; -select soundex(utf8_binary collate utf8_lcase), soundex(utf8_lcase collate utf8_binary) from t5; - --- Length, BitLength & OctetLength -select length(utf8_binary), length(utf8_lcase) from t5; -select length(utf8_binary collate utf8_lcase), length(utf8_lcase collate utf8_binary) from t5; -select bit_length(utf8_binary), bit_length(utf8_lcase) from t5; -select bit_length(utf8_binary collate utf8_lcase), bit_length(utf8_lcase collate utf8_binary) from t5; -select octet_length(utf8_binary), octet_length(utf8_lcase) from t5; -select octet_length(utf8_binary collate utf8_lcase), octet_length(utf8_lcase collate utf8_binary) from t5; -select octet_length(utf8_binary collate utf8_lcase_rtrim), octet_length(utf8_lcase collate utf8_binary_rtrim) from t5; - --- Luhncheck -select luhn_check(num) from t9; - --- Levenshtein -select levenshtein(utf8_binary, utf8_lcase) from t5; -select levenshtein(s, utf8_binary) from t5; -select levenshtein(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5; -select levenshtein(utf8_binary, utf8_lcase collate utf8_binary) from t5; -select levenshtein(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t5; -select levenshtein(utf8_binary, 'a'), levenshtein(utf8_lcase, 'a') from t5; -select levenshtein(utf8_binary, 'AaAA' collate utf8_lcase, 3), levenshtein(utf8_lcase, 'AAa' collate utf8_binary, 4) from t5; - --- IsValidUTF8 -select is_valid_utf8(utf8_binary), is_valid_utf8(utf8_lcase) from t5; -select is_valid_utf8(utf8_binary collate utf8_lcase), is_valid_utf8(utf8_lcase collate utf8_binary) from t5; -select is_valid_utf8(utf8_binary collate utf8_lcase_rtrim), is_valid_utf8(utf8_lcase collate utf8_binary_rtrim) from t5; - --- MakeValidUTF8 -select make_valid_utf8(utf8_binary), make_valid_utf8(utf8_lcase) from t5; -select make_valid_utf8(utf8_binary collate utf8_lcase), make_valid_utf8(utf8_lcase collate utf8_binary) from t5; -select make_valid_utf8(utf8_binary collate utf8_lcase_rtrim), make_valid_utf8(utf8_lcase collate utf8_binary_rtrim) from t5; - --- ValidateUTF8 -select validate_utf8(utf8_binary), validate_utf8(utf8_lcase) from t5; -select validate_utf8(utf8_binary collate utf8_lcase), validate_utf8(utf8_lcase collate utf8_binary) from t5; -select validate_utf8(utf8_binary collate utf8_lcase_rtrim), validate_utf8(utf8_lcase collate utf8_binary_rtrim) from t5; - --- TryValidateUTF8 -select try_validate_utf8(utf8_binary), try_validate_utf8(utf8_lcase) from t5; -select try_validate_utf8(utf8_binary collate utf8_lcase), try_validate_utf8(utf8_lcase collate utf8_binary) from t5; -select try_validate_utf8(utf8_binary collate utf8_lcase_rtrim), try_validate_utf8(utf8_lcase collate utf8_binary_rtrim) from t5; - --- Left/Right/Substr -select substr(utf8_binary, 2, 2), substr(utf8_lcase, 2, 2) from t5; -select substr(utf8_binary collate utf8_lcase, 2, 2), substr(utf8_lcase collate utf8_binary, 2, 2) from t5; -select right(utf8_binary, 2), right(utf8_lcase, 2) from t5; -select right(utf8_binary collate utf8_lcase, 2), right(utf8_lcase collate utf8_binary, 2) from t5; -select left(utf8_binary, '2' collate utf8_lcase), left(utf8_lcase, 2) from t5; -select left(utf8_binary collate utf8_lcase, 2), left(utf8_lcase collate utf8_binary, 2) from t5; - --- StringRPad -select rpad(utf8_binary, 8, utf8_lcase) from t5; -select rpad(s, 8, utf8_binary) from t5; -select rpad(utf8_binary collate utf8_binary, 8, s collate utf8_lcase) from t5; -select rpad(utf8_binary, 8, utf8_lcase collate utf8_binary) from t5; -select rpad(utf8_binary collate utf8_lcase, 8, utf8_lcase collate utf8_lcase) from t5; -select lpad(utf8_binary collate utf8_binary_rtrim, 8, utf8_lcase collate utf8_binary_rtrim) from t5; -select rpad(utf8_binary, 8, 'a'), rpad(utf8_lcase, 8, 'a') from t5; -select rpad(utf8_binary, 8, 'AaAA' collate utf8_lcase), rpad(utf8_lcase, 8, 'AAa' collate utf8_binary) from t5; - --- StringLPad -select lpad(utf8_binary, 8, utf8_lcase) from t5; -select lpad(s, 8, utf8_binary) from t5; -select lpad(utf8_binary collate utf8_binary, 8, s collate utf8_lcase) from t5; -select lpad(utf8_binary, 8, utf8_lcase collate utf8_binary) from t5; -select lpad(utf8_binary collate utf8_lcase, 8, utf8_lcase collate utf8_lcase) from t5; -select lpad(utf8_binary collate utf8_binary_rtrim, 8, utf8_lcase collate utf8_binary_rtrim) from t5; -select lpad(utf8_binary, 8, 'a'), lpad(utf8_lcase, 8, 'a') from t5; -select lpad(utf8_binary, 8, 'AaAA' collate utf8_lcase), lpad(utf8_lcase, 8, 'AAa' collate utf8_binary) from t5; - --- Locate -select locate(utf8_binary, utf8_lcase) from t5; -select locate(s, utf8_binary) from t5; -select locate(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5; -select locate(utf8_binary, utf8_lcase collate utf8_binary) from t5; -select locate(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase, 3) from t5; -select locate(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 3) from t5; -select locate(utf8_binary, 'a'), locate(utf8_lcase, 'a') from t5; -select locate(utf8_binary, 'AaAA' collate utf8_lcase, 4), locate(utf8_lcase, 'AAa' collate utf8_binary, 4) from t5; -select locate(utf8_binary, 'AaAA ' collate utf8_binary_rtrim, 4), locate(utf8_lcase, 'AAa ' collate utf8_binary, 4) from t5; - --- StringTrim -select TRIM(utf8_binary, utf8_lcase) from t5; -select TRIM(s, utf8_binary) from t5; -select TRIM(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5; -select TRIM(utf8_binary, utf8_lcase collate utf8_binary) from t5; -select TRIM(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t5; -select TRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t5; -select TRIM(utf8_binary collate utf8_binary_rtrim, utf8_lcase collate utf8_binary_rtrim) from t5; -select TRIM('ABc', utf8_binary), TRIM('ABc', utf8_lcase) from t5; -select TRIM('ABc' collate utf8_lcase, utf8_binary), TRIM('AAa' collate utf8_binary, utf8_lcase) from t5; --- StringTrimBoth -select BTRIM(utf8_binary, utf8_lcase) from t5; -select BTRIM(s, utf8_binary) from t5; -select BTRIM(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5; -select BTRIM(utf8_binary, utf8_lcase collate utf8_binary) from t5; -select BTRIM(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t5; -select BTRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t5; -select BTRIM(utf8_binary collate utf8_binary_rtrim, utf8_lcase collate utf8_binary_rtrim) from t5; -select BTRIM('ABc', utf8_binary), BTRIM('ABc', utf8_lcase) from t5; -select BTRIM('ABc' collate utf8_lcase, utf8_binary), BTRIM('AAa' collate utf8_binary, utf8_lcase) from t5; --- StringTrimLeft -select LTRIM(utf8_binary, utf8_lcase) from t5; -select LTRIM(s, utf8_binary) from t5; -select LTRIM(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5; -select LTRIM(utf8_binary, utf8_lcase collate utf8_binary) from t5; -select LTRIM(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t5; -select LTRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t5; -select LTRIM(utf8_binary collate utf8_binary_rtrim, utf8_lcase collate utf8_binary_rtrim) from t5; -select LTRIM('ABc', utf8_binary), LTRIM('ABc', utf8_lcase) from t5; -select LTRIM('ABc' collate utf8_lcase, utf8_binary), LTRIM('AAa' collate utf8_binary, utf8_lcase) from t5; --- StringTrimRight -select RTRIM(utf8_binary, utf8_lcase) from t5; -select RTRIM(s, utf8_binary) from t5; -select RTRIM(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5; -select RTRIM(utf8_binary, utf8_lcase collate utf8_binary) from t5; -select RTRIM(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t5; -select RTRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t5; -select RTRIM(utf8_binary collate utf8_binary_rtrim, utf8_lcase collate utf8_binary_rtrim) from t5; -select RTRIM('ABc', utf8_binary), RTRIM('ABc', utf8_lcase) from t5; -select RTRIM('ABc' collate utf8_lcase, utf8_binary), RTRIM('AAa' collate utf8_binary, utf8_lcase) from t5; - --- Implicit aliases to collated expression trees are correctly generated - --- Simple select -select concat_ws(' ', utf8_lcase, utf8_lcase) from t5; - --- Select by implicit alias -select `concat_ws(' ' collate UTF8_LCASE, utf8_lcase, utf8_lcase)` from ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 -); - --- Select by star -select * from ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 -); - --- Select by qualified star -select subq1.* from ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 -) AS subq1; - --- Implicit alias in CTE output -with cte as ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 -) -select * from cte; - --- Implicit alias in EXISTS subquery output -select * from values (1) where exists ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 -); - --- Implicit alias in scalar subquery output -select ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 limit 1 -); - --- Scalar subquery with CTE with implicit alias -select ( - with cte as ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 - ) - select * from cte limit 1 -); - --- Outer reference to implicit alias -select * from ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 limit 1 -) -where ( - `concat_ws(' ' collate UTF8_LCASE, utf8_lcase, utf8_lcase)` == 'aaa' -); - --- Implicit alias reference in Sort -select lower(`concat_ws(' ' collate UTF8_LCASE, utf8_lcase, utf8_lcase)`) from ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 - group by 1 - order by 1 -); - --- Implciit alias from aggregate in Sort -select lower(`concat_ws(' ' collate UTF8_LCASE, utf8_lcase, utf8_lcase)`) from ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 - group by 1 - order by max(concat_ws(' ', utf8_lcase, utf8_lcase)) -); - --- Implicit alias in view schema -create temporary view v1 as ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 -); - -select * from v1; - -select `concat_ws(' ' collate UTF8_LCASE, utf8_lcase, utf8_lcase)` from v1; - -drop view v1; - -drop table t5; -drop table t6; -drop table t7; -drop table t8; -drop table t9; -drop table t10; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/csv-functions.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/csv-functions.sql index 01d436534a1..4dbc0b39ca0 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/csv-functions.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/csv-functions.sql @@ -12,6 +12,7 @@ select from_csv(); select from_csv('1,abc', schema_of_csv('1,abc')); select schema_of_csv('1|abc', map('delimiter', '|')); select schema_of_csv(null); +select schema_of_csv(42); CREATE TEMPORARY VIEW csvTable(csvField, a) AS SELECT * FROM VALUES ('1,abc', 'a'); SELECT schema_of_csv(csvField) FROM csvTable; -- Clean up diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/cte-recursion.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/cte-recursion.sql new file mode 100644 index 00000000000..4aa7be79a05 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/cte-recursion.sql @@ -0,0 +1,826 @@ +--SET spark.sql.cteRecursionLevelLimit=25 +--SET spark.sql.cteRecursionRowLimit=50 + +-- fails due to recursion isn't allowed without RECURSIVE keyword +WITH r(level) AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r WHERE level < 9 +) +SELECT * FROM r; + +-- basic recursion +WITH RECURSIVE r AS ( + SELECT 0 AS level + UNION ALL + SELECT level + 1 FROM r WHERE level < 9 +) +SELECT * FROM r; + +-- basic recursion with subquery column alias +WITH RECURSIVE r(level) AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r WHERE level < 9 +) +SELECT * FROM r; + +-- using string column in recursion +WITH RECURSIVE r(c) AS ( + SELECT 'a' + UNION ALL + SELECT c || char(ascii(substr(c, -1)) + 1) FROM r WHERE LENGTH(c) < 10 +) +SELECT * FROM r; + +-- unlimited recursion fails at spark.sql.cteRecursionLevelLimit level +WITH RECURSIVE r(level) AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r +) +SELECT * FROM r; + +-- unlimited recursion fails at spark.sql.cteRecursionRowLimit level +CREATE TEMPORARY VIEW ZeroAndOne(current, next) AS VALUES + (0,0), + (0,1), + (1,0), + (1,1); + +WITH RECURSIVE t(n) AS ( + SELECT 1 + UNION ALL + SELECT next FROM t LEFT JOIN ZeroAndOne ON n = current +) +SELECT * FROM t; + +DROP VIEW ZeroAndOne; + +-- limited recursion doesn't fail at spark.sql.cteRecursionLevelLimit by setting MAX RECURSION LEVEL +WITH RECURSIVE r(level) MAX RECURSION LEVEL 35 AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r WHERE level < 30 + ) +SELECT * FROM r; + +-- setting MAX RECURSION LEVEL without keyword RECURSIVE fails +WITH r(level) MAX RECURSION LEVEL 35 AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r WHERE level < 30 +) +SELECT * FROM r; + +-- limited recursion fails at spark.sql.cteRecursionLevelLimit level because it is too low +WITH RECURSIVE r(level) AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r WHERE level < 150 +) +SELECT * FROM r; + +-- unlimited recursion stopped from failing by putting LIMIT +CREATE TEMPORARY VIEW ZeroAndOne(current, next) AS VALUES + (0,0), + (0,1), + (1,0), + (1,1); + +WITH RECURSIVE t(n) AS ( + SELECT 1 + UNION ALL + SELECT next FROM t LEFT JOIN ZeroAndOne ON n = current + ) +SELECT * FROM t LIMIT 60; + +DROP VIEW ZeroAndOne; + +-- limited recursion allowed to stop from failing by putting LIMIT ALL +WITH RECURSIVE t(n) MAX RECURSION LEVEL 100 AS ( + SELECT 1 + UNION ALL + SELECT n + 1 FROM t WHERE n < 60 + ) +SELECT * FROM t LIMIT ALL; + +WITH RECURSIVE t MAX RECURSION LEVEL 100 AS ( + SELECT 1 AS n + UNION ALL + SELECT n + 1 FROM t WHERE n < 60 + ) +SELECT * FROM t LIMIT ALL; + +-- One reference is limit all but other isn't. Should fail. +WITH RECURSIVE t MAX RECURSION LEVEL 100 AS ( + SELECT 1 AS n + UNION ALL + SELECT n + 1 FROM t WHERE n < 60 + ) + (SELECT n FROM t LIMIT ALL) UNION ALL (SELECT n FROM t); + +-- One references are limit all. +WITH RECURSIVE t MAX RECURSION LEVEL 100 AS ( + SELECT 1 AS n + UNION ALL + SELECT n + 1 FROM t WHERE n < 60 + ) + (SELECT n FROM t LIMIT ALL) UNION ALL (SELECT n FROM t LIMIT ALL); + +-- terminate recursion with LIMIT +WITH RECURSIVE r(level) AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r +) +SELECT * FROM r LIMIT 10; + +-- UNION - not yet supported +WITH RECURSIVE r AS ( + SELECT 0 as level + UNION + SELECT (level + 1) % 10 FROM r +) +SELECT * FROM r; + +-- UNION with subquery column alias - not yet supported +WITH RECURSIVE r(level) AS ( + VALUES 0 + UNION + SELECT (level + 1) % 10 FROM r +) +SELECT * FROM r; + +-- unlimited recursion fails because using LIMIT to terminate recursion only works where it can be +-- pushed down to recursion +WITH RECURSIVE r(level) AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r +) +SELECT level, level FROM r ORDER BY 1 LIMIT 10; + +-- fails because recursion doesn't follow the expected form +WITH RECURSIVE r(level) AS ( + SELECT level + 1 FROM r WHERE level < 9 +) +SELECT * FROM r; + +-- fails because recursion doesn't follow the expected form +WITH RECURSIVE r(level) AS ( + SELECT level + 1 FROM r WHERE level < 9 + UNION ALL + VALUES 0 +) +SELECT * FROM r; + +--recursive keyword but no self-reference +--other sql engines don't throw an error in this case, so Spark doesn't throw it as well +WITH RECURSIVE t(n) AS ( + SELECT 1 + UNION ALL + SELECT 2 +) +SELECT * FROM t; + +-- fails because a recursive query should contain UNION ALL or UNION combinator +WITH RECURSIVE r(level) AS ( + VALUES 0 + INTERSECT + SELECT level + 1 FROM r WHERE level < 9 +) +SELECT * FROM r; + +-- recursive reference is not allowed in a subquery expression +WITH RECURSIVE t(col) ( + SELECT 1 + UNION ALL + SELECT (SELECT max(col) FROM t) +) +SELECT * FROM t LIMIT 5; + +-- complicated subquery example: self-reference in subquery in an inner CTE +WITH + t1 AS (SELECT 1 as n), + t2(n) AS ( + WITH RECURSIVE t3(n) AS ( + SELECT 1 + UNION ALL + SELECT n+1 FROM (SELECT MAX(n) FROM t3) + ) + SELECT * FROM t3 + ) +SELECT * FROM t2; + +-- Self reference is inside OneRowSubquery +WITH RECURSIVE t1(n) AS ( + SELECT 1 + UNION ALL + SELECT (SELECT n+1 FROM t1 WHERE n<5) +) +SELECT * FROM t1 LIMIT 5; + +-- recursive reference in a nested CTE +WITH RECURSIVE + t1 AS ( + SELECT 1 AS level + UNION ALL ( + WITH t2 AS (SELECT level + 1 FROM t1 WHERE level < 10) + SELECT * FROM t2 + ) + ) +SELECT * FROM t1; + +-- recursive reference and conflicting outer CTEs in a nested CTE +SET spark.sql.legacy.ctePrecedencePolicy=CORRECTED; +WITH + t1 AS (SELECT 1), + t2 AS ( + WITH RECURSIVE + t1 AS ( + SELECT 1 AS level + UNION ALL ( + WITH t3 AS (SELECT level + 1 FROM t1 WHERE level < 10) + SELECT * FROM t3 + ) + ) + SELECT * FROM t1 + ) +SELECT * FROM t2; +SET spark.sql.legacy.ctePrecedencePolicy=EXCEPTION; + +-- recursive reference can't be used multiple times in a recursive term +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 0) + UNION ALL + SELECT r1.level + 1, r1.data + FROM r AS r1 + JOIN r AS r2 ON r2.data = r1.data + WHERE r1.level < 9 +) +SELECT * FROM r; + +-- recursive reference is allowed on left side of a left outer join +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 0) + UNION ALL + SELECT level + 1, r.data + FROM r + LEFT OUTER JOIN ( + SELECT 0 AS data + ) AS t ON t.data = r.data + WHERE r.level < 9 +) +SELECT * FROM r; + +-- recursive reference is not allowed on right side of a left outer join +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 0) + UNION ALL + SELECT level + 1, r.data + FROM ( + SELECT 0 AS data + ) AS t + LEFT OUTER JOIN r ON r.data = t.data + WHERE r.level < 9 +) +SELECT * FROM r; + +-- recursive reference is allowed on right side of a right outer join +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 0) + UNION ALL + SELECT level + 1, r.data + FROM ( + SELECT 0 AS data + ) AS t + RIGHT OUTER JOIN r ON r.data = t.data + WHERE r.level < 9 +) +SELECT * FROM r; + +-- recursive reference is not allowed on left side of a right outer join +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 0) + UNION ALL + SELECT level + 1, r.data + FROM r + RIGHT OUTER JOIN ( + SELECT 0 AS data + ) AS t ON t.data = r.data + WHERE r.level < 9 +) +SELECT * FROM r; + +-- recursive reference is not allowed in a full outer join +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 0) + UNION ALL + SELECT level + 1, r.data + FROM r + FULL OUTER JOIN ( + SELECT 0 AS data + ) AS t ON t.data = r.data + WHERE r.level < 9 +) +SELECT * FROM r; + +-- recursive reference is allowed on left side of a left semi join +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 0) + UNION ALL + SELECT level + 1, r.data + FROM r + LEFT SEMI JOIN ( + SELECT 0 AS data + ) AS t ON t.data = r.data + WHERE r.level < 9 +) +SELECT * FROM r; + +-- recursive reference is not allowed on right side of a left semi join +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 0) + UNION ALL + SELECT level + 1, data + FROM ( + SELECT 0 AS level, 0 AS data + ) AS t + LEFT SEMI JOIN r ON r.data = t.data AND r.level < 9 +) +SELECT * FROM r; + +-- recursive reference is allowed on left side of a left anti join +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 0) + UNION ALL + SELECT level + 1, r.data + FROM r + LEFT ANTI JOIN ( + SELECT -1 AS data + ) AS t ON t.data = r.data + WHERE r.level < 9 +) +SELECT * FROM r; + +-- recursive reference is not allowed on right side of a left anti join +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 0) + UNION ALL + SELECT level + 1, data + FROM ( + SELECT 0 AS level, 0 AS data + ) AS t + LEFT ANTI JOIN r ON r.data = t.data AND r.level < 9 +) +SELECT * FROM r; + +-- recursive reference is not allowed in an aggregate +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 1L) + UNION ALL + SELECT MAX(level) + 1, SUM(data) FROM r WHERE level < 9 +) +SELECT * FROM r; + +-- group by inside recursion not allowed (considered as aggregate as well) +WITH RECURSIVE r(n) AS ( + SELECT 1 + UNION ALL + SELECT n+1 FROM r GROUP BY n) +SELECT * FROM r; + +-- recursion is allowed in simple commands +CREATE TEMPORARY VIEW rv AS +WITH RECURSIVE r(level) AS ( + VALUES (0) + UNION ALL + SELECT level + 1 FROM r WHERE level < 9 +) +SELECT * FROM r; + +SELECT * FROM rv; + +DROP VIEW rv; + +-- recursion is allowed in simple commands 2 +CREATE TABLE rt(level INT) USING csv; + +WITH RECURSIVE r(level) AS ( + VALUES (0) + UNION ALL + SELECT level + 1 FROM r WHERE level < 9 +) +INSERT INTO rt SELECT * FROM r; + +SELECT * from rt; + +DROP TABLE rt; + +-- recursion is not allowed in multi commands +CREATE TABLE rt2(level INT) USING csv; + +WITH RECURSIVE r(level) AS ( + VALUES (0) + UNION ALL + SELECT level + 1 FROM r WHERE level < 9 +) +FROM r +INSERT INTO rt2 SELECT * +INSERT INTO rt2 SELECT *; + +SELECT * FROM rt2; + +DROP TABLE rt2; + +-- multiple recursive CTEs +WITH RECURSIVE + r1 AS ( + SELECT 0 AS level + UNION ALL + SELECT level + 1 FROM r1 WHERE level < 9 + ), + r2 AS ( + SELECT 10 AS level + UNION ALL + SELECT level + 1 FROM r2 WHERE level < 19 + ) +SELECT * +FROM r1 +JOIN r2 ON r2.level = r1.level + 10; + +-- multiple uses of recursive CTEs +WITH RECURSIVE r AS ( + SELECT 0 AS level + UNION ALL + SELECT level + 1 FROM r WHERE level < 9 +) +SELECT * +FROM r AS r1 +JOIN r AS r2 ON r2.level = r1.level; + +-- recursive cte nested into recursive cte as anchor +WITH RECURSIVE r2 AS ( + WITH RECURSIVE r1 AS ( + SELECT 0 AS innerlevel + UNION ALL + SELECT innerlevel + 1 FROM r1 WHERE innerlevel < 3 + ) + SELECT 0 AS outerlevel, innerlevel FROM r1 + UNION ALL + SELECT outerlevel + 1, innerlevel FROM r2 WHERE outerlevel < 3 +) +SELECT * FROM r2; + +-- name collision of nested CTEs (the outer CTE is not recursive) +WITH RECURSIVE r(level) AS ( + WITH RECURSIVE r(level) AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r WHERE level < 3 + ) + SELECT * FROM r + UNION ALL + SELECT level + 1 FROM r WHERE level < 3 +) +SELECT * FROM r; + +-- name collision of nested CTEs (the outer CTE is recursive) +WITH RECURSIVE r(level) AS ( + (WITH RECURSIVE r(level) AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r WHERE level < 3 + ) + SELECT * FROM r) + UNION ALL + SELECT level + 1 FROM r WHERE level < 3 +) +SELECT * FROM r; + +-- routes represented here is as follows: +-- +-- New York<--->Boston +-- | ∧ +-- ∨ | +-- Washington---+ +-- | +-- ∨ +-- Raleigh +CREATE TEMPORARY VIEW routes(origin, destination) AS VALUES + ('New York', 'Washington'), + ('New York', 'Boston'), + ('Boston', 'New York'), + ('Washington', 'Boston'), + ('Washington', 'Raleigh'); + +-- handling cycles that could cause infinite recursion +WITH RECURSIVE destinations_from_new_york AS ( + SELECT 'New York' AS destination, ARRAY('New York') AS path, 0 AS length + UNION ALL + SELECT r.destination, CONCAT(d.path, ARRAY(r.destination)), d.length + 1 + FROM routes AS r + JOIN destinations_from_new_york AS d ON d.destination = r.origin AND NOT ARRAY_CONTAINS(d.path, r.destination) +) +SELECT * FROM destinations_from_new_york; + +DROP VIEW routes; + +-- Fibonacci numbers +WITH RECURSIVE fibonacci AS ( + VALUES (0, 1) AS t(a, b) + UNION ALL + SELECT b, a + b FROM fibonacci WHERE a < 10 +) +SELECT a FROM fibonacci ORDER BY a; + +-- Recursive CTE with useless columns +WITH RECURSIVE t1(a,b,c) AS ( + SELECT 1,1,1 + UNION ALL + SELECT a+1,a+1,a+1 FROM t1) +SELECT a FROM t1 LIMIT 5; + +-- CROSS JOIN example +CREATE TABLE tb (next INT) USING json; + +INSERT INTO tb VALUES (0), (1); + +WITH RECURSIVE t(n) AS ( + SELECT 1 + UNION ALL + SELECT next FROM t CROSS JOIN tb + ) +SELECT * FROM t LIMIT 63; + +DROP TABLE tb; +-- CROSS JOIN example 2 + +WITH RECURSIVE + x(id) AS (SELECT 1 UNION SELECT 2), + t(id, xid) AS ( + SELECT 0 AS id, 0 AS xid + UNION ALL + SELECT t.id + 1, xid * 10 + x.id FROM t CROSS JOIN x WHERE t.id < 3 + ) +SELECT * FROM t; + +-- rCTE referencing other rCTE +WITH RECURSIVE t1(a, b) AS ( + SELECT 1, 1 + UNION ALL + SELECT a + b, a FROM t1 WHERE a < 20 +), +t2(n) AS ( + SELECT 1 + UNION ALL + SELECT n + 1 FROM t2, t1 WHERE n + 1 = a +) +SELECT * FROM t2; + +-- Multiple CTEs within rCTE +WITH RECURSIVE t1 (n) AS ( + VALUES(1) + UNION ALL + ( + WITH t2(j) AS ( + SELECT n + 1 FROM t1 + ), + t3(k) AS ( + SELECT j FROM t2 + ) + SELECT k FROM t3 WHERE k <= 5 + ) +) +SELECT n FROM t1; + +-- Column aliases with CTEs inside rCTEs +WITH RECURSIVE r2(outerlevel1, innerlevel1) AS ( + WITH RECURSIVE r1 AS ( + SELECT 0 AS innerlevel + UNION ALL + SELECT innerlevel + 1 FROM r1 WHERE innerlevel < 3 + ) + SELECT 0 AS outerlevel, innerlevel FROM r1 + UNION ALL + SELECT outerlevel1 + 1, innerlevel1 FROM r2 WHERE outerlevel1 < 3 +) +SELECT * FROM r2; + +-- An inner cte that is defined for both the anchor and recursion but called only in the recursion +-- with subquery alias +WITH RECURSIVE t1(n) AS ( + WITH t2(n) AS (SELECT * FROM t1) + SELECT 1 + UNION ALL + SELECT n+1 FROM t2 WHERE n < 5) +SELECT * FROM t1; + +-- An inner cte that is defined for both the anchor and recursion but called only in the recursion +-- without query alias +WITH RECURSIVE t1 AS ( + WITH t2(n) AS (SELECT * FROM t1) + SELECT 1 AS n + UNION ALL + SELECT n+1 FROM t2 WHERE n < 5) +SELECT * FROM t1; + +-- Recursive CTE with multiple of the same reference in the anchor, which get referenced differently subsequent iterations. +WITH RECURSIVE tmp(x) AS ( + values (1), (2), (3), (4), (5) +), rcte(x, y) AS ( + SELECT x, x FROM tmp WHERE x = 1 + UNION ALL + SELECT x + 1, x FROM rcte WHERE x < 5 +) +SELECT * FROM rcte; + +-- Previous query without converting to local relations +SET spark.sql.cteRecursionAnchorRowsLimitToConvertToLocalRelation=0; + +WITH RECURSIVE tmp(x) AS ( + values (1), (2), (3), (4), (5) +), rcte(x, y) AS ( + SELECT x, x FROM tmp WHERE x = 1 + UNION ALL + SELECT x + 1, x FROM rcte WHERE x < 5 +) +SELECT * FROM rcte; + +SET spark.sql.cteRecursionAnchorRowsLimitToConvertToLocalRelation=100; + +-- Recursive CTE with multiple of the same reference in the anchor, which get referenced as different variables in subsequent iterations. +WITH RECURSIVE tmp(x) AS ( + values (1), (2), (3), (4), (5) +), rcte(x, y, z, t) AS ( + SELECT x, x, x, x FROM tmp WHERE x = 1 + UNION ALL + SELECT x + 1, x, y + 1, y FROM rcte WHERE x < 5 +) +SELECT * FROM rcte; + +-- Non-deterministic query with rand with seed +WITH RECURSIVE randoms(val) AS ( + SELECT CAST(floor(rand(82374) * 5 + 1) AS INT) + UNION ALL + SELECT CAST(floor(rand(237685) * 5 + 1) AS INT) + FROM randoms +) +SELECT val FROM randoms LIMIT 5; + +-- Non-deterministic query with uniform with seed +WITH RECURSIVE randoms(val) AS ( + SELECT CAST(UNIFORM(1, 6, 82374) AS INT) + UNION ALL + SELECT CAST(UNIFORM(1, 6, 237685) AS INT) + FROM randoms +) +SELECT val FROM randoms LIMIT 5; + +-- Non-deterministic query with randn with seed +WITH RECURSIVE randoms(val) AS ( + SELECT CAST(floor(randn(82374) * 5 + 1) AS INT) + UNION ALL + SELECT CAST(floor(randn(237685) * 5 + 1) AS INT) + FROM randoms +) +SELECT val FROM randoms LIMIT 5; + +-- Non-deterministic query with randstr +WITH RECURSIVE randoms(val) AS ( + SELECT randstr(10, 82374) + UNION ALL + SELECT randstr(10, 237685) + FROM randoms +) +SELECT val FROM randoms LIMIT 5; + +-- Non-deterministic query with UUID +WITH RECURSIVE randoms(val) AS ( + SELECT UUID(82374) + UNION ALL + SELECT UUID(237685) + FROM randoms +) +SELECT val FROM randoms LIMIT 5; + +-- Non-deterministic query with shuffle +WITH RECURSIVE randoms(val) AS ( + SELECT ARRAY(1,2,3,4,5) + UNION ALL + SELECT SHUFFLE(ARRAY(1,2,3,4,5), 237685) + FROM randoms +) +SELECT val FROM randoms LIMIT 5; + +-- Type coercion where the anchor is wider +WITH RECURSIVE t1(n, m) AS ( + SELECT 1, CAST(1 AS BIGINT) + UNION ALL + SELECT n+1, n+1 FROM t1 WHERE n < 5) +SELECT * FROM t1; + +-- Type coercion where the recursion is wider +WITH RECURSIVE t1(n, m) AS ( + SELECT 1, 1 + UNION ALL + SELECT n+1, CAST(n+1 AS BIGINT) FROM t1 WHERE n < 5) +SELECT * FROM t1; + +-- Recursive CTE with nullable recursion and non-recursive anchor +WITH RECURSIVE t1(n) AS ( + SELECT 1 + UNION ALL + SELECT CASE WHEN n < 5 THEN n + 1 ELSE NULL END FROM t1 +) +SELECT * FROM t1 LIMIT 25; + +-- Two calls to same rCTE with and without limit +WITH RECURSIVE t1(n) AS ( + SELECT 1 + UNION ALL + SELECT n + 1 FROM t1 WHERE n < 5 +) +SELECT (SELECT SUM(n) FROM (SELECT * FROM t1)), (SELECT SUM(n) FROM (SELECT * FROM t1 LIMIT 3)); + +-- Two calls to same infinite rCTE with different limits +WITH RECURSIVE t1(n) AS ( + SELECT 1 + UNION ALL + SELECT n + 1 FROM t1 +) +SELECT (SELECT SUM(n) FROM (SELECT * FROM t1 LIMIT 5)), (SELECT SUM(n) FROM (SELECT * FROM t1 LIMIT 3)); + +-- Two calls to same infinite rCTE from another rCTE +WITH RECURSIVE t1(n) AS ( + SELECT 1 + UNION ALL + SELECT n + 1 FROM t1 +), t2(m) AS ( + SELECT (SELECT SUM(n) FROM (SELECT n FROM t1 LIMIT 10) AS sums) + UNION ALL + SELECT m + (SELECT SUM(n) FROM (SELECT n FROM t1 LIMIT 3) AS sums) FROM t2 +) +SELECT * FROM t2 LIMIT 20; + +-- Two calls to recursive CTE with single limit pushed to both +WITH RECURSIVE t1(n) AS ( + SELECT 1 + UNION ALL + SELECT n + 1 FROM t1 +) + ((SELECT n FROM t1) UNION ALL (SELECT n FROM t1)) LIMIT 20; + +-- Recursive CTE with self reference inside Window function +WITH RECURSIVE win(id, val) AS ( + SELECT 1, CAST(10 AS BIGINT) + UNION ALL + SELECT id + 1, SUM(val) OVER (ORDER BY id ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) + FROM win WHERE id < 3 +) +SELECT * FROM win; + +WITH RECURSIVE t1(n) AS ( + SELECT 1 + UNION ALL + (SELECT n + 1 FROM t1 WHERE n < 5 ORDER BY n) +) +SELECT * FROM t1; + +WITH RECURSIVE t1(n) AS ( + SELECT 1 FROM t1 + UNION ALL + SELECT n+1 FROM t1 WHERE n < 5) +SELECT * FROM t1; + +WITH RECURSIVE t1 AS ( + SELECT 1 AS n FROM t1 + UNION ALL + SELECT n+1 FROM t1 WHERE n < 5) +SELECT * FROM t1; + +WITH RECURSIVE t1(n) AS ( + WITH t2(m) AS (SELECT 1) + SELECT 1 FROM t1 + UNION ALL + SELECT n+1 FROM t1 WHERE n < 5) +SELECT * FROM t1; + +WITH RECURSIVE t1 AS ( + WITH t2(m) AS (SELECT 1) + SELECT 1 AS n FROM t1 + UNION ALL + SELECT n+1 FROM t1 WHERE n < 5) +SELECT * FROM t1; + +-- Query with recursion that gets optimized to empty relation +WITH RECURSIVE t AS ( + SELECT 1 AS n + UNION ALL + SELECT n + m + FROM (SELECT 2 as m) subq + JOIN t ON n = m + WHERE n <> m +) +SELECT * FROM t; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/cte.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/cte.sql index ecf760ecac7..abcf2416a38 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/cte.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/cte.sql @@ -1,6 +1,7 @@ create temporary view t as select * from values 0, 1, 2 as t(id); create temporary view t2 as select * from values 0, 1 as t(id); create temporary view t3 as select * from t; +create table t4(col1 TIMESTAMP); -- WITH clause should not fall into infinite loop by referencing self WITH s AS (SELECT 1 FROM s) SELECT * FROM s; @@ -178,7 +179,117 @@ with cte AS (SELECT * FROM va) SELECT * FROM cte; -- Self-refer to non-existent cte, should fail. with cte as (select * from cte) select * from cte; +-- WithCTE placement for WITH in boch UNION branches +SELECT * FROM ( + ( + WITH cte AS (SELECT 1) + SELECT * FROM cte + ) UNION ALL ( + WITH cte AS (SELECT 2) + SELECT * FROM cte + ) +); + +-- CTE in the left UNION branch with a subquery referencing that CTE name on the right +SELECT * FROM ( + ( + WITH cte AS (SELECT 2) + SELECT * FROM cte + ) UNION ALL ( + SELECT 1 WHERE EXISTS ( + SELECT * FROM cte + ) + ) +); + +-- CTEs in subqueries in both branches of UNION +SELECT + * +FROM + VALUES (1) +WHERE EXISTS ( + WITH cte AS (SELECT 1) + SELECT * FROM cte +) +UNION ALL ( + SELECT + * + FROM + VALUES (1) + WHERE EXISTS ( + WITH cte AS (SELECT 1) + SELECT * FROM cte + ) +); + +WITH cte AS ( + SELECT + * + FROM + VALUES (1) + WHERE EXISTS ( + WITH cte AS (SELECT 1) + SELECT * FROM cte + ) + UNION ALL ( + SELECT + * + FROM + VALUES (1) + WHERE EXISTS ( + WITH cte AS (SELECT 1) + SELECT * FROM cte + ) + ) +) +SELECT * FROM cte; + +SELECT * FROM ( + WITH cte AS (SELECT 1) + SELECT + * + FROM VALUES (1) + WHERE EXISTS ( + WITH cte AS (SELECT 1) + SELECT * FROM cte + ) + UNION ALL ( + SELECT + * + FROM + VALUES (1) + WHERE EXISTS ( + WITH cte AS (SELECT 1) + SELECT * FROM cte + ) + ) +); + +-- CTE name with dots +WITH `a.b.c` AS ( + SELECT 1 +) +SELECT * FROM `a.b.c`; + +-- Expression ID assignment in CTE with JOIN +SELECT * FROM ( + WITH cte1 AS (SELECT * FROM t4) SELECT t4.col1 FROM t4 JOIN cte1 USING (col1) +); + +SELECT * FROM ( + WITH cte1 AS (SELECT * FROM t4) SELECT cte1.col1 FROM t4 JOIN cte1 USING (col1) +); + +SELECT * FROM ( + WITH cte1 AS (SELECT * FROM t4) SELECT t4.col1 FROM cte1 JOIN t4 USING (col1) +); + +SELECT * FROM ( + WITH cte1 AS (SELECT * FROM t4) SELECT cte1.col1 FROM cte1 JOIN t4 USING (col1) +); + -- Clean up DROP VIEW IF EXISTS t; DROP VIEW IF EXISTS t2; DROP VIEW IF EXISTS t3; +DROP TABLE IF EXISTS t4; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/describe.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/describe.sql index dbe5bc840bc..2b4191a2825 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/describe.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/describe.sql @@ -64,6 +64,13 @@ DESC t PARTITION (c='Us'); -- ParseException: PARTITION specification is incomplete DESC t PARTITION (c='Us', d); +-- DESC SCHEMA +DROP SCHEMA IF EXISTS test_schema; +CREATE SCHEMA test_schema DEFAULT COLLATION UNICODE; +DESCRIBE SCHEMA EXTENDED test_schema; +ALTER SCHEMA test_schema DEFAULT COLLATION UTF8_LCASE; +DESCRIBE SCHEMA EXTENDED test_schema; + -- DESC Temp View DESC temp_v; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/double-quoted-identifiers.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/double-quoted-identifiers.sql index ffb52b40334..202b55f4f45 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/double-quoted-identifiers.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/double-quoted-identifiers.sql @@ -1,4 +1,4 @@ --- All these should error out in the parser +-- All these should error out in the parser in non-ansi mode, error out in the analyzer in ansi mode SELECT 1 FROM "not_exist"; USE SCHEMA "not_exist"; @@ -15,6 +15,8 @@ SELECT "not_exist"(); SELECT "not_exist".not_exist(); +select 1 from "not_""exists"; + -- All these should error out in analysis SELECT 1 FROM `hello`; @@ -35,6 +37,7 @@ SELECT `not_exist`.not_exist(); -- Strings in various situations all work SELECT "hello"; +-- Ok for non-ansi mode, error for ansi-mode CREATE TEMPORARY VIEW v(c1 COMMENT "hello") AS SELECT 1; DROP VIEW v; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/execute-immediate.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/execute-immediate.sql index f7d27c6c0b0..16e1850d5e5 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/execute-immediate.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/execute-immediate.sql @@ -87,13 +87,20 @@ EXECUTE IMMEDIATE 'SELECT \'invalid_cast_error_expected\'' INTO res_id; -- require query when using INTO EXECUTE IMMEDIATE 'INSERT INTO x VALUES (?)' INTO res_id USING 1; +-- require query when using INTO with SET VAR command +DECLARE OR REPLACE testvarA INT; +EXECUTE IMMEDIATE 'SET VAR testVarA = 1' INTO testVarA; + -- use column in using - should fail as we expect variable here EXECUTE IMMEDIATE 'SELECT * FROM tbl_view WHERE ? = id' USING id; -- either positional or named parameters must be used -EXECUTE IMMEDIATE 'SELECT * FROM tbl_view where ? = id and :first = name' USING 1, 'name2' as first; +EXECUTE IMMEDIATE 'SELECT * FROM tbl_view where ? = id and :first = name' USING 1 as x, 'name2' as first; + +-- all parameters must be named +EXECUTE IMMEDIATE 'SELECT * FROM tbl_view where :x = id and :first = name' USING 1, 'name2' as first; --- all paramerers must be named +-- all parameters must be named EXECUTE IMMEDIATE 'SELECT * FROM tbl_view where :first = name' USING 1, 'name2' as first; -- internal syntax error @@ -109,8 +116,10 @@ EXECUTE IMMEDIATE b; SET VAR sql_string = 'SELECT * from tbl_view where name = :first or id = :second'; SET VAR a = 'na'; --- expressions not supported - feature not supported +-- constant expressions are supported EXECUTE IMMEDIATE 'SELECT * from tbl_view where name = :first' USING CONCAT(a , "me1") as first; + +-- subquery in using not supported EXECUTE IMMEDIATE 'SELECT * from tbl_view where name = :first' USING (SELECT 42) as first, 'name2' as second; -- INTO variables not matching scalar types @@ -140,10 +149,151 @@ EXECUTE IMMEDIATE 'SELECT id FROM tbl_view WHERE id = :p' USING p, 'p'; EXECUTE IMMEDIATE 'SELECT id, data.f1 FROM tbl_view WHERE id = 10' INTO res_id, res_id; -- nested execute immediate -EXECUTE IMMEDIATE 'EXECUTE IMMEDIATE \'SELECT id FROM tbl_view WHERE id = ? USING 10\''; +EXECUTE IMMEDIATE 'EXECUTE IMMEDIATE \'SELECT id FROM tbl_view WHERE id = ?\' USING 10'; -- sqlString is null SET VAR sql_string = null; EXECUTE IMMEDIATE sql_string; -DROP TABLE x; \ No newline at end of file +-- sqlString is not a string +SET VAR sql_string = 5; +EXECUTE IMMEDIATE sql_string; + +-- sqlString is not a well formed SQL statement. +SET VAR sql_string = 'hello'; +EXECUTE IMMEDIATE length(sql_string); + +-- mixed positional and named parameters in query +EXECUTE IMMEDIATE 'SELECT 42 where ? = :first' USING 1, 2 as first; + +-- non-string variable as sqlString parameter +DECLARE int_var INT; +SET VAR int_var = 42; +EXECUTE IMMEDIATE int_var; + +-- null string as sqlString parameter +DECLARE null_var STRING; +SET VAR null_var = null; +EXECUTE IMMEDIATE null_var; + +-- unsupported expression for parameter (subquery) +EXECUTE IMMEDIATE 'SELECT ?' USING (SELECT 1); + +-- named query with unnamed parameters +EXECUTE IMMEDIATE 'SELECT :first' USING 2, 3; + +-- Query is not a constant +EXECUTE IMMEDIATE (SELECT c FROM (VALUES(1)) AS T(c)); + +DROP TABLE x; + +-- Test data type conversion correctness for LiteralToSqlConverter +-- Each test validates that the parameter is correctly converted to SQL and executed + +-- !query +-- Basic numeric types +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING 5 AS p; + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING 5L AS p; + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING 5S AS p; + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING 5Y AS p; + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING 3.14F AS p; + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING 3.14159D AS p; + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING 123.45BD AS p; + +-- !query +-- Boolean type +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING true AS p; + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING false AS p; + +-- !query +-- String types +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING 'hello world' AS p; + +-- !query +-- String with single quotes (test escaping) +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING 'it''s a test' AS p; + +-- !query +-- Date and timestamp types +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING DATE '2023-12-25' AS p; + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING TIMESTAMP '2023-12-25 10:30:45' AS p; + +-- !query +-- TimestampNTZ type +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING TIMESTAMP_NTZ '2023-12-25 10:30:45' AS p; + +-- !query +-- Null values +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING CAST(NULL AS INT) AS p; + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING CAST(NULL AS STRING) AS p; + +-- !query +-- Binary type +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, hex(:p) as val' USING X'010203FF' AS p; + +-- !query +-- Interval types +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING INTERVAL '3' DAY AS p; + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING INTERVAL '2' YEAR AS p; + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING INTERVAL '1-2' YEAR TO MONTH AS p; + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING INTERVAL '3 4:5:6' DAY TO SECOND AS p; + +-- !query +-- Additional numeric type tests +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING 999.999BD AS p; + +-- !query +-- Test multiple parameters with different types +EXECUTE IMMEDIATE 'SELECT typeof(:p1) as type1, :p1 as val1, typeof(:p2) as type2, :p2 as val2' + USING 42 as p1, 'test string' as p2; + +-- !query +-- Array types (simple) +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING ARRAY(1, 2, 3) AS p; + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING ARRAY('a', 'b', 'c') AS p; + +-- !query +-- Nested array +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING ARRAY(ARRAY(1, 2), ARRAY(3, 4)) AS p; + +-- !query +-- Map types +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING MAP('key1', 'value1', 'key2', 'value2') AS p; + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING MAP(1, 'one', 2, 'two') AS p; + +-- !query +-- Test unbound parameter markers without USING clause +-- named parameter without USING clause should fail +EXECUTE IMMEDIATE 'SELECT :param'; + +-- !query +-- positional parameter without USING clause should fail +EXECUTE IMMEDIATE 'SELECT ?'; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/explain.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/explain.sql index 698ca009b4f..96dddafd82a 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/explain.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/explain.sql @@ -96,6 +96,15 @@ EXPLAIN FORMATTED ) SELECT * FROM cte1 a, cte1 b WHERE a.key = b.key; +-- Recursion +EXPLAIN FORMATTED + WITH RECURSIVE r(level) AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r WHERE level < 9 + ) +SELECT * FROM r; + -- A spark plan which has innerChildren other than subquery EXPLAIN FORMATTED CREATE VIEW explain_view AS diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/extract-value-resolution-edge-cases.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/extract-value-resolution-edge-cases.sql new file mode 100644 index 00000000000..5a2784d5427 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/extract-value-resolution-edge-cases.sql @@ -0,0 +1,10 @@ +CREATE TABLE t1(col1 STRUCT, a STRING); + +-- Correctly fallback from ambiguous reference due to ExtractValue alias +SELECT col1.a, a FROM t1 ORDER BY a; +SELECT col1.a, a FROM t1 ORDER BY col1.a; + +-- Indexing a result of a function that returns a complex type +SELECT split(col1, '-')[1] AS a FROM VALUES('a-b') ORDER BY split(col1, '-')[1]; + +DROP TABLE t1; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/generators.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/generators.sql new file mode 100644 index 00000000000..1908655dd3c --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/generators.sql @@ -0,0 +1,79 @@ +CREATE OR REPLACE TEMPORARY VIEW testData AS SELECT * FROM VALUES +(1, 1), (1, 2), (2, 1), (2, 2), (3, 1), (3, 2), (null, 1), (3, null), (null, null) +AS testData(a, b); + +-- explode function +SELECT explode(array(a, b)) AS elem FROM testData; +SELECT explode(array(a, b)) AS elem, 'Spark' FROM testData; +SELECT explode(array(a, b)) AS null, null FROM testData; +SELECT explode(array(1, 2)) AS null, null, 'column'; +SELECT explode(map(1, 'a', 2, 'b')); +SELECT explode(struct(1, 'a', 2, 'b')); +SELECT explode(1); +SELECT explode(null); +SELECT explode(cast (null as array)); + +-- explode_outer function +SELECT explode_outer(array(a, b)) AS elem FROM testData; +SELECT explode_outer(array(a, b)) AS elem, 'Spark' FROM testData; +SELECT explode_outer(array(a, b)) AS null, null FROM testData; +SELECT explode_outer(array(1, 2)) AS null, null, 'column'; +SELECT explode_outer(map(1, 'a', 2, 'b')); +SELECT explode_outer(struct(1, 'a', 2, 'b')); +SELECT explode_outer(1); +SELECT explode_outer(null); +SELECT explode_outer(cast (null as array)); + +-- posexplode function +SELECT posexplode(array(a, b)) AS elem FROM testData; +SELECT posexplode(array(a, b)) AS (elem, elem2) FROM testData; +SELECT posexplode(array(a, b)) AS (null, null) FROM testData; +SELECT posexplode(array(1, 2)) AS (null, null, column); +SELECT posexplode(map(1, 'a', 2, 'b')); +SELECT posexplode(struct(1, 'a', 2, 'b')); +SELECT posexplode(1); +SELECT posexplode(null); +SELECT posexplode(cast (null as array)); + +-- posexplode_outer function +SELECT posexplode_outer(array(a, b)) AS elem FROM testData; +SELECT posexplode_outer(array(a, b)) AS (elem, elem2) FROM testData; +SELECT posexplode_outer(array(a, b)) AS (null, null) FROM testData; +SELECT posexplode_outer(array(1, 2)) AS (null, null, column); +SELECT posexplode_outer(map(1, 'a', 2, 'b')); +SELECT posexplode_outer(struct(1, 'a', 2, 'b')); +SELECT posexplode_outer(1); +SELECT posexplode_outer(null); +SELECT posexplode_outer(cast (null as array)); + +-- inline function +SELECT inline(array(struct(1, 'a'))); +SELECT inline(array(struct(null, 'a'), struct(null, 'b'))); +SELECT inline(array(struct(a, 'a'), struct(a, 'b'))) FROM testData; +SELECT inline(array(struct(a, 'a'), struct(b, 'b'))) FROM testData; +SELECT inline(1); +SELECT inline(array(1, 'a')); +SELECT inline(struct(1, 'a')); + +-- inline_outer function +SELECT inline_outer(array(struct(1, 'a'))); +SELECT inline_outer(array(struct(null, 'a'), struct(null, 'b'))); +SELECT inline_outer(array(struct(a, 'a'), struct(a, 'b'))) FROM testData; +SELECT inline_outer(array(struct(a, 'a'), struct(b, 'b'))) FROM testData; +SELECT inline_outer(1); +SELECT inline_outer(array(1, 'a')); +SELECT inline_outer(struct(1, 'a')); + +-- json_tuple function +select json_tuple('{"a": 1, "b": 2}', 'a', 'b'); +select json_tuple(); +select json_tuple('{"a": 1}'); +select json_tuple('{"a": 1}', 1); +select json_tuple('{"a": 1}', null); + +-- stack function +select stack(1, 1, 2, 3); +select stack(2, 1, 1.1, 'a', 2, 2.2, 'b'); +select stack(2, 1, 1.1, null, 2, null, 'b'); +select stack(); +select stack(2, explode(array(1, 2, 3))); diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/group-by-alias.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/group-by-alias.sql index 75afc82f998..80456e2e5cf 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/group-by-alias.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/group-by-alias.sql @@ -46,6 +46,39 @@ SELECT COUNT(b) AS k FROM testData GROUP BY k; -- Ordinal is replaced correctly when grouping by alias of a literal SELECT MAX(col1), 3 as abc FROM VALUES(1),(2),(3),(4) GROUP BY col1 % abc; +-- GROUP BY attribute takes precedence over alias +SELECT 1 AS a FROM testData GROUP BY `a`; + +-- Group alias on subquery with CTE inside +SELECT ( + WITH cte AS (SELECT 1) + SELECT * FROM cte +) AS subq1 +FROM + VALUES (1) +GROUP BY + subq1 +; + +-- Group by alias on subquery with relation +SELECT ( + SELECT a FROM testData LIMIT 1 +) AS subq1 +FROM + VALUES (1) +GROUP BY + subq1 +; + +-- Group by alias which has IntegerLiteral as its child +SELECT 111 AS abc GROUP BY 'a', abc; +SELECT *, 111 AS abc FROM VALUES ('a', 'b', 'c') GROUP BY col1, col2, col3, abc; + +-- Group by alias should respect order of aliases in aggregate expressions list +SELECT col1 as a, col2 AS a FROM values('a','b') GROUP BY col2, a; +SELECT 1 AS a, 2 AS a FROM VALUES (1) t (a) GROUP BY a HAVING a > 1 ORDER BY a; +SELECT 1 AS a, 2 AS a FROM VALUES (1) t (col1) GROUP BY a HAVING a > 1 ORDER BY a; + -- turn off group by aliases set spark.sql.groupByAliases=false; @@ -56,3 +89,6 @@ SELECT 1 AS col FROM testData GROUP BY `col`; -- GROUP BY attribute takes precedence over alias SELECT 1 AS a FROM testData GROUP BY `a`; + +-- GROUP BY alias cannot reference nested fields +SELECT col1 AS a FROM VALUES (NAMED_STRUCT('f1', 1)) GROUP BY a.f1; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/group-by-all.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/group-by-all.sql index 4400c0b5786..dd05b1b8d26 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/group-by-all.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/group-by-all.sql @@ -82,4 +82,34 @@ select country, (select count(*) from data d1 where d1.country = d2.country), co select (select count(*) from data d1 where d1.country = d2.country) + count(id) from data d2 group by all; -- SELECT list contains unresolved column, should not report UNRESOLVED_ALL_IN_GROUP_BY -select non_exist from data group by all; \ No newline at end of file +select non_exist from data group by all; + +-- GROUP BY ALL with a * in aggregate expressions list +SELECT * FROM data GROUP BY ALL; + +SELECT 4 AS a, 5 AS b, 6 AS c, * FROM data GROUP BY ALL; + +SELECT *, 4 AS a, 5 AS b, 6 AS c FROM data GROUP BY ALL; + +SELECT 4 AS a, 5 AS b, *, 6 AS c FROM data GROUP BY ALL; + +-- Group by ALL on subquery with CTE inside +SELECT ( + WITH cte AS (SELECT 1) + SELECT * FROM cte +) AS subq1 +FROM + VALUES (1) +GROUP BY + ALL +; + +-- Group by ALL on subquery with relation +SELECT ( + SELECT country FROM data LIMIT 1 +) AS subq1 +FROM + VALUES (1) +GROUP BY + ALL +; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/group-by-ordinal.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/group-by-ordinal.sql index b773396c050..ca563ba5db0 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/group-by-ordinal.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/group-by-ordinal.sql @@ -89,6 +89,27 @@ select a, b, count(1) from data group by cube(-1, 2); select a, b, count(1) from data group by cube(1, 3); +-- Group by ordinal on subquery with CTE inside +SELECT ( + WITH cte AS (SELECT 1) + SELECT * FROM cte +) AS subq1 +FROM + VALUES (1) +GROUP BY + 1 +; + +-- Group by ordinal on subquery with relation +SELECT ( + SELECT a FROM data LIMIT 1 +) AS subq1 +FROM + VALUES (1) +GROUP BY + 1 +; + -- turn off group by ordinal set spark.sql.groupByOrdinal=false; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/group-by.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/group-by.sql index c1b5e88c43f..f114e04ea09 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/group-by.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/group-by.sql @@ -7,6 +7,7 @@ CREATE OR REPLACE TEMPORARY VIEW testData AS SELECT * FROM VALUES (1, 1), (1, 2), (2, 1), (2, 2), (3, 1), (3, 2), (null, 1), (3, null), (null, null) AS testData(a, b); +CREATE TABLE t1(col1 TIMESTAMP, col2 STRING); -- Aggregate with empty GroupBy expressions. SELECT a, COUNT(b) FROM testData; @@ -326,4 +327,14 @@ GROUP BY a; -- MAP>> SELECT count(*) FROM VALUES (Map(1, Array(Map(1,2)), 2, Array(Map(2, 3, 1, 2)))), (Map(2, Array(Map(1, 2, 2,3)), 1, Array(Map(1, 2)))), (Map(1, Array(Map(1,2)), 2, Array(Map(2, 4)))) as t(a) -GROUP BY a; \ No newline at end of file +GROUP BY a; + +-- Attributes under Last, First, AnyValue can be resolved using the hidden output. +SELECT col1 FROM t1 GROUP BY ALL HAVING first(col2) = 'a'; +SELECT col1 FROM t1 GROUP BY col1 HAVING EXISTS (SELECT first(t1.col2) == 0); +SELECT col1 FROM t1 GROUP BY ALL HAVING last(col2) = 'a'; +SELECT col1 FROM t1 GROUP BY col1 HAVING EXISTS (SELECT last(t1.col2) == 0); +SELECT col1 FROM t1 GROUP BY ALL HAVING any_value(col2) = 'a'; +SELECT col1 FROM t1 GROUP BY col1 HAVING EXISTS (SELECT any_value(t1.col2) == 0); + +DROP TABLE t1; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/grouping_set.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/grouping_set.sql index 909c36c926c..013a5419f8d 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/grouping_set.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/grouping_set.sql @@ -13,6 +13,10 @@ SELECT a, b, c, count(d) FROM grouping GROUP BY a, b, c GROUPING SETS ((a)); -- SPARK-17849: grouping set throws NPE #3 SELECT a, b, c, count(d) FROM grouping GROUP BY a, b, c GROUPING SETS ((c)); +-- SPARK-52007: grouping set doesn't produce expression IDs in grouping expressions +SELECT a, b, c, d FROM grouping GROUP BY GROUPING SETS (a, b, c, d); +SELECT a, b FROM grouping GROUP BY GROUPING SETS (a, b, d + 1) ORDER BY `(d + 1)`; + -- Group sets without explicit group by SELECT c1, sum(c2) FROM (VALUES ('x', 10, 0), ('y', 20, 0)) AS t (c1, c2, c3) GROUP BY GROUPING SETS (c1); diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/having-and-order-by-recursive-type-name-resolution.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/having-and-order-by-recursive-type-name-resolution.sql new file mode 100644 index 00000000000..1f53ca359fe --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/having-and-order-by-recursive-type-name-resolution.sql @@ -0,0 +1,143 @@ +-- This test file contains queries that test recursive types name resolution in ORDER BY and HAVING clauses. + +-- Alias type: String, Table column type: Struct +SELECT 'a' AS col1 FROM VALUES (NAMED_STRUCT('a', 1)) t (col1) GROUP BY col1 ORDER BY col1.a; +SELECT 'a' AS col1 FROM VALUES (NAMED_STRUCT('a', 1)) t (col1) GROUP BY col1 HAVING col1.a > 0; +SELECT 'a' AS col1 FROM VALUES (NAMED_STRUCT('a', 1)) t (col1) GROUP BY col1 HAVING col1.a > 0 ORDER BY col1.a; + +-- Alias type: Struct, Table column type: String +SELECT NAMED_STRUCT('a', 1) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 ORDER BY col1.a; +SELECT NAMED_STRUCT('a', 1) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 HAVING col1.a > 0; +SELECT NAMED_STRUCT('a', 1) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 HAVING col1.a > 0 ORDER BY col1.a; + +-- Alias type: Struct, Table column type: Struct +SELECT NAMED_STRUCT('a', 1) AS col1 FROM VALUES (NAMED_STRUCT('a', 0)) t (col1) GROUP BY col1 ORDER BY col1.a; +SELECT NAMED_STRUCT('a', 1) AS col1 FROM VALUES (NAMED_STRUCT('a', 0)) t (col1) GROUP BY col1 HAVING col1.a > 0; +SELECT NAMED_STRUCT('a', 1) AS col1 FROM VALUES (NAMED_STRUCT('a', 0)) t (col1) GROUP BY col1 HAVING col1.a > 0 ORDER BY col1.a; + +-- Alias type: String, Table column type: Array +SELECT 'a' AS col1 FROM VALUES (ARRAY(1)) t (col1) GROUP BY col1 ORDER BY col1[0]; +SELECT 'a' AS col1 FROM VALUES (ARRAY(1)) t (col1) GROUP BY col1 HAVING col1[0] > 0; +SELECT 'a' AS col1 FROM VALUES (ARRAY(1)) t (col1) GROUP BY col1 HAVING col1[0] > 0 ORDER BY col1[0]; + +-- Alias type: Array, Table column type: String +SELECT ARRAY(1) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 ORDER BY col1[0]; +SELECT ARRAY(1) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 HAVING col1[0] > 0; + +-- Alias type: Struct, Table column type: String +SELECT NAMED_STRUCT('a', NAMED_STRUCT('b', 1)) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 ORDER BY col1.a.b; +SELECT NAMED_STRUCT('a', NAMED_STRUCT('b', 1)) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 HAVING col1.a.b > 0; +SELECT NAMED_STRUCT('a', NAMED_STRUCT('b', 1)) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 HAVING col1.a.b > 0 ORDER BY col1.a.b; + +-- Alias type: Array, Table column type: String +SELECT ARRAY(NAMED_STRUCT('a', 1)) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 ORDER BY col1[0].a; +SELECT ARRAY(NAMED_STRUCT('a', 1)) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 HAVING col1[0].a > 0; + +-- Alias type: String, Table column type: Map +SELECT 'a' AS col1 FROM VALUES (MAP('key', 1)) t (col1) GROUP BY col1 ORDER BY col1['key']; +SELECT 'a' AS col1 FROM VALUES (MAP('key', 1)) t (col1) GROUP BY col1 HAVING col1['key'] > 0; +SELECT 'a' AS col1 FROM VALUES (MAP('key', 1)) t (col1) GROUP BY col1 HAVING col1['key'] > 0 ORDER BY col1['key']; + +-- Alias type: Map, Table column type: String +SELECT MAP('key', 1) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 ORDER BY col1['key']; +SELECT MAP('key', 1) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 HAVING col1['key'] > 0; + +-- Using ORDER BY with named_struct +SELECT named_struct('a',1) as col, col1 +FROM values(named_struct('a',1)) +ORDER BY col1.a; + +-- Using HAVING with named_struct +SELECT named_struct('a', 1) AS col1, col1 +FROM values(named_struct('a', 1)) +GROUP BY col1 +HAVING col1.a > 0; + +-- Using array instead of named_struct with ORDER BY +SELECT array(1, 2, 3) AS col1, col1 +FROM values(array(1, 2, 3)) +ORDER BY col1[0]; + +-- Using array with HAVING +SELECT array(1, 2, 3) AS col1, col1 +FROM values(array(1, 2, 3)) +GROUP BY col1 +HAVING col1[1] > 1; + +-- Using map with ORDER BY +SELECT map('a', 1, 'b', 2) AS col1, col1 +FROM values(map('a', 1, 'b', 2)) +ORDER BY col1['a']; + +-- Using map with HAVING +SELECT map('a', 1, 'b', 2) AS col1, col1 +FROM values(map('a', 1, 'b', 2)) +GROUP BY col1 +HAVING col1['b'] > 1; + +-- Both alias and column are named the `col1`, but fields are named `a` and `b` + +-- Reference to column field +SELECT NAMED_STRUCT('b', 1) AS col1 FROM VALUES (NAMED_STRUCT('a', 0)) t (col1) GROUP BY col1 ORDER BY col1.a; +SELECT NAMED_STRUCT('b', 1) AS col1 FROM VALUES (NAMED_STRUCT('a', 0)) t (col1) GROUP BY col1 HAVING col1.a > 0; +SELECT NAMED_STRUCT('b', 1) AS col1 FROM VALUES (NAMED_STRUCT('a', 0)) t (col1) GROUP BY col1 HAVING col1.a > 0 ORDER BY col1.a; + +-- Reference to alias field +SELECT NAMED_STRUCT('b', 1) AS col1 FROM VALUES (NAMED_STRUCT('a', 0)) t (col1) GROUP BY col1 ORDER BY col1.b; +SELECT NAMED_STRUCT('b', 1) AS col1 FROM VALUES (NAMED_STRUCT('a', 0)) t (col1) GROUP BY col1 HAVING col1.b > 0; +SELECT NAMED_STRUCT('b', 1) AS col1 FROM VALUES (NAMED_STRUCT('a', 0)) t (col1) GROUP BY col1 HAVING col1.b > 0 ORDER BY col1.b; + +SELECT col1.name +FROM VALUES (NAMED_STRUCT('name', 'test', 'id', 1)) t (col1) +GROUP BY col1 +HAVING col1.id > 0 +ORDER BY col1.name; + +SELECT col1.items[0] +FROM VALUES (NAMED_STRUCT('items', ARRAY(1, 2, 3))) t (col1) +GROUP BY col1 +HAVING col1.items[0] > 0 +ORDER BY col1.items[0]; + +SELECT col1.data['key'] +FROM VALUES (NAMED_STRUCT('data', MAP('key', 'value', 'num', '42'))) t (col1) +GROUP BY col1 +HAVING col1.data['num'] IS NOT NULL +ORDER BY col1.data['key']; + +SELECT col1.users[0].name +FROM VALUES ( + NAMED_STRUCT('users', ARRAY(NAMED_STRUCT('name', 'John', 'age', 30))) + ) t (col1) +GROUP BY col1 +HAVING col1.users[0].age > 25 +ORDER BY col1.users[0].name; + +SELECT col1.person.address.city +FROM VALUES ( + NAMED_STRUCT('person', NAMED_STRUCT('address', NAMED_STRUCT('city', 'NYC', 'zip', 10001))) + ) t (col1) +GROUP BY col1 +HAVING col1.person.address.zip > 10000 +ORDER BY col1.person.address.city; + +SELECT col1.matrix[0][1] +FROM VALUES ( + NAMED_STRUCT('matrix', ARRAY(ARRAY(1, 2), ARRAY(3, 4))) + ) t (col1) +GROUP BY col1 +HAVING col1.matrix[0][0] < 5 +ORDER BY col1.matrix[0][1]; + +SELECT col1.data[0].props['status'] +FROM VALUES ( + NAMED_STRUCT('data', ARRAY(NAMED_STRUCT('props', MAP('status', 'active')))) + ) t (col1) +GROUP BY col1 +HAVING col1.data[0].props['status'] = 'active'; + +SELECT col1.nums[0] + col1.nums[1] AS sum_val +FROM VALUES (NAMED_STRUCT('nums', ARRAY(10, 20))) t (col1) +GROUP BY col1 +HAVING col1.nums[0] + col1.nums[1] > 25 +ORDER BY col1.nums[0]; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/having.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/having.sql index 4c25a60c8ab..0f3f9e2cad6 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/having.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/having.sql @@ -39,3 +39,78 @@ SELECT k, sum(v) FROM hav GROUP BY k HAVING sum(v) > 2 ORDER BY sum(v); -- SPARK-28386: Resolve ORDER BY agg function with HAVING clause, while the agg function does not present on SELECT list SELECT k, sum(v) FROM hav GROUP BY k HAVING sum(v) > 2 ORDER BY avg(v); + +-- SPARK-52385: Remove TempResolvedColumns from InheritAnalysisRules name +SELECT sum(v) FROM hav HAVING avg(try_add(v, 1)) = 1; +SELECT sum(v) FROM hav HAVING sum(try_add(v, 1)) = 1; +SELECT sum(v) FROM hav HAVING sum(ifnull(v, 1)) = 1; +SELECT sum(v) FROM hav GROUP BY ALL HAVING sum(ifnull(v, 1)) = 1; +SELECT sum(v) FROM hav GROUP BY v HAVING sum(ifnull(v, 1)) = 1; +SELECT v + 1 FROM hav GROUP BY ALL HAVING avg(try_add(v, 1)) = 1; +SELECT v + 1 FROM hav GROUP BY ALL HAVING avg(try_add(v, 1) + 1) = 1; +SELECT sum(v) FROM hav GROUP BY ifnull(v, 1) + 1 order by ifnull(v, 1) + 1; + +-- HAVING condition should prefer table columns over aliases +SELECT 1 AS `2`, 2 FROM VALUES (2) t (`2`) GROUP BY `2` HAVING `2` > 2; +SELECT 2, 1 AS `2` FROM VALUES (2) t (`2`) GROUP BY `2` HAVING `2` > 2; +SELECT 1 AS `2` FROM VALUES (2) t (`2`) GROUP BY `2` HAVING `2` > 2; +SELECT 2 FROM VALUES (2) t (`2`) GROUP BY `2` HAVING `2` > 2; + +-- HAVING condition is resolved as a semantically equivalent to one in the SELECT list +SELECT SUM(v) + 1 FROM hav HAVING SUM(v) + 1; +SELECT 1 + SUM(v) FROM hav HAVING SUM(v) + 1; +SELECT SUM(v) + 1 FROM hav HAVING 1 + SUM(v); +SELECT MAX(v) + SUM(v) FROM hav HAVING SUM(v) + MAX(v); +SELECT SUM(v) + 1 + MIN(v) FROM hav HAVING 1 + 1 + 1 + MIN(v) + 1 + SUM(v); + +-- HAVING with outer reference to alias in outer project list +SELECT col1 AS alias +FROM values(1) +GROUP BY col1 +HAVING ( + SELECT col1 = 1 +); + +SELECT col1 AS alias +FROM values(named_struct('a', 1)) +GROUP BY col1 +HAVING ( + SELECT col1.a = 1 +); + +SELECT col1 AS alias +FROM values(array(1)) +GROUP BY col1 +HAVING ( + SELECT col1[0] = 1 +); + +SELECT col1 AS alias +FROM values(map('a', 1)) +GROUP BY col1 +HAVING ( + SELECT col1[0] = 1 +); + +-- Missing attribute (col2) in HAVING is added only once +SELECT col1 FROM VALUES(1,2) GROUP BY col1, col2 HAVING col2 = col2; +SELECT col1 AS a, a AS b FROM VALUES(1,2) GROUP BY col1, col2 HAVING col2 = col2; + +-- Replacing Having condition with alias from below +SELECT col1, col1 AS a FROM VALUES(1) GROUP BY col1 HAVING col1 > 0; +SELECT col1 AS a, col1 FROM VALUES(1) GROUP BY col1 HAVING col1 > 0; +SELECT make_date(col1, col2, col3) AS a, a AS b FROM VALUES(1,2,3) GROUP BY make_date(col1, col2, col3) HAVING make_date(col1, col2, col3) > '2025-01-01'; +SELECT 1 AS a, 1 / a AS b, ZEROIFNULL(SUM(col1)) FROM VALUES(1) GROUP BY 1 HAVING ZEROIFNULL(SUM(col1)) > 0; +SELECT col1 AS a, SUM(col2) AS b, CASE WHEN col1 = 1 THEN 1 END AS c FROM VALUES(1,2) GROUP BY col1 HAVING CASE WHEN col1 = 1 THEN 1 END = 1; + +-- Deduplicate expressions before adding them to Aggregate +SELECT col1 FROM VALUES(1,2) GROUP BY col1 HAVING MAX(col2) == (SELECT 1 WHERE MAX(col2) = 1); +SELECT col1 FROM VALUES(1,2) GROUP BY col1 HAVING (SELECT 1 WHERE MAX(col2) = 1) == MAX(col2); +SELECT col1 FROM VALUES(1,2) GROUP BY col1 HAVING (SELECT 1 WHERE MAX(col2) = 1) == (SELECT 1 WHERE MAX(col2) = 1); +SELECT col1 FROM VALUES(1,2) GROUP BY col1 HAVING bool_or(col2 = 1) AND bool_or(col2 = 1); +SELECT 1 GROUP BY COALESCE(1, 1) HAVING COALESCE(1, 1) = 1 OR COALESCE(1, 1) IS NOT NULL; +SELECT col1 FROM VALUES (1) t1 GROUP BY col1 HAVING ( + SELECT MAX(t2.col1) FROM VALUES (1) t2 WHERE t2.col1 == MAX(t1.col1) GROUP BY t2.col1 HAVING ( + SELECT t3.col1 FROM VALUES (1) t3 WHERE t3.col1 == MAX(t2.col1) + ) +); diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/higher-order-functions.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/higher-order-functions.sql index 37081de012e..f1c92327bde 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/higher-order-functions.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/higher-order-functions.sql @@ -102,4 +102,66 @@ select transform(ys, all -> all * all) as v from values (array(32, 97)) as t(ys) select transform(ys, (all, i) -> all + i) as v from values (array(32, 97)) as t(ys); -- SPARK-32819: Aggregate on nested string arrays -select aggregate(split('abcdefgh',''), array(array('')), (acc, x) -> array(array(x))); \ No newline at end of file +select aggregate(split('abcdefgh',''), array(array('')), (acc, x) -> array(array(x))); + +-- HigherOrderFunctions without lambda variables + +select aggregate(array(1, 2, 3), 0, 100) as aggregate_int_literal; +select aggregate(array(1, 2, 3), map(), map('result', 999)) as aggregate_map_literal; +select aggregate(array(1, 2, 3), struct('init', 0), struct('final', 999)) as aggregate_struct_literal; +select aggregate(array(1, 2, 3), array(), array('result')) as aggregate_array_literal; + +select array_sort(array(3, 1, 2), 1) as array_sort_int_literal; +select array_sort(array(3, 1, 2), map('compare', 0)) as array_sort_map_literal; +select array_sort(array(3, 1, 2), struct('result', 0)) as array_sort_struct_literal; +select array_sort(array(3, 1, 2), array(0)) as array_sort_array_literal; + +select exists(array(1, 2, 3), 1) as exists_int_literal; +select exists(array(1, 2, 3), map('found', true)) as exists_map_literal; +select exists(array(1, 2, 3), struct('exists', true)) as exists_struct_literal; +select exists(array(1, 2, 3), array(true)) as exists_array_literal; + +select filter(array(1, 2, 3), 1) as filter_int_literal; +select filter(array(1, 2, 3), map('key', 'value')) as filter_map_literal; +select filter(array(1, 2, 3), struct('valid', true)) as filter_struct_literal; +select filter(array(1, 2, 3), array(true, false)) as filter_array_literal; + +select forall(array(1, 2, 3), 1) as forall_int_literal; +select forall(array(1, 2, 3), map('all', true)) as forall_map_literal; +select forall(array(1, 2, 3), struct('all', true)) as forall_struct_literal; +select forall(array(1, 2, 3), array(true, true)) as forall_array_literal; + +select map_filter(map('a', 1, 'b', 2), 1) as map_filter_int_literal; +select map_filter(map('a', 1, 'b', 2), map('keep', true)) as map_filter_map_literal; +select map_filter(map('a', 1, 'b', 2), struct('filter', true)) as map_filter_struct_literal; +select map_filter(map('a', 1, 'b', 2), array(true)) as map_filter_array_literal; + +select map_zip_with(map('a', 1), map('a', 10), 100) as map_zipwith_int_literal; +select map_zip_with(map('a', 1), map('a', 10), map('merged', true)) as map_zipwith_map_literal; +select map_zip_with(map('a', 1), map('a', 10), struct('left', 1, 'right', 10)) as map_zipwith_struct_literal; +select map_zip_with(map('a', 1), map('a', 10), array('combined')) as map_zipwith_array_literal; + +select reduce(array(1, 2, 3), 0, 100) as reduce_int_literal; +select reduce(array(1, 2, 3), map(), map('result', 999)) as reduce_map_literal; +select reduce(array(1, 2, 3), struct('init', 0), struct('final', 999)) as reduce_struct_literal; +select reduce(array(1, 2, 3), array(), array('result')) as reduce_array_literal; + +select transform(array(1, 2, 3), 42) as transform_int_literal; +select transform(array(1, 2, 3), map('key', 'value')) as transform_map_literal; +select transform(array(1, 2, 3), struct('id', 99, 'name', 'test')) as transform_struct_literal; +select transform(array(1, 2, 3), array('a', 'b')) as transform_array_literal; + +select transform_keys(map('a', 1, 'b', 2), 42) as transform_keys_int_literal; +select transform_keys(map('a', 1, 'b', 2), map('new', 'key')) as transform_keys_map_literal; +select transform_keys(map('a', 1, 'b', 2), struct('key', 'value')) as transform_keys_struct_literal; +select transform_keys(map('a', 1, 'b', 2), array('new_key')) as transform_keys_array_literal; + +select transform_values(map('a', 1, 'b', 2), 999) as transform_values_int_literal; +select transform_values(map('a', 1, 'b', 2), map('new', 'value')) as transform_values_map_literal; +select transform_values(map('a', 1, 'b', 2), struct('val', 999)) as transform_values_struct_literal; +select transform_values(map('a', 1, 'b', 2), array('new_value')) as transform_values_array_literal; + +select zip_with(array(1, 2, 3), array(4, 5, 6), 100) as zipwith_int_literal; +select zip_with(array(1, 2, 3), array(4, 5, 6), map('merged', true)) as zipwith_map_literal; +select zip_with(array(1, 2, 3), array(4, 5, 6), struct('left', 1, 'right', 2)) as zipwith_struct_literal; +select zip_with(array(1, 2, 3), array(4, 5, 6), array('combined')) as zipwith_array_literal; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/hll.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/hll.sql index a0c29cb25a5..35128da97fd 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/hll.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/hll.sql @@ -1,10 +1,40 @@ -- Positive test cases -- Create a table with some testing data. DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS hll_binary_test; +DROP TABLE IF EXISTS hll_string_test; + CREATE TABLE t1 USING JSON AS VALUES (0), (1), (2), (2), (2), (3), (4) as tab(col); +CREATE TABLE hll_binary_test (bytes BINARY) USING PARQUET; +CREATE TABLE hll_string_test (s STRING) USING PARQUET; + +INSERT INTO hll_binary_test VALUES (X''), (CAST(' ' AS BINARY)), (X'e280'), (X'c1'), (X'c120'); + +-- `\u030A` is the "combining ring above" Unicode character: https://www.compart.com/en/unicode/U+030A +-- `\uFFFD is the Unicode replacement character +-- `\xC1` is an invalid Unicode byte. +-- `\x80` is a Unicode continuation byte, that is it cannot be the first byte of a multi-byte UTF8 character. +-- All strings are different based on the UTF8_BINARY collation. +-- The first and second strings are equal for any collation with the RTRIM modifier, and equal to the empty string. +-- The last three strings are respectively equal to the next last three strings for any collation with the RTRIM modifier. +-- The strings "\xC1", "\x80" and "\uFFFD" are equal for all collations except UTF8_BINARY. +-- The (sub)strings `å` and `a\u030A` are equal for the UNICODE family of collations. +-- `å` is the lowercase version of `Å`. +INSERT INTO hll_string_test VALUES (''), (' '), (CAST(X'C1' AS STRING)), (CAST(X'80' AS STRING)), ('\uFFFD'), ('Å'), ('å'), ('a\u030A'), ('Å '), ('å '), ('a\u030A '); SELECT hll_sketch_estimate(hll_sketch_agg(col)) AS result FROM t1; +SELECT hll_sketch_estimate(hll_sketch_agg(bytes)) FROM hll_binary_test; + +SELECT hll_sketch_estimate(hll_sketch_agg(s)) utf8_b FROM hll_string_test; +SELECT hll_sketch_estimate(hll_sketch_agg(s COLLATE UTF8_LCASE)) utf8_lc FROM hll_string_test; +SELECT hll_sketch_estimate(hll_sketch_agg(s COLLATE UNICODE)) unicode FROM hll_string_test; +SELECT hll_sketch_estimate(hll_sketch_agg(s COLLATE UNICODE_CI)) unicode_ci FROM hll_string_test; +SELECT hll_sketch_estimate(hll_sketch_agg(s COLLATE UTF8_BINARY_RTRIM)) utf8_b_rt FROM hll_string_test; +SELECT hll_sketch_estimate(hll_sketch_agg(s COLLATE UTF8_LCASE_RTRIM)) utf8_lc_rt FROM hll_string_test; +SELECT hll_sketch_estimate(hll_sketch_agg(s COLLATE UNICODE_RTRIM)) unicode_rt FROM hll_string_test; +SELECT hll_sketch_estimate(hll_sketch_agg(s COLLATE UNICODE_CI_RTRIM)) unicode_ci_rt FROM hll_string_test; + SELECT hll_sketch_estimate(hll_sketch_agg(col, 12)) FROM VALUES (50), (60), (60), (60), (75), (100) tab(col); @@ -39,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)) @@ -74,3 +113,5 @@ FROM (SELECT CAST('abc' AS BINARY) AS buffer); -- Clean up DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS hll_binary_test; +DROP TABLE IF EXISTS hll_string_test; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/identifier-clause-legacy.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/identifier-clause-legacy.sql new file mode 100644 index 00000000000..ae1f10f1af1 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/identifier-clause-legacy.sql @@ -0,0 +1,2 @@ +--SET spark.sql.legacy.identifierClause = true +--IMPORT identifier-clause.sql diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/identifier-clause.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/identifier-clause.sql index 4aa8019097f..bb6c7107062 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/identifier-clause.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/identifier-clause.sql @@ -119,6 +119,14 @@ VALUES(IDENTIFIER(1)); VALUES(IDENTIFIER(SUBSTR('HELLO', 1, RAND() + 1))); SELECT `IDENTIFIER`('abs')(c1) FROM VALUES(-1) AS T(c1); +CREATE TABLE t(col1 INT); +SELECT * FROM IDENTIFIER((SELECT 't')); +SELECT * FROM (SELECT IDENTIFIER((SELECT 'col1')) FROM IDENTIFIER((SELECT 't'))); +SELECT IDENTIFIER((SELECT 'col1')) FROM VALUES(1); +SELECT col1, IDENTIFIER((SELECT col1)) FROM VALUES(1); +SELECT IDENTIFIER((SELECT 'col1', 'col2')) FROM VALUES(1,2); +DROP TABLE t; + CREATE TABLE IDENTIFIER(1)(c1 INT) USING csv; CREATE TABLE IDENTIFIER('a.b.c')(c1 INT) USING csv; CREATE VIEW IDENTIFIER('a.b.c')(c1) AS VALUES(1); @@ -157,7 +165,6 @@ SELECT IDENTIFIER('max')(IDENTIFIER('c1')) FROM IDENTIFIER('T'); WITH ABC(c1, c2) AS (VALUES(1, 2), (2, 3)) SELECT IDENTIFIER('max')(IDENTIFIER('c1')) FROM IDENTIFIER('A' || 'BC'); --- Not supported SELECT row_number() OVER IDENTIFIER('x.win') FROM VALUES(1) AS T(c1) WINDOW win AS (ORDER BY c1); SELECT T1.c1 FROM VALUES(1) AS T1(c1) JOIN VALUES(1) AS T2(c1) USING (IDENTIFIER('c1')); SELECT IDENTIFIER('t').c1 FROM VALUES(1) AS T(c1); @@ -168,10 +175,217 @@ SELECT * FROM IDENTIFIER('s').IDENTIFIER('tab'); SELECT * FROM IDENTIFIER('s').tab; SELECT row_number() OVER IDENTIFIER('win') FROM VALUES(1) AS T(c1) WINDOW win AS (ORDER BY c1); SELECT row_number() OVER win FROM VALUES(1) AS T(c1) WINDOW IDENTIFIER('win') AS (ORDER BY c1); +SELECT 1 AS IDENTIFIER('col1'); +SELECT my_table.* FROM VALUES (1, 2) AS IDENTIFIER('my_table')(IDENTIFIER('c1'), IDENTIFIER('c2')); WITH identifier('v')(identifier('c1')) AS (VALUES(1)) (SELECT c1 FROM v); -INSERT INTO tab(IDENTIFIER('c1')) VALUES(1); CREATE OR REPLACE VIEW v(IDENTIFIER('c1')) AS VALUES(1); +SELECT c1 FROM v; +DROP VIEW IF EXISTS v; CREATE TABLE tab(IDENTIFIER('c1') INT) USING CSV; +INSERT INTO tab(IDENTIFIER('c1')) VALUES(1); +SELECT c1 FROM tab; +ALTER TABLE IDENTIFIER('tab') RENAME COLUMN IDENTIFIER('c1') TO IDENTIFIER('col1'); +SELECT col1 FROM tab; +ALTER TABLE IDENTIFIER('tab') ADD COLUMN IDENTIFIER('c2') INT; +SELECT c2 FROM tab; +ALTER TABLE IDENTIFIER('tab') DROP COLUMN IDENTIFIER('c2'); +ALTER TABLE IDENTIFIER('tab') RENAME TO IDENTIFIER('tab_renamed'); +SELECT * FROM tab_renamed; +DROP TABLE IF EXISTS tab_renamed; +DROP TABLE IF EXISTS tab; + +-- Error because qualified names are not allowed +CREATE TABLE test_col_with_dot(IDENTIFIER('`col.with.dot`') INT) USING CSV; +DROP TABLE IF EXISTS test_col_with_dot; +-- Identifier-lite: table alias with qualified name should error (table alias must be single) +SELECT * FROM VALUES (1, 2) AS IDENTIFIER('schema.table')(c1, c2); +-- Identifier-lite: column alias with qualified name should error (column alias must be single) +SELECT 1 AS IDENTIFIER('col1.col2'); + +-- Additional coverage: SHOW commands with identifier-lite +CREATE SCHEMA identifier_clause_test_schema; +USE identifier_clause_test_schema; +CREATE TABLE test_show(c1 INT, c2 STRING) USING CSV; +SHOW VIEWS IN IDENTIFIER('identifier_clause_test_schema'); +SHOW PARTITIONS IDENTIFIER('test_show'); +SHOW CREATE TABLE IDENTIFIER('test_show'); +DROP TABLE test_show; + +-- SET CATALOG with identifier-lite +-- SET CATALOG IDENTIFIER('spark_catalog'); + +-- DESCRIBE with different forms +CREATE TABLE test_desc(c1 INT) USING CSV; +DESCRIBE TABLE IDENTIFIER('test_desc'); +DESCRIBE FORMATTED IDENTIFIER('test_desc'); +DESCRIBE EXTENDED IDENTIFIER('test_desc'); +DESC IDENTIFIER('test_desc'); +DROP TABLE test_desc; + +-- COMMENT ON COLUMN with identifier-lite +CREATE TABLE test_comment(c1 INT, c2 STRING) USING CSV; +COMMENT ON TABLE IDENTIFIER('test_comment') IS 'table comment'; +ALTER TABLE test_comment ALTER COLUMN IDENTIFIER('c1') COMMENT 'column comment'; +DROP TABLE test_comment; + +-- Additional identifier tests with qualified table names in various commands +CREATE TABLE identifier_clause_test_schema.test_table(c1 INT) USING CSV; +ANALYZE TABLE IDENTIFIER('identifier_clause_test_schema.test_table') COMPUTE STATISTICS; +REFRESH TABLE IDENTIFIER('identifier_clause_test_schema.test_table'); +DESCRIBE IDENTIFIER('identifier_clause_test_schema.test_table'); +SHOW COLUMNS FROM IDENTIFIER('identifier_clause_test_schema.test_table'); +DROP TABLE IDENTIFIER('identifier_clause_test_schema.test_table'); + +-- Session variables with identifier-lite +DECLARE IDENTIFIER('my_var') = 'value'; +SET VAR IDENTIFIER('my_var') = 'new_value'; +SELECT IDENTIFIER('my_var'); +DROP TEMPORARY VARIABLE IDENTIFIER('my_var'); + +-- SQL UDF with identifier-lite in parameter names and return statement +CREATE TEMPORARY FUNCTION test_udf(IDENTIFIER('param1') INT, IDENTIFIER('param2') STRING) +RETURNS INT +RETURN IDENTIFIER('param1') + length(IDENTIFIER('param2')); + +SELECT test_udf(5, 'hello'); +DROP TEMPORARY FUNCTION test_udf; + +-- SQL UDF with table return type using identifier-lite +CREATE TEMPORARY FUNCTION test_table_udf(IDENTIFIER('input_val') INT) +RETURNS TABLE(IDENTIFIER('col1') INT, IDENTIFIER('col2') STRING) +RETURN SELECT IDENTIFIER('input_val'), 'result'; + +SELECT * FROM test_table_udf(42); +DROP TEMPORARY FUNCTION test_table_udf; + +-- Integration tests: Combining parameter markers, string coalescing, and IDENTIFIER +-- These tests demonstrate the power of combining IDENTIFIER with parameters + +-- Test 1: IDENTIFIER with parameter marker for table name +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(:tab \'b\').c1 FROM VALUES(1) AS tab(c1)' USING 'ta' AS tab; + +-- Test 2: IDENTIFIER with string coalescing for column name +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(:col1 ''.c2'') FROM VALUES(named_struct(''c2'', 42)) AS T(c1)' + USING 'c1' AS col1; + +-- Test 3: IDENTIFIER with parameter and string literal coalescing for qualified table name +CREATE TABLE integration_test(c1 INT, c2 STRING) USING CSV; +INSERT INTO integration_test VALUES (1, 'a'), (2, 'b'); +EXECUTE IMMEDIATE 'SELECT * FROM IDENTIFIER(:schema ''.'' :table) ORDER BY ALL' + USING 'identifier_clause_test_schema' AS schema, 'integration_test' AS table; + +-- Test 4: IDENTIFIER in column reference with parameter and string coalescing +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(:prefix ''1''), IDENTIFIER(:prefix ''2'') FROM integration_test ORDER BY ALL' + USING 'c' AS prefix; + +-- Test 5: IDENTIFIER in WHERE clause with parameters +EXECUTE IMMEDIATE 'SELECT * FROM integration_test WHERE IDENTIFIER(:col) = :val' + USING 'c1' AS col, 1 AS val; + +-- Test 6: IDENTIFIER in JOIN with parameters for table and column names +CREATE TABLE integration_test2(c1 INT, c3 STRING) USING CSV; +INSERT INTO integration_test2 VALUES (1, 'x'), (2, 'y'); +EXECUTE IMMEDIATE 'SELECT t1.*, t2.* FROM IDENTIFIER(:t1) t1 JOIN IDENTIFIER(:t2) t2 USING (IDENTIFIER(:col)) ORDER BY ALL' + USING 'integration_test' AS t1, 'integration_test2' AS t2, 'c1' AS col; + +-- Test 7: IDENTIFIER in window function with parameter for partition column +EXECUTE IMMEDIATE + 'SELECT IDENTIFIER(:col1), IDENTIFIER(:col2), row_number() OVER (PARTITION BY IDENTIFIER(:part) ORDER BY IDENTIFIER(:ord)) as rn FROM integration_test' + USING 'c1' AS col1, 'c2' AS col2, 'c2' AS part, 'c1' AS ord; + +-- Test 8: IDENTIFIER in aggregate function with string coalescing +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(:prefix ''2''), IDENTIFIER(:agg)(IDENTIFIER(:col)) FROM integration_test GROUP BY IDENTIFIER(:prefix ''2'') ORDER BY ALL' + USING 'c' AS prefix, 'count' AS agg, 'c1' AS col; + +-- Test 9: IDENTIFIER in ORDER BY with multiple parameters +EXECUTE IMMEDIATE 'SELECT * FROM integration_test ORDER BY IDENTIFIER(:col1) DESC, IDENTIFIER(:col2)' + USING 'c1' AS col1, 'c2' AS col2; + +-- Test 10: IDENTIFIER in INSERT with parameter for column name +EXECUTE IMMEDIATE 'INSERT INTO integration_test(IDENTIFIER(:col1), IDENTIFIER(:col2)) VALUES (:val1, :val2)' + USING 'c1' AS col1, 'c2' AS col2, 3 AS val1, 'c' AS val2; + +-- Test 11: Complex - IDENTIFIER with nested string operations +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(concat(:schema, ''.'', :table, ''.c1'')) FROM VALUES(named_struct(''c1'', 100)) AS IDENTIFIER(:alias)(IDENTIFIER(:schema ''.'' :table))' + USING 'identifier_clause_test_schema' AS schema, 'my_table' AS table, 't' AS alias; + +-- Test 12: IDENTIFIER in CTE name with parameter +EXECUTE IMMEDIATE 'WITH IDENTIFIER(:cte_name)(c1) AS (VALUES(1)) SELECT c1 FROM IDENTIFIER(:cte_name)' + USING 'my_cte' AS cte_name; + +-- Test 13: IDENTIFIER in view name with parameter +EXECUTE IMMEDIATE 'CREATE OR REPLACE TEMPORARY VIEW IDENTIFIER(:view_name)(IDENTIFIER(:col_name)) AS VALUES(1)' + USING 'test_view' AS view_name, 'test_col' AS col_name; +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(:col) FROM IDENTIFIER(:view)' + USING 'test_col' AS col, 'test_view' AS view; +DROP VIEW test_view; + +-- Test 14: IDENTIFIER in ALTER TABLE with parameters +EXECUTE IMMEDIATE 'ALTER TABLE IDENTIFIER(:tab) ADD COLUMN IDENTIFIER(:new_col) INT' + USING 'integration_test' AS tab, 'c4' AS new_col; +EXECUTE IMMEDIATE 'ALTER TABLE IDENTIFIER(:tab) RENAME COLUMN IDENTIFIER(:old_col) TO IDENTIFIER(:new_col)' + USING 'integration_test' AS tab, 'c4' AS old_col, 'c5' AS new_col; + +-- Test 15: IDENTIFIER with dereference using parameters +EXECUTE IMMEDIATE 'SELECT map(:key, :val).IDENTIFIER(:key) AS result' + USING 'mykey' AS key, 42 AS val; + +-- Test 16: IDENTIFIER in table alias with string coalescing +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(:alias ''.c1'') FROM integration_test AS IDENTIFIER(:alias) ORDER BY ALL' + USING 't' AS alias; + +-- Test 17: Multiple IDENTIFIER clauses with different parameter combinations +EXECUTE IMMEDIATE + 'SELECT IDENTIFIER(:col1), IDENTIFIER(:p ''2'') FROM IDENTIFIER(:schema ''.'' :tab) WHERE IDENTIFIER(:col1) > 0 ORDER BY IDENTIFIER(:p ''1'')' + USING 'c1' AS col1, 'c' AS p, 'identifier_clause_test_schema' AS schema, 'integration_test' AS tab; + +-- Test 19: IDENTIFIER with qualified name coalescing for schema.table.column pattern +-- This should work for multi-part identifiers +EXECUTE IMMEDIATE 'SELECT * FROM IDENTIFIER(:schema ''.'' :table) WHERE IDENTIFIER(concat(:tab_alias, ''.c1'')) > 0 ORDER BY ALL' + USING 'identifier_clause_test_schema' AS schema, 'integration_test' AS table, 'integration_test' AS tab_alias; + +-- Test 20: Error case - IDENTIFIER with too many parts from parameter coalescing +-- This should error as column alias must be single identifier +EXECUTE IMMEDIATE 'SELECT 1 AS IDENTIFIER(:schema ''.'' :col)' + USING 'identifier_clause_test_schema' AS schema, 'col1' AS col; + +-- Cleanup +DROP TABLE integration_test; +DROP TABLE integration_test2; + +-- LATERAL VIEW with IDENTIFIER() for table and column names +CREATE TABLE lateral_test(arr ARRAY) USING PARQUET; +INSERT INTO lateral_test VALUES (array(1, 2, 3)); +SELECT * FROM lateral_test LATERAL VIEW explode(arr) IDENTIFIER('tbl') AS IDENTIFIER('col') ORDER BY ALL; +SELECT * FROM lateral_test LATERAL VIEW OUTER explode(arr) IDENTIFIER('my_table') AS IDENTIFIER('my_col') ORDER BY ALL; +DROP TABLE lateral_test; + +-- UNPIVOT with IDENTIFIER() for value column alias +CREATE TABLE unpivot_test(id INT, a INT, b INT, c INT) USING CSV; +INSERT INTO unpivot_test VALUES (1, 10, 20, 30); +SELECT * FROM unpivot_test UNPIVOT (val FOR col IN (a AS IDENTIFIER('col_a'), b AS IDENTIFIER('col_b'))) ORDER BY ALL; +SELECT * FROM unpivot_test UNPIVOT ((v1, v2) FOR col IN ((a, b) AS IDENTIFIER('cols_ab'), (b, c) AS IDENTIFIER('cols_bc'))) ORDER BY ALL; +DROP TABLE unpivot_test; + +-- All the following tests fail because they are not about "true" identifiers + +-- This should fail - named parameters don't support IDENTIFIER() +SELECT :IDENTIFIER('param1') FROM VALUES(1) AS T(c1); + +-- Hint names use simpleIdentifier - these should fail +CREATE TABLE hint_test(c1 INT, c2 INT) USING CSV; +INSERT INTO hint_test VALUES (1, 2), (3, 4); +SELECT /*+ IDENTIFIER('BROADCAST')(hint_test) */ * FROM hint_test; +SELECT /*+ IDENTIFIER('MERGE')(hint_test) */ * FROM hint_test; +DROP TABLE hint_test; + +-- These should fail - function scope doesn't support IDENTIFIER() +SHOW IDENTIFIER('USER') FUNCTIONS; +-- EXTRACT field name uses simpleIdentifier - should fail +SELECT EXTRACT(IDENTIFIER('YEAR') FROM DATE'2024-01-15'); +-- TIMESTAMPADD unit is a token, not identifier - should fail +SELECT TIMESTAMPADD(IDENTIFIER('YEAR'), 1, DATE'2024-01-15'); +DROP SCHEMA identifier_clause_test_schema; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/interval.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/interval.sql index e4da28c2e75..e8e10d089de 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/interval.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/interval.sql @@ -385,3 +385,8 @@ SELECT width_bucket(INTERVAL '0' YEAR, INTERVAL '0' YEAR, INTERVAL '10' YEAR, 10 SELECT width_bucket(INTERVAL '-1' YEAR, INTERVAL -'1-2' YEAR TO MONTH, INTERVAL '1-2' YEAR TO MONTH, 10); SELECT width_bucket(INTERVAL '0' DAY, INTERVAL '0' DAY, INTERVAL '10' DAY, 10); SELECT width_bucket(INTERVAL '-59' MINUTE, INTERVAL -'1 01' DAY TO HOUR, INTERVAL '1 2:3:4.001' DAY TO SECOND, 10); + +-- interval overflow with large day values (SPARK-50072) +-- This should throw INTERVAL_ARITHMETIC_OVERFLOW error +SELECT interval 106751991 day 4 hour 0 minute 54.776 second; + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/join-resolution-edge-cases.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/join-resolution-edge-cases.sql new file mode 100644 index 00000000000..34a8f779277 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/join-resolution-edge-cases.sql @@ -0,0 +1,26 @@ +CREATE TABLE t1(col1 INT, col2 STRING); +CREATE TABLE t2(col1 INT, col2 STRING); + +-- Join names should be computed as intersection of names of the left and right sides. +SELECT * FROM t2 as t2_1 LEFT JOIN t2 as t2_2 ON t2_1.col1 = t2_2.col1 + NATURAL JOIN t2 as t2_3; +SELECT * FROM t2 as t2_1 RIGHT JOIN t2 as t2_2 ON t2_1.col1 = t2_2.col1 + NATURAL JOIN t2 as t2_3; +SELECT * FROM t2 as t2_1 CROSS JOIN t2 as t2_2 ON t2_1.col1 = t2_2.col1 + NATURAL JOIN t2 as t2_3; +SELECT * FROM t2 as t2_1 INNER JOIN t2 as t2_2 ON t2_1.col1 = t2_2.col1 + NATURAL JOIN t2 as t2_3; + +-- Regular join hidden output should be main output ++ old metadata output +SELECT col2 AS alias FROM t1 as t1_1 LEFT ANTI JOIN t1 as t1_2 ON t1_1.col1 = t1_2.col1 ORDER BY col2; +SELECT col2 AS alias FROM t1 as t1_1 LEFT SEMI JOIN t1 as t1_2 ON t1_1.col1 = t1_2.col1 ORDER BY col2; +SELECT col1 FROM t1 as t1_1 LEFT SEMI JOIN t1 as t1_2 ORDER BY col2; +SELECT col1 FROM t1 as t1_1 LEFT SEMI JOIN t1 as t1_2 GROUP BY ALL HAVING MIN(col2) > 1; + +-- Retain original join output under Project/Aggregate/Filter +SELECT 1 FROM t2 NATURAL JOIN t1 JOIN t2 ON t2.col1 = t1.col1 WHERE t2.col2 = 1; +SELECT 1 FROM t2 NATURAL JOIN t1 JOIN t2 ON t2.col1 = t1.col1 GROUP BY t2.col2 HAVING t2.col2 = 1; +SELECT 1 FROM t2 NATURAL JOIN t1 JOIN t2 ON t2.col1 = t1.col1 ORDER BY t2.col2; + +DROP TABLE t1; +DROP TABLE t2; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/kllquantiles.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/kllquantiles.sql new file mode 100644 index 00000000000..d0d7fb1f9c1 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/kllquantiles.sql @@ -0,0 +1,473 @@ +-- Positive test cases +-- Create tables with two columns for each data type + +-- Integer table +DROP TABLE IF EXISTS t_int_1_5_through_7_11; +CREATE TABLE t_int_1_5_through_7_11 AS +VALUES + (1, 5), (2, 6), (3, 7), (4, 8), (5, 9), (6, 10), (7, 11) AS tab(col1, col2); + +-- Long table +DROP TABLE IF EXISTS t_long_1_5_through_7_11; +CREATE TABLE t_long_1_5_through_7_11 AS +VALUES + (1L, 5L), (2L, 6L), (3L, 7L), (4L, 8L), (5L, 9L), (6L, 10L), (7L, 11L) AS tab(col1, col2); + +-- SMALLINT (ShortType) table +DROP TABLE IF EXISTS t_short_1_5_through_7_11; +CREATE TABLE t_short_1_5_through_7_11 AS +VALUES + (CAST(1 AS SMALLINT), CAST(5 AS SMALLINT)), + (CAST(2 AS SMALLINT), CAST(6 AS SMALLINT)), + (CAST(3 AS SMALLINT), CAST(7 AS SMALLINT)), + (CAST(4 AS SMALLINT), CAST(8 AS SMALLINT)), + (CAST(5 AS SMALLINT), CAST(9 AS SMALLINT)), + (CAST(6 AS SMALLINT), CAST(10 AS SMALLINT)), + (CAST(7 AS SMALLINT), CAST(11 AS SMALLINT)) + AS tab(col1, col2); + +-- TINYINT (ByteType) table +DROP TABLE IF EXISTS t_byte_1_5_through_7_11; +CREATE TABLE t_byte_1_5_through_7_11 AS +VALUES + (CAST(1 AS TINYINT), CAST(5 AS TINYINT)), + (CAST(2 AS TINYINT), CAST(6 AS TINYINT)), + (CAST(3 AS TINYINT), CAST(7 AS TINYINT)), + (CAST(4 AS TINYINT), CAST(8 AS TINYINT)), + (CAST(5 AS TINYINT), CAST(9 AS TINYINT)), + (CAST(6 AS TINYINT), CAST(10 AS TINYINT)), + (CAST(7 AS TINYINT), CAST(11 AS TINYINT)) + AS tab(col1, col2); + +-- Float table +DROP TABLE IF EXISTS t_float_1_5_through_7_11; +CREATE TABLE t_float_1_5_through_7_11 AS +VALUES + (CAST(1 AS FLOAT), CAST(5 AS FLOAT)), + (CAST(2 AS FLOAT), CAST(6 AS FLOAT)), + (CAST(3 AS FLOAT), CAST(7 AS FLOAT)), + (CAST(4 AS FLOAT), CAST(8 AS FLOAT)), + (CAST(5 AS FLOAT), CAST(9 AS FLOAT)), + (CAST(6 AS FLOAT), CAST(10 AS FLOAT)), + (CAST(7 AS FLOAT), CAST(11 AS FLOAT)) AS tab(col1, col2); + +-- Double table +DROP TABLE IF EXISTS t_double_1_5_through_7_11; +CREATE TABLE t_double_1_5_through_7_11 AS +VALUES + (CAST(1 AS DOUBLE), CAST(5 AS DOUBLE)), + (CAST(2 AS DOUBLE), CAST(6 AS DOUBLE)), + (CAST(3 AS DOUBLE), CAST(7 AS DOUBLE)), + (CAST(4 AS DOUBLE), CAST(8 AS DOUBLE)), + (CAST(5 AS DOUBLE), CAST(9 AS DOUBLE)), + (CAST(6 AS DOUBLE), CAST(10 AS DOUBLE)), + (CAST(7 AS DOUBLE), CAST(11 AS DOUBLE)) AS tab(col1, col2); + +-- BIGINT sketches +SELECT split(kll_sketch_to_string_bigint(agg), '\n')[1] LIKE '%Kll%' AS str_contains_kll, + abs(kll_sketch_get_quantile_bigint(agg, 0.5) - 4) < 1 AS median_close_to_4, + abs(kll_sketch_get_rank_bigint(agg, 3) - 0.4) < 0.1 AS rank3_close_to_0_4 +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_byte_1_5_through_7_11 +); + +SELECT split(kll_sketch_to_string_bigint(agg), '\n')[1] LIKE '%Kll%' AS str_contains_kll, + abs(kll_sketch_get_quantile_bigint(agg, 0.5) - 4) < 1 AS median_close_to_4, + abs(kll_sketch_get_rank_bigint(agg, 3) - 0.4) < 0.1 AS rank3_close_to_0_4 +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_int_1_5_through_7_11 +); + +SELECT split(kll_sketch_to_string_bigint(agg), '\n')[1] LIKE '%Kll%' AS str_contains_kll, + abs(kll_sketch_get_quantile_bigint(agg, 0.5) - 4) < 1 AS median_close_to_4, + abs(kll_sketch_get_rank_bigint(agg, 3) - 0.4) < 0.1 AS rank3_close_to_0_4 +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_long_1_5_through_7_11 +); + +SELECT split(kll_sketch_to_string_bigint(agg), '\n')[1] LIKE '%Kll%' AS str_contains_kll, + abs(kll_sketch_get_quantile_bigint(agg, 0.5) - 4) < 1 AS median_close_to_4, + abs(kll_sketch_get_rank_bigint(agg, 3) - 0.4) < 0.1 AS rank3_close_to_0_4 +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_short_1_5_through_7_11 +); + +-- FLOAT sketches (only accepts float types to avoid precision loss) +SELECT split(kll_sketch_to_string_float(agg), '\n')[1] LIKE '%Kll%' AS str_contains_kll, + abs(kll_sketch_get_quantile_float(agg, 0.5) - 4.0) < 0.5 AS median_close_to_4, + abs(kll_sketch_get_rank_float(agg, 3) - 0.4) < 0.1 AS rank3_close_to_0_4 +FROM ( + SELECT kll_sketch_agg_float(col1) AS agg + FROM t_float_1_5_through_7_11 +); + +-- DOUBLE sketches (accepts float and double types to avoid precision loss from integer conversion) +SELECT split(kll_sketch_to_string_double(agg), '\n')[1] LIKE '%Kll%' AS str_contains_kll, + abs(kll_sketch_get_quantile_double(agg, 0.5) - 4.0) < 0.5 AS median_close_to_4, + abs(kll_sketch_get_rank_double(agg, 3) - 0.4) < 0.1 AS rank3_close_to_0_4 +FROM ( + SELECT kll_sketch_agg_double(col1) AS agg + FROM t_double_1_5_through_7_11 +); + +-- Test float column with double sketch (valid type promotion) +SELECT split(kll_sketch_to_string_double(agg), '\n')[1] LIKE '%Kll%' AS str_contains_kll, + abs(kll_sketch_get_quantile_double(agg, 0.5) - 4.0) < 0.5 AS median_close_to_4, + abs(kll_sketch_get_rank_double(agg, 3) - 0.4) < 0.1 AS rank3_close_to_0_4 +FROM ( + SELECT kll_sketch_agg_double(col1) AS agg + FROM t_float_1_5_through_7_11 +); + +-- Merging sketches and converting them to strings +SELECT + split( + kll_sketch_to_string_bigint( + kll_sketch_merge_bigint( + kll_sketch_agg_bigint(col1), + kll_sketch_agg_bigint(col1) + ) + ), + '\n' + )[1] AS result + FROM t_byte_1_5_through_7_11; + +SELECT + split( + kll_sketch_to_string_float( + kll_sketch_merge_float( + kll_sketch_agg_float(col1), + kll_sketch_agg_float(col1) + ) + ), + '\n' + )[1] AS result +FROM t_byte_1_5_through_7_11; + +SELECT + split( + kll_sketch_to_string_double( + kll_sketch_merge_double( + kll_sketch_agg_double(col1), + kll_sketch_agg_double(col1) + ) + ), + '\n' + )[1] AS result +FROM t_byte_1_5_through_7_11; + +-- Tests verifying that NULL input values are ignored by aggregate functions + +-- Test BIGINT aggregate ignores NULL values +-- Verify that the sketch computed with NULLs matches the sketch without NULLs +-- Both should compute median of [1, 3, 5, 7] which is 4 +-- Input data: 1, NULL, 3, 5, NULL, 7 +SELECT abs(kll_sketch_get_quantile_bigint(agg_with_nulls, 0.5) - + kll_sketch_get_quantile_bigint(agg_without_nulls, 0.5)) < 1 AS medians_match, + abs(kll_sketch_get_rank_bigint(agg_with_nulls, 4) - + kll_sketch_get_rank_bigint(agg_without_nulls, 4)) < 0.1 AS ranks_match +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg_with_nulls + FROM (VALUES (1L), (CAST(NULL AS BIGINT)), (3L), (5L), (CAST(NULL AS BIGINT)), (7L)) AS tab(col1) +) WITH_NULLS, +( + SELECT kll_sketch_agg_bigint(col1) AS agg_without_nulls + FROM (VALUES (1L), (3L), (5L), (7L)) AS tab(col1) +) WITHOUT_NULLS; + +-- Test FLOAT aggregate ignores NULL values +-- Verify that the sketch computed with NULLs matches the sketch without NULLs +-- Input data: 1.0, NULL, 3.0, 5.0, NULL, 7.0 +SELECT abs(kll_sketch_get_quantile_float(agg_with_nulls, 0.5) - + kll_sketch_get_quantile_float(agg_without_nulls, 0.5)) < 0.5 AS medians_match, + abs(kll_sketch_get_rank_float(agg_with_nulls, 4.0) - + kll_sketch_get_rank_float(agg_without_nulls, 4.0)) < 0.1 AS ranks_match +FROM ( + SELECT kll_sketch_agg_float(col1) AS agg_with_nulls + FROM (VALUES (1.0F), (CAST(NULL AS FLOAT)), (3.0F), (5.0F), (CAST(NULL AS FLOAT)), (7.0F)) AS tab(col1) +) WITH_NULLS, +( + SELECT kll_sketch_agg_float(col1) AS agg_without_nulls + FROM (VALUES (1.0F), (3.0F), (5.0F), (7.0F)) AS tab(col1) +) WITHOUT_NULLS; + +-- Test DOUBLE aggregate ignores NULL values +-- Verify that the sketch computed with NULLs matches the sketch without NULLs +-- Input data: 1.0, NULL, 3.0, 5.0, NULL, 7.0 +SELECT abs(kll_sketch_get_quantile_double(agg_with_nulls, 0.5) - + kll_sketch_get_quantile_double(agg_without_nulls, 0.5)) < 0.5 AS medians_match, + abs(kll_sketch_get_rank_double(agg_with_nulls, 4.0) - + kll_sketch_get_rank_double(agg_without_nulls, 4.0)) < 0.1 AS ranks_match +FROM ( + SELECT kll_sketch_agg_double(col1) AS agg_with_nulls + FROM (VALUES (1.0D), (CAST(NULL AS DOUBLE)), (3.0D), (5.0D), (CAST(NULL AS DOUBLE)), (7.0D)) AS tab(col1) +) WITH_NULLS, +( + SELECT kll_sketch_agg_double(col1) AS agg_without_nulls + FROM (VALUES (1.0D), (3.0D), (5.0D), (7.0D)) AS tab(col1) +) WITHOUT_NULLS; + +-- Tests covering NULLs +-- NULL sketch to get_quantile +SELECT kll_sketch_get_quantile_bigint(CAST(NULL AS BINARY), 0.5) AS null_sketch; + +-- NULL sketch to get_rank +SELECT kll_sketch_get_rank_float(CAST(NULL AS BINARY), 5.0) AS null_sketch; + +-- Tests for the optional k parameter +-- Positive tests with valid k values +SELECT LENGTH(kll_sketch_to_string_bigint(kll_sketch_agg_bigint(col1, 8))) > 0 AS k_min_value +FROM t_long_1_5_through_7_11; + +SELECT LENGTH(kll_sketch_to_string_bigint(kll_sketch_agg_bigint(col1, 200))) > 0 AS k_default_value +FROM t_long_1_5_through_7_11; + +SELECT LENGTH(kll_sketch_to_string_bigint(kll_sketch_agg_bigint(col1, 400))) > 0 AS k_custom_value +FROM t_long_1_5_through_7_11; + +SELECT LENGTH(kll_sketch_to_string_bigint(kll_sketch_agg_bigint(col1, 65535))) > 0 AS k_max_value +FROM t_long_1_5_through_7_11; + +SELECT LENGTH(kll_sketch_to_string_float(kll_sketch_agg_float(col1, 100))) > 0 AS k_float_sketch +FROM t_float_1_5_through_7_11; + +SELECT LENGTH(kll_sketch_to_string_double(kll_sketch_agg_double(col1, 300))) > 0 AS k_double_sketch +FROM t_double_1_5_through_7_11; + +-- Tests for kll_sketch_get_n functions +-- BIGINT sketches +SELECT kll_sketch_get_n_bigint(kll_sketch_agg_bigint(col1)) AS n_bigint +FROM t_long_1_5_through_7_11; + +SELECT kll_sketch_get_n_bigint(kll_sketch_agg_bigint(col1)) AS n_byte +FROM t_byte_1_5_through_7_11; + +SELECT kll_sketch_get_n_bigint(kll_sketch_agg_bigint(col1)) AS n_short +FROM t_short_1_5_through_7_11; + +SELECT kll_sketch_get_n_bigint(kll_sketch_agg_bigint(col1)) AS n_int +FROM t_int_1_5_through_7_11; + +-- FLOAT sketches +SELECT kll_sketch_get_n_float(kll_sketch_agg_float(col1)) AS n_float +FROM t_float_1_5_through_7_11; + +-- DOUBLE sketches +SELECT kll_sketch_get_n_double(kll_sketch_agg_double(col1)) AS n_double +FROM t_double_1_5_through_7_11; + +-- Test with different k values +SELECT kll_sketch_get_n_bigint(kll_sketch_agg_bigint(col1, 100)) AS n_k_100 +FROM t_long_1_5_through_7_11; + +-- Negative tests +-- These queries should fail with type mismatch or validation errors + +-- Type mismatch: BIGINT sketch does not accept DOUBLE columns +SELECT split(kll_sketch_to_string_bigint(agg), '\n')[1] LIKE '%Kll%' AS str_contains_kll, + abs(kll_sketch_get_quantile_bigint(agg, 0.5) - 4) < 1 AS median_close_to_4, + abs(kll_sketch_get_rank_bigint(agg, 3) - 0.4) < 0.1 AS rank3_close_to_0_4 +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_double_1_5_through_7_11 +); + +-- Type mismatch: BIGINT sketch does not accept FLOAT columns +SELECT split(kll_sketch_to_string_bigint(agg), '\n')[1] LIKE '%Kll%' AS str_contains_kll, + abs(kll_sketch_get_quantile_bigint(agg, 0.5) - 4) < 1 AS median_close_to_4, + abs(kll_sketch_get_rank_bigint(agg, 3) - 0.4) < 0.1 AS rank3_close_to_0_4 +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_float_1_5_through_7_11 +); + +-- Type mismatch: FLOAT sketch does not accept DOUBLE columns +SELECT split(kll_sketch_to_string_float(agg), '\n')[1] LIKE '%Kll%' AS str_contains_kll, + abs(kll_sketch_get_quantile_float(agg, 0.5) - 4.0) < 0.5 AS median_close_to_4, + abs(kll_sketch_get_rank_float(agg, 3) - 0.4) < 0.1 AS rank3_close_to_0_4 +FROM ( + SELECT kll_sketch_agg_float(col1) AS agg + FROM t_double_1_5_through_7_11 +); + +-- Type mismatch: FLOAT sketch does not accept integer types (BIGINT) to avoid precision loss +SELECT kll_sketch_agg_float(col1) AS invalid_float_bigint +FROM t_long_1_5_through_7_11; + +-- Type mismatch: FLOAT sketch does not accept integer types (INT) to avoid precision loss +SELECT kll_sketch_agg_float(col1) AS invalid_float_int +FROM t_int_1_5_through_7_11; + +-- Type mismatch: FLOAT sketch does not accept integer types (SMALLINT) to avoid precision loss +SELECT kll_sketch_agg_float(col1) AS invalid_float_short +FROM t_short_1_5_through_7_11; + +-- Type mismatch: FLOAT sketch does not accept integer types (TINYINT) to avoid precision loss +SELECT kll_sketch_agg_float(col1) AS invalid_float_byte +FROM t_byte_1_5_through_7_11; + +-- Type mismatch: DOUBLE sketch does not accept integer types (BIGINT) to avoid precision loss +SELECT kll_sketch_agg_double(col1) AS invalid_double_bigint +FROM t_long_1_5_through_7_11; + +-- Type mismatch: DOUBLE sketch does not accept integer types (INT) to avoid precision loss +SELECT kll_sketch_agg_double(col1) AS invalid_double_int +FROM t_int_1_5_through_7_11; + +-- Type mismatch: DOUBLE sketch does not accept integer types (SMALLINT) to avoid precision loss +SELECT kll_sketch_agg_double(col1) AS invalid_double_short +FROM t_short_1_5_through_7_11; + +-- Type mismatch: DOUBLE sketch does not accept integer types (TINYINT) to avoid precision loss +SELECT kll_sketch_agg_double(col1) AS invalid_double_byte +FROM t_byte_1_5_through_7_11; + +-- Invalid quantile: quantile value must be between 0 and 1 (negative value) +SELECT kll_sketch_get_quantile_bigint(agg, -0.5) AS invalid_quantile +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_long_1_5_through_7_11 +); + +-- Invalid quantile: quantile value must be between 0 and 1 (value > 1) +SELECT kll_sketch_get_quantile_bigint(agg, 1.5) AS invalid_quantile +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_long_1_5_through_7_11 +); + +-- Invalid quantile: quantile array with out of range values +SELECT kll_sketch_get_quantile_float(agg, array(-0.1, 0.5, 1.5)) AS invalid_quantiles +FROM ( + SELECT kll_sketch_agg_float(col1) AS agg + FROM t_float_1_5_through_7_11 +); + +-- Type mismatch: wrong sketch type for get_rank function +SELECT kll_sketch_get_rank_bigint(agg, 5) AS wrong_type +FROM ( + SELECT kll_sketch_agg_float(col1) AS agg + FROM t_float_1_5_through_7_11 +); + +-- Type mismatch: incompatible sketches in merge (BIGINT and FLOAT) +SELECT kll_sketch_merge_bigint(agg1, agg2) AS incompatible_merge +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg1, + kll_sketch_agg_float(CAST(col1 AS FLOAT)) AS agg2 + FROM t_long_1_5_through_7_11 +); + +-- Invalid input: non-sketch binary data to get_quantile +SELECT kll_sketch_get_quantile_bigint(CAST('not_a_sketch' AS BINARY), 0.5) AS invalid_binary; + +-- Note: get_quantile functions cannot detect sketch type mismatches at the binary level. +-- This query succeeds even though we're using a FLOAT get_quantile on a BIGINT sketch, +-- but it returns garbage values because it interprets the BIGINT binary data as FLOAT data. +SELECT kll_sketch_get_quantile_float(agg, 0.5) IS NOT NULL AS returns_value +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_long_1_5_through_7_11 +); + +-- Note: to_string functions cannot detect sketch type mismatches because they just +-- interpret the binary data. This query succeeds even though we're using a DOUBLE +-- to_string function on a BIGINT sketch. The function reads the binary representation +-- and produces output, but the numeric values will be incorrectly interpreted. +SELECT kll_sketch_to_string_double(agg) LIKE '%Kll%' AS contains_kll_header +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_long_1_5_through_7_11 +); + +-- Negative tests for k parameter +-- k parameter too small (minimum is 8) +SELECT kll_sketch_agg_bigint(col1, 7) AS k_too_small +FROM t_long_1_5_through_7_11; + +-- k parameter too large (maximum is 65535) +SELECT kll_sketch_agg_bigint(col1, 65536) AS k_too_large +FROM t_long_1_5_through_7_11; + +-- k parameter is NULL +SELECT kll_sketch_agg_float(col1, CAST(NULL AS INT)) AS k_is_null +FROM t_float_1_5_through_7_11; + +-- k parameter is not foldable (non-constant) +SELECT kll_sketch_agg_double(col1, CAST(col1 AS INT)) AS k_non_constant +FROM t_double_1_5_through_7_11; + +-- k parameter has wrong type (STRING instead of INT) +SELECT kll_sketch_agg_bigint(col1, '100') AS k_wrong_type +FROM t_long_1_5_through_7_11; + +-- Negative tests for kll_sketch_get_n functions +-- Invalid binary data +SELECT kll_sketch_get_n_bigint(X'deadbeef') AS invalid_binary_bigint; + +SELECT kll_sketch_get_n_float(X'cafebabe') AS invalid_binary_float; + +SELECT kll_sketch_get_n_double(X'12345678') AS invalid_binary_double; + +-- Wrong argument types +SELECT kll_sketch_get_n_bigint(42) AS wrong_argument_type; + +SELECT kll_sketch_get_n_float(42.0) AS wrong_argument_type; + +SELECT kll_sketch_get_n_double(42.0D) AS wrong_argument_type; + +-- Negative tests for kll_sketch_get_quantile functions with invalid second argument types +-- Invalid type: STRING instead of DOUBLE for quantile parameter +SELECT kll_sketch_get_quantile_bigint(agg, 'invalid') AS quantile_string +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_long_1_5_through_7_11 +); + +-- Invalid type: BINARY instead of DOUBLE for quantile parameter +SELECT kll_sketch_get_quantile_float(agg, X'deadbeef') AS quantile_binary +FROM ( + SELECT kll_sketch_agg_float(col1) AS agg + FROM t_float_1_5_through_7_11 +); + +-- Invalid type: BOOLEAN instead of DOUBLE for quantile parameter +SELECT kll_sketch_get_quantile_double(agg, true) AS quantile_boolean +FROM ( + SELECT kll_sketch_agg_double(col1) AS agg + FROM t_double_1_5_through_7_11 +); + +-- Negative tests for kll_sketch_get_rank functions with invalid second argument types +-- Invalid type: STRING instead of BIGINT for rank value parameter +SELECT kll_sketch_get_rank_bigint(agg, 'invalid') AS rank_string +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_long_1_5_through_7_11 +); + +-- Invalid type: BINARY instead of FLOAT for rank value parameter +SELECT kll_sketch_get_rank_float(agg, X'cafebabe') AS rank_binary +FROM ( + SELECT kll_sketch_agg_float(col1) AS agg + FROM t_float_1_5_through_7_11 +); + +-- Invalid type: BOOLEAN instead of DOUBLE for rank value parameter +SELECT kll_sketch_get_rank_double(agg, false) AS rank_boolean +FROM ( + SELECT kll_sketch_agg_double(col1) AS agg + FROM t_double_1_5_through_7_11 +); + +-- Clean up +DROP TABLE IF EXISTS t_int_1_5_through_7_11; +DROP TABLE IF EXISTS t_long_1_5_through_7_11; +DROP TABLE IF EXISTS t_short_1_5_through_7_11; +DROP TABLE IF EXISTS t_byte_1_5_through_7_11; +DROP TABLE IF EXISTS t_float_1_5_through_7_11; +DROP TABLE IF EXISTS t_double_1_5_through_7_11; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/literals.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/literals.sql index e1e4a370bff..1d8b74ad000 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/literals.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/literals.sql @@ -121,3 +121,13 @@ select -x'2379ACFe'; -- normalize -0 and -0.0 select -0, -0.0; + +-- Double-quote escaping ("", '') +SELECT "S""par""k" AS c1, "S\"par\"k" AS c2, 'S""par""k' AS c3; +SELECT 'S''par''k' AS c1, 'S\'par\'k' AS c2, "S''par''k" AS c3; +SELECT "S" "par" "k" AS c1, 'S' 'par' 'k' AS c2, "S" 'par' "k" AS c3, 'S' "par" 'k' AS c4, "S"'par'"k" AS c5, 'S'"par"'k' AS c6; + +SET spark.sql.legacy.consecutiveStringLiterals.enabled=true; +SELECT "S""par""k" AS c1, "S\"par\"k" AS c2, 'S""par""k' AS c3; +SELECT 'S''par''k' AS c1, 'S\'par\'k' AS c2, "S''par''k" AS c3; +SELECT "S" "par" "k" AS c1, 'S' 'par' 'k' AS c2, "S" 'par' "k" AS c3, 'S' "par" 'k' AS c4, "S"'par'"k" AS c5, 'S'"par"'k' AS c6; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/misc-functions.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/misc-functions.sql index e178f69c7d5..5181e284b3e 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/misc-functions.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/misc-functions.sql @@ -43,3 +43,6 @@ SET spark.sql.legacy.raiseErrorWithoutErrorClass=true; SELECT assert_true(false); SELECT raise_error('hello'); SET spark.sql.legacy.raiseErrorWithoutErrorClass=false; + +-- Implicit alias of assert expression +SELECT assert_true(col1 <= col2) FROM VALUES ('2025-03-01', '2025-03-10'); diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/name-precedence-in-order-by-and-having-with-conflicting-attributes.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/name-precedence-in-order-by-and-having-with-conflicting-attributes.sql new file mode 100644 index 00000000000..91811cc8024 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/name-precedence-in-order-by-and-having-with-conflicting-attributes.sql @@ -0,0 +1,134 @@ +CREATE OR REPLACE TEMPORARY VIEW v1 AS SELECT col1 FROM VALUES + (42), (17), (99), (5), (42), + (23), (8), (17), (76), (33), + (99), (55), (3), (42), (8) +; + +CREATE OR REPLACE TEMPORARY VIEW v2 AS SELECT col1 FROM VALUES + ('apple'), ('banana'), ('cherry'), ('date'), ('apple'), + ('fig'), ('grape'), ('banana'), ('kiwi'), ('lemon'), + ('cherry'), ('mango'), ('orange'), ('apple'), ('grape') +; + +-- Explicit aliases + +-- Baseline + +SELECT 2 AS col1 FROM v1 ORDER BY col1; + +SELECT 2 AS col1 FROM v1 GROUP BY ALL ORDER BY col1; + +SELECT 2 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50; + +SELECT * FROM ( + SELECT col1 AS c, 2 AS col1 FROM v1 ORDER BY col1 +) ORDER BY 1; + +SELECT * FROM ( + SELECT col1 AS c, 2 AS col1 FROM v1 GROUP BY ALL ORDER BY col1 +) ORDER BY 1; + +SELECT * FROM ( + SELECT col1 AS c, 2 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50 +) ORDER BY 1; + +-- Conflict in main output + +SELECT 2 AS col1, 3 AS col1 FROM v1 ORDER BY col1; + +SELECT 2 AS col1, 3 AS col1 FROM v1 GROUP BY ALL ORDER BY col1; + +SELECT 2 AS col1, 3 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50; + +SELECT col1 AS c, 2 AS col1, 3 AS col1 FROM v1 ORDER BY col1; + +SELECT col1 AS c, 2 AS col1, 3 AS col1 FROM v1 GROUP BY ALL ORDER BY col1; + +SELECT * FROM ( + SELECT col1 AS c, 2 AS col1, 3 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50 +) ORDER BY 1; + +SELECT col1, 2 AS col1 FROM v1 ORDER BY col1; + +SELECT col1, 2 AS col1 FROM v1 GROUP BY ALL ORDER BY col1; + +SELECT * FROM ( + SELECT col1, 2 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50 +) ORDER BY 1; + +-- Conflict in hidden output + +SELECT 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) ORDER BY col1; + +SELECT 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) GROUP BY ALL ORDER BY col1; + +SELECT 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) GROUP BY ALL HAVING col1 > 50; + +SELECT col1 AS c, 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) ORDER BY col1; + +SELECT col1 AS c, 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) GROUP BY ALL ORDER BY col1; + +SELECT col1 AS c, 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) GROUP BY ALL HAVING col1 > 50; + +-- Implicit aliases + +-- Baseline + +SELECT 'col1' FROM v2 ORDER BY col1; + +SELECT 'col1' FROM v2 GROUP BY ALL ORDER BY col1; + +SELECT 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana'; + +SELECT * FROM ( + SELECT col1 AS c, 'col1' FROM v2 ORDER BY col1 +) ORDER BY 1; + +SELECT * FROM ( + SELECT col1 AS c, 'col1' FROM v2 GROUP BY ALL ORDER BY col1 +) ORDER BY 1; + +SELECT * FROM ( + SELECT col1 AS c, 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana' +) ORDER BY 1; + +-- Conflict in main output + +SELECT 'col1', 'col1' FROM v2 ORDER BY col1; + +SELECT 'col1', 'col1' FROM v2 GROUP BY ALL ORDER BY col1; + +SELECT 'col1', 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana'; + +SELECT col1 AS c, 'col1', 'col1' FROM v2 ORDER BY col1; + +SELECT col1 AS c, 'col1', 'col1' FROM v2 GROUP BY ALL ORDER BY col1; + +SELECT * FROM ( + SELECT col1 AS c, 'col1', 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana' +) ORDER BY 1; + +SELECT col1, 'col1' FROM v2 ORDER BY col1; + +SELECT col1, 'col1' FROM v2 GROUP BY ALL ORDER BY col1; + +SELECT * FROM ( + SELECT col1, 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana' +) ORDER BY 1; + +-- Conflict in hidden output + +SELECT 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) ORDER BY col1; + +SELECT 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) GROUP BY ALL ORDER BY col1; + +SELECT 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) GROUP BY ALL HAVING col1 > 'banana'; + +SELECT col1 AS c, 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) ORDER BY col1; + +SELECT col1 AS c, 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) GROUP BY ALL ORDER BY col1; + +SELECT col1 AS c, 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) GROUP BY ALL HAVING col1 > 'banana'; + +DROP VIEW v2; +DROP VIEW v1; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/nonansi/st-functions.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/nonansi/st-functions.sql new file mode 100644 index 00000000000..720ce3767dc --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/nonansi/st-functions.sql @@ -0,0 +1 @@ +--IMPORT st-functions.sql diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/order-by-alias.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/order-by-alias.sql new file mode 100644 index 00000000000..c4ececea4cd --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/order-by-alias.sql @@ -0,0 +1,43 @@ +-- Test data. +CREATE OR REPLACE TEMPORARY VIEW testData AS SELECT * FROM VALUES +(1, 1), (1, 2), (2, 1), (2, 2), (3, 1), (3, 2), (null, 1), (3, null), (null, null) +AS testData(a, b); + +-- ORDER BY alias should work with case insensitive names +SELECT a FROM testData ORDER BY A; + +-- Aliases in SELECT could be used in ORDER BY +SELECT a as alias FROM testData ORDER BY ALIAS; + +-- ORDER BY literal +SELECT a AS k FROM testData ORDER BY 'k'; +SELECT 1 AS k FROM testData ORDER BY 'k'; + +-- ORDER BY alias with the function name +SELECT concat_ws(' ', a, b) FROM testData ORDER BY `concat_ws( , a, b)`; + +-- ORDER BY column with name same as an alias used in the project list +SELECT 1 AS a FROM testData ORDER BY a; +SELECT 1 AS a FROM testData ORDER BY `a`; + +-- ORDER BY implicit alias +SELECT 1 ORDER BY `1`; + +-- ORDER BY with expression subqueries +SELECT a, b FROM testData ORDER BY a, (SELECT b FROM testData LIMIT 1); + +-- ORDER BY more than one row +SELECT a FROM testData ORDER BY (SELECT b FROM testData); + +-- Unsupported expressions in ORDER BY +SELECT a, b FROM testData ORDER BY a, b IN (SELECT a FROM testData); +SELECT a, b FROM testData ORDER BY a, EXISTS(SELECT b FROM testData); + +-- ORDER BY alias with invalid col in SELECT list +SELECT a AS k, c FROM testData ORDER BY k; + +-- ORDER BY alias should prefer table columns over aliases +SELECT 1 AS `2`, 2 FROM VALUES (2) t (`2`) ORDER BY `2`; +SELECT 2, 1 AS `2` FROM VALUES (2) t (`2`) ORDER BY `2`; +SELECT 1 AS `2` FROM VALUES (2) t (`2`) ORDER BY `2`; +SELECT 2 FROM VALUES (2) t (`2`) ORDER BY `2`; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/order-by-and-having-on-top-of-aggregate-with-join.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/order-by-and-having-on-top-of-aggregate-with-join.sql new file mode 100644 index 00000000000..4e50f4c4a36 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/order-by-and-having-on-top-of-aggregate-with-join.sql @@ -0,0 +1,244 @@ +CREATE OR REPLACE TEMPORARY VIEW v1 AS SELECT * FROM VALUES + (1, 2), + (3, 5), + (7, 2), + (1, 2), + (8, 3), + (4, 9), + (5, 7), + (9, 4), + (2, 6), + (5, 7), + (3, 8), + (6, 1), + (4, 9), + (7, 5), + (2, 8) +; +CREATE OR REPLACE TEMPORARY VIEW v2 AS SELECT * FROM VALUES + (1, 2), + (5, 9), + (8, 4), + (7, 5), + (4, 9), + (3, 1), + (7, 2), + (6, 8), + (9, 7), + (2, 3), + (8, 3), + (5, 7), + (1, 6), + (3, 2), + (9, 8) +; + +-- ORDER BY + +-- Referencing a grouping attribute + +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 ORDER BY col1; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 ORDER BY col2; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY v1.col1; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY v1.col2; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY v2.col1; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY v2.col2; + +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 ORDER BY 1 + col1, 2 + col2; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 ORDER BY 1 + col2, 2 + col1; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 ORDER BY 1 + v1.col1, 2 + v1.col2; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 ORDER BY 1 + v1.col2, 2 + v1.col1; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 ORDER BY 1 + v1.col1, 2 + v2.col2; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 ORDER BY 1 + v2.col1, 2 + v1.col2; + +-- Referencing any attribute under aggregate expression + +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 ORDER BY MAX(col1); +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 ORDER BY MAX(col2); +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY MAX(v1.col1); +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY MAX(v1.col2); +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY MAX(v2.col1); +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY MAX(v2.col2); + +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 ORDER BY 1 + MAX(col1), 2 + MIN(col2); +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 ORDER BY 1 + MAX(col2), 2 + MIN(col1); +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 ORDER BY 1 + MAX(v1.col1), 2 + MIN(v1.col2); +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 ORDER BY 1 + MAX(v1.col2), 2 + MIN(v1.col1); +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 ORDER BY 1 + MAX(v1.col1), 2 + MIN(v2.col2); +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 ORDER BY 1 + MAX(v2.col1), 2 + MIN(v1.col2); + +-- ORDER BY with LCA below + +-- Referencing a grouping attribute + +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 ORDER BY col1; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 ORDER BY col2; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY v1.col1; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY v1.col2; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY v2.col1; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY v2.col2; + +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 ORDER BY 1 + col1, 2 + col2; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 ORDER BY 1 + col2, 2 + col1; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 ORDER BY 1 + v1.col1, 2 + v1.col2; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 ORDER BY 1 + v1.col2, 2 + v1.col1; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 ORDER BY 1 + v1.col1, 2 + v2.col2; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 ORDER BY 1 + v2.col1, 2 + v1.col2; + +-- Referencing any attribute under aggregate expression + +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 ORDER BY MAX(col1); +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 ORDER BY MAX(col2); +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY MAX(v1.col1); +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY MAX(v1.col2); +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY MAX(v2.col1); +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY MAX(v2.col2); + +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 ORDER BY 1 + MAX(col1), 2 + MIN(col2); +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 ORDER BY 1 + MAX(col2), 2 + MIN(col1); +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 ORDER BY 1 + MAX(v1.col1), 2 + MIN(v1.col2); +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 ORDER BY 1 + MAX(v1.col2), 2 + MIN(v1.col1); +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 ORDER BY 1 + MAX(v1.col1), 2 + MIN(v2.col2); +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 ORDER BY 1 + MAX(v2.col1), 2 + MIN(v1.col2); + +-- HAVING + +-- Referencing a grouping attribute + +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING col1 > 5; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING col2 > 5; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v1.col1 > 5; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v1.col2 > 5; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v2.col1 > 5; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v2.col2 > 5; + +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + col1 > 5; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + col2 > 5; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + v1.col1 > 5; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + v1.col2 > 5; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + v1.col1 > 5; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + v2.col1 > 5; + +-- Referencing any attribute under aggregate expression + +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING MAX(col1) > 5; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING MAX(col2) > 5; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v1.col1) > 5; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v1.col2) > 5; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v2.col1) > 5; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v2.col2) > 5; + +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + MAX(col1) > 5; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + MAX(col2) > 5; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + MAX(v1.col1) > 5; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + MAX(v1.col2) > 5; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + MAX(v1.col1) > 5; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + MAX(v2.col1) > 5; + +-- HAVING with LCA below + +-- Referencing a grouping attribute + +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING col1 > 5; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING col2 > 5; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v1.col1 > 5; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v1.col2 > 5; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v2.col1 > 5; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v2.col2 > 5; + +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + col1 > 5; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + col2 > 5; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + v1.col1 > 5; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + v1.col2 > 5; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + v1.col1 > 5; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + v2.col1 > 5; + +-- Referencing any attribute under aggregate expression + +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING MAX(col1) > 5; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING MAX(col2) > 5; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v1.col1) > 5; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v1.col2) > 5; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v2.col1) > 5; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v2.col2) > 5; + +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + MAX(col1) > 5; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + MAX(col2) > 5; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + MAX(v1.col1) > 5; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + MAX(v1.col2) > 5; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + MAX(v1.col1) > 5; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + MAX(v2.col1) > 5; + +-- ORDER BY and HAVING + +-- Referencing a grouping attribute + +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING col1 > 5 ORDER BY col1; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING col2 > 5 ORDER BY col2; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v1.col1 > 5 ORDER BY v1.col1; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v1.col2 > 5 ORDER BY v1.col2; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v2.col1 > 5 ORDER BY v2.col1; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v2.col2 > 5 ORDER BY v2.col2; + +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + col1 > 5 ORDER BY 1 + col1, 2 + col2; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + col2 > 5 ORDER BY 1 + col2, 2 + col1; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + v1.col1 > 5 ORDER BY 1 + v1.col1, 2 + v1.col2; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + v1.col2 > 5 ORDER BY 1 + v1.col2, 2 + v1.col1; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + v1.col1 > 5 ORDER BY 1 + v1.col1, 2 + v2.col2; +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + v2.col1 > 5 ORDER BY 1 + v2.col1, 2 + v1.col2; + +-- Referencing any attribute under aggregate expression. +-- These mostly fail because Spark does not support referencing any attributes under aggregate expressions in ORDER BY on top of HAVING + +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING MAX(col1) > 5 ORDER BY MAX(col1); +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING MAX(col2) > 5 ORDER BY MAX(col2); +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v1.col1) > 5 ORDER BY MAX(v1.col1); +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v1.col2) > 5 ORDER BY MAX(v1.col2); +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v2.col1) > 5 ORDER BY MAX(v2.col1); +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v2.col2) > 5 ORDER BY MAX(v2.col2); + +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + MAX(col1) > 5 ORDER BY 1 + MAX(col1), 2 + MIN(col2); +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + MAX(col2) > 5 ORDER BY 1 + MAX(col2), 2 + MIN(col1); +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + MAX(v1.col1) > 5 ORDER BY 1 + MAX(v1.col1), 2 + MIN(v1.col2); +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + MAX(v1.col2) > 5 ORDER BY 1 + MAX(v1.col2), 2 + MIN(v1.col1); +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + MAX(v1.col1) > 5 ORDER BY 1 + MAX(v1.col1), 2 + MIN(v2.col2); +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + MAX(v1.col1) > 5 ORDER BY 1 + MAX(v1.col1), 2 + MIN(v2.col2); + +-- ORDER BY and HAVING with LCA below + +-- Referencing a grouping attribute + +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING col1 > 5 ORDER BY col1; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING col2 > 5 ORDER BY col2; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v1.col1 > 5 ORDER BY v1.col1; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v1.col2 > 5 ORDER BY v1.col2; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v2.col1 > 5 ORDER BY v2.col1; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v2.col2 > 5 ORDER BY v2.col2; + +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + col1 > 5 ORDER BY 1 + col1, 2 + col2; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + col2 > 5 ORDER BY 1 + col2, 2 + col1; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + v1.col1 > 5 ORDER BY 1 + v1.col1, 2 + v1.col2; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + v1.col2 > 5 ORDER BY 1 + v1.col2, 2 + v1.col1; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + v1.col1 > 5 ORDER BY 1 + v1.col1, 2 + v2.col2; +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + v2.col1 > 5 ORDER BY 1 + v2.col1, 2 + v1.col2; + +-- Referencing any attribute under aggregate expression. +-- These mostly fail because Spark does not support referencing any attributes under aggregate expressions in ORDER BY on top of HAVING + +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING MAX(col1) > 5 ORDER BY MAX(col1); +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING MAX(col2) > 5 ORDER BY MAX(col2); +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v1.col1) > 5 ORDER BY MAX(v1.col1); +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v1.col2) > 5 ORDER BY MAX(v1.col2); +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v2.col1) > 5 ORDER BY MAX(v2.col1); +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v2.col2) > 5 ORDER BY MAX(v2.col2); + +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + MAX(col1) > 5 ORDER BY 1 + MAX(col1), 2 + MIN(col2); +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + MAX(col2) > 5 ORDER BY 1 + MAX(col2), 2 + MIN(col1); +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + MAX(v1.col1) > 5 ORDER BY 1 + MAX(v1.col1), 2 + MIN(v1.col2); +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + MAX(v1.col2) > 5 ORDER BY 1 + MAX(v1.col2), 2 + MIN(v1.col1); +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + MAX(v1.col1) > 5 ORDER BY 1 + MAX(v1.col1), 2 + MIN(v2.col2); +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + MAX(v1.col1) > 5 ORDER BY 1 + MAX(v1.col1), 2 + MIN(v2.col2); + +-- Clean up +DROP VIEW IF EXISTS v1; +DROP VIEW IF EXISTS v2; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/order-by-ordinal.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/order-by-ordinal.sql index 8d733e77fa8..9908e215db8 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/order-by-ordinal.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/order-by-ordinal.sql @@ -28,6 +28,25 @@ select * from data order by 3; -- sort by ordinal select * from data sort by 1 desc; +-- SPARK-52565: Enforce ordinal resolution before other sort order expressions +set spark.sql.prioritizeOrdinalResolutionInSort.enabled=true; +SELECT a FROM data ORDER BY 2, b; +SELECT a FROM data ORDER BY b, 2; +SELECT a FROM data ORDER BY 'b', 2; +SELECT a FROM data ORDER BY `b`, 2; +SELECT a FROM data ORDER BY a, 2; +SELECT a FROM data ORDER BY b, 3; +SELECT a, a + 1 FROM data ORDER BY b, 3; + +set spark.sql.prioritizeOrdinalResolutionInSort.enabled=false; +SELECT a FROM data ORDER BY 2, b; +SELECT a FROM data ORDER BY b, 2; +SELECT a FROM data ORDER BY 'b', 2; +SELECT a FROM data ORDER BY `b`, 2; +SELECT a FROM data ORDER BY a, 2; +SELECT a FROM data ORDER BY b, 3; +SELECT a, a + 1 FROM data ORDER BY b, 3; + -- turn off order by ordinal set spark.sql.orderByOrdinal=false; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/order-by.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/order-by.sql index d67987bcb51..7dcc9de5ecd 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/order-by.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/order-by.sql @@ -30,5 +30,43 @@ SELECT * FROM testData ORDER BY (SELECT * FROM testData ORDER BY (SELECT a FROM -- Fails because correlation is not allowed in ORDER BY SELECT * FROM testData ORDER BY (SELECT a FROM VALUES (1)); +-- Nondeterministic expression + Aggregate expression in ORDER BY +SELECT col1 FROM VALUES (1, 2) GROUP BY col1 ORDER BY MAX(col2), RAND(); + +-- Order by table column and alias with the same name +SELECT 1 AS col1, col1 FROM VALUES (10) ORDER BY col1; + +-- Order by non-orderable expressions should fail +SELECT 'a' ORDER BY CAST('a' AS VARIANT); +SELECT a, b FROM testData ORDER BY CAST(a + b AS VARIANT); +SELECT a FROM testData ORDER BY CAST(CAST(a AS VARIANT) AS VARIANT); +SELECT a FROM testData GROUP BY a ORDER BY CAST(CAST(a AS STRING) AS VARIANT); +SELECT * FROM testData ORDER BY CAST(null AS VARIANT); +SELECT a FROM testData ORDER BY ARRAY(CAST(true AS VARIANT)); +SELECT a FROM testData ORDER BY CAST(ARRAY('a') AS VARIANT); +SELECT a FROM testData ORDER BY CAST(ARRAY(CAST(true AS VARIANT)) AS VARIANT); + +-- ORDER BY expression is resolved as a semantically equivalent to one in the SELECT list +SELECT SUM(a) + 1 FROM testData ORDER BY SUM(a) + 1; +SELECT 1 + SUM(b) FROM testData ORDER BY SUM(b) + 1; +SELECT SUM(a) + 1 FROM testData ORDER BY 1 + SUM(a); +SELECT MAX(a) + SUM(b) FROM testData ORDER BY SUM(b) + MAX(a); +SELECT SUM(a) + 1 + MIN(a) FROM testData ORDER BY 1 + 1 + 1 + MIN(a) + 1 + SUM(a); +SELECT SUM(b) + 1 FROM testData HAVING SUM(b) + 1 > 0 ORDER BY SUM(b) + 1; + +-- Missing attribute (col2) in ORDER BY is added only once +SELECT col1 FROM VALUES(1,2) GROUP BY col1, col2 ORDER BY col2, col2; +SELECT col1 AS a, a AS b FROM VALUES(1,2) GROUP BY col1, col2 ORDER BY col2, col2; + +-- Replacing SortOrder expression with alias from below +SELECT col1, col1 AS a FROM VALUES(1) GROUP BY col1 ORDER BY col1 ASC; +SELECT col1 AS a, col1 FROM VALUES(1) GROUP BY col1 ORDER BY col1 ASC; +SELECT make_date(col1, col2, col3) AS a, a AS b FROM VALUES(1,2,3) GROUP BY make_date(col1, col2, col3) ORDER BY make_date(col1, col2, col3); +SELECT 1 AS a, 1 / a AS b, ZEROIFNULL(SUM(col1)) FROM VALUES(1) GROUP BY 1 ORDER BY ZEROIFNULL(SUM(col1)); +SELECT col1 AS a, SUM(col2) AS b, CASE WHEN col1 = 1 THEN 1 END AS c FROM VALUES(1,2) GROUP BY col1 ORDER BY CASE WHEN col1 = 1 THEN 1 END ASC; + +-- Priority of aliases when replacing them in ORDER BY should be determined by name +SELECT col1+1 AS ltrl2, col1+1 AS ltrl1 FROM VALUES(1) GROUP BY col1+1 ORDER BY col1+1; + -- Clean up DROP VIEW IF EXISTS testData; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/postgreSQL/with.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/postgreSQL/with.sql index a3e0b15b582..bd349ec4a53 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/postgreSQL/with.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/postgreSQL/with.sql @@ -35,87 +35,113 @@ SELECT count(*) FROM ( -- WITH RECURSIVE -- sum of 1..100 --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE t(n) AS ( --- VALUES (1) ---UNION ALL --- SELECT n+1 FROM t WHERE n < 100 ---) ---SELECT sum(n) FROM t; +WITH RECURSIVE t(n) AS ( + VALUES (1) +UNION ALL + SELECT n+1 FROM t WHERE n < 100 +) +SELECT sum(n) FROM t; --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE t(n) AS ( --- SELECT (VALUES(1)) ---UNION ALL --- SELECT n+1 FROM t WHERE n < 5 ---) ---SELECT * FROM t; +WITH RECURSIVE t(n) AS ( + SELECT (VALUES(1)) +UNION ALL + SELECT n+1 FROM t WHERE n < 5 +) +SELECT * FROM t; -- recursive view --- [SPARK-24497] Support recursive SQL query +-- [SPARK-28453] Support recursive view syntax +-- [ORIGINAL SQL] --CREATE RECURSIVE VIEW nums (n) AS -- VALUES (1) --UNION ALL -- SELECT n+1 FROM nums WHERE n < 5; --- ---SELECT * FROM nums; +CREATE TEMPORARY VIEW nums AS +WITH RECURSIVE nums (n) AS ( + VALUES (1) +UNION ALL + SELECT n+1 FROM nums WHERE n < 5 +) +SELECT * FROM nums; + +SELECT * FROM nums; --- [SPARK-24497] Support recursive SQL query +-- [SPARK-28453] Support recursive view syntax +-- [ORIGINAL SQL] --CREATE OR REPLACE RECURSIVE VIEW nums (n) AS -- VALUES (1) --UNION ALL -- SELECT n+1 FROM nums WHERE n < 6; --- ---SELECT * FROM nums; +CREATE OR REPLACE TEMPORARY VIEW nums AS +WITH RECURSIVE nums (n) AS ( + VALUES (1) +UNION ALL + SELECT n+1 FROM nums WHERE n < 6 +) +SELECT * FROM nums; + +SELECT * FROM nums; -- This is an infinite loop with UNION ALL, but not with UNION --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE t(n) AS ( --- SELECT 1 ---UNION --- SELECT 10-n FROM t) ---SELECT * FROM t; +WITH RECURSIVE t(n) AS ( + SELECT 1 +UNION + SELECT 10-n FROM t) +SELECT * FROM t; -- This'd be an infinite loop, but outside query reads only as much as needed --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE t(n) AS ( --- VALUES (1) ---UNION ALL --- SELECT n+1 FROM t) ---SELECT * FROM t LIMIT 10; +WITH RECURSIVE t(n) AS ( + VALUES (1) +UNION ALL + SELECT n+1 FROM t) +SELECT * FROM t LIMIT 10; -- UNION case should have same property --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE t(n) AS ( --- SELECT 1 ---UNION --- SELECT n+1 FROM t) ---SELECT * FROM t LIMIT 10; +WITH RECURSIVE t(n) AS ( + SELECT 1 +UNION + SELECT n+1 FROM t) +SELECT * FROM t LIMIT 10; -- Test behavior with an unknown-type literal in the WITH -- [SPARK-28146] Support IS OF type predicate +-- [ORIGINAL SQL] --WITH q AS (SELECT 'foo' AS x) --SELECT x, x IS OF (text) AS is_text FROM q; +WITH q AS (SELECT 'foo' AS x) +SELECT x FROM q; --- [SPARK-24497] Support recursive SQL query -- [SPARK-28146] Support IS OF type predicate +-- [ORIGINAL SQL] --WITH RECURSIVE t(n) AS ( -- SELECT 'foo' --UNION ALL -- SELECT n || ' bar' FROM t WHERE length(n) < 20 --) --SELECT n, n IS OF (text) AS is_text FROM t; +WITH RECURSIVE t(n) AS ( + SELECT 'foo' +UNION ALL + SELECT n || ' bar' FROM t WHERE length(n) < 20 +) +SELECT n AS is_text FROM t; -- In a perfect world, this would work and resolve the literal as int ... -- but for now, we have to be content with resolving to text too soon. --- [SPARK-24497] Support recursive SQL query -- [SPARK-28146] Support IS OF type predicate +-- [ORIGINAL SQL] --WITH RECURSIVE t(n) AS ( -- SELECT '7' --UNION ALL -- SELECT n+1 FROM t WHERE n < 10 --) --SELECT n, n IS OF (int) AS is_int FROM t; +WITH RECURSIVE t(n) AS ( + SELECT '7' +UNION ALL + SELECT n+1 FROM t WHERE n < 10 +) +SELECT n FROM t; -- -- Some examples with a tree @@ -151,62 +177,58 @@ INSERT INTO department VALUES (7, 5, 'G'); -- extract all departments under 'A'. Result should be A, B, C, D and F --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE subdepartment AS ---( --- -- non recursive term --- SELECT name as root_name, * FROM department WHERE name = 'A' --- --- UNION ALL --- --- -- recursive term --- SELECT sd.root_name, d.* FROM department AS d, subdepartment AS sd --- WHERE d.parent_department = sd.id ---) ---SELECT * FROM subdepartment ORDER BY name; +WITH RECURSIVE subdepartment AS +( + -- non recursive term + SELECT name as root_name, * FROM department WHERE name = 'A' + + UNION ALL + + -- recursive term + SELECT sd.root_name, d.* FROM department AS d, subdepartment AS sd + WHERE d.parent_department = sd.id +) +SELECT * FROM subdepartment ORDER BY name; -- extract all departments under 'A' with "level" number --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE subdepartment(level, id, parent_department, name) AS ---( --- -- non recursive term --- SELECT 1, * FROM department WHERE name = 'A' --- --- UNION ALL --- --- -- recursive term --- SELECT sd.level + 1, d.* FROM department AS d, subdepartment AS sd --- WHERE d.parent_department = sd.id ---) ---SELECT * FROM subdepartment ORDER BY name; +WITH RECURSIVE subdepartment(level, id, parent_department, name) AS +( + -- non recursive term + SELECT 1, * FROM department WHERE name = 'A' + + UNION ALL + + -- recursive term + SELECT sd.level + 1, d.* FROM department AS d, subdepartment AS sd + WHERE d.parent_department = sd.id +) +SELECT * FROM subdepartment ORDER BY name; -- extract all departments under 'A' with "level" number. -- Only shows level 2 or more --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE subdepartment(level, id, parent_department, name) AS ---( --- -- non recursive term --- SELECT 1, * FROM department WHERE name = 'A' --- --- UNION ALL --- --- -- recursive term --- SELECT sd.level + 1, d.* FROM department AS d, subdepartment AS sd --- WHERE d.parent_department = sd.id ---) ---SELECT * FROM subdepartment WHERE level >= 2 ORDER BY name; +WITH RECURSIVE subdepartment(level, id, parent_department, name) AS +( + -- non recursive term + SELECT 1, * FROM department WHERE name = 'A' + + UNION ALL + + -- recursive term + SELECT sd.level + 1, d.* FROM department AS d, subdepartment AS sd + WHERE d.parent_department = sd.id +) +SELECT * FROM subdepartment WHERE level >= 2 ORDER BY name; -- "RECURSIVE" is ignored if the query has no self-reference --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE subdepartment AS ---( --- -- note lack of recursive UNION structure --- SELECT * FROM department WHERE name = 'A' ---) ---SELECT * FROM subdepartment ORDER BY name; +WITH RECURSIVE subdepartment AS +( + -- note lack of recursive UNION structure + SELECT * FROM department WHERE name = 'A' +) +SELECT * FROM subdepartment ORDER BY name; -- inside subqueries --- [SPARK-24497] Support recursive SQL query +-- [ORIGINAL SQL] --SELECT count(*) FROM ( -- WITH RECURSIVE t(n) AS ( -- SELECT 1 UNION ALL SELECT n + 1 FROM t WHERE n < 500 @@ -218,48 +240,59 @@ INSERT INTO department VALUES (7, 5, 'G'); -- ) -- SELECT * FROM t WHERE n < 50000 -- ) AS t WHERE n < 100); +-- [NOTE] Decreased recursion depth to avoid stack overflow +SET spark.sql.cteRecursionLevelLimit=200; +SELECT count(*) FROM ( + WITH RECURSIVE t(n) AS ( + SELECT 1 UNION ALL SELECT n + 1 FROM t WHERE n < 200 + ) + SELECT * FROM t) AS t WHERE n < ( + SELECT count(*) FROM ( + WITH RECURSIVE t(n) AS ( + SELECT 1 UNION ALL SELECT n + 1 FROM t WHERE n < 100 + ) + SELECT * FROM t WHERE n < 50000 + ) AS t WHERE n < 100); +SET spark.sql.cteRecursionLevelLimit=100; -- use same CTE twice at different subquery levels --- [SPARK-24497] Support recursive SQL query ---WITH q1(x,y) AS ( --- SELECT hundred, sum(ten) FROM tenk1 GROUP BY hundred --- ) ---SELECT count(*) FROM q1 WHERE y > (SELECT sum(y)/100 FROM q1 qsub); +WITH q1(x,y) AS ( + SELECT hundred, sum(ten) FROM tenk1 GROUP BY hundred + ) +SELECT count(*) FROM q1 WHERE y > (SELECT sum(y)/100 FROM q1 qsub); -- via a VIEW --- [SPARK-24497] Support recursive SQL query ---CREATE TEMPORARY VIEW vsubdepartment AS --- WITH RECURSIVE subdepartment AS --- ( --- -- non recursive term --- SELECT * FROM department WHERE name = 'A' --- UNION ALL --- -- recursive term --- SELECT d.* FROM department AS d, subdepartment AS sd --- WHERE d.parent_department = sd.id --- ) --- SELECT * FROM subdepartment; --- ---SELECT * FROM vsubdepartment ORDER BY name; --- +CREATE TEMPORARY VIEW vsubdepartment AS + WITH RECURSIVE subdepartment AS + ( + -- non recursive term + SELECT * FROM department WHERE name = 'A' + UNION ALL + -- recursive term + SELECT d.* FROM department AS d, subdepartment AS sd + WHERE d.parent_department = sd.id + ) + SELECT * FROM subdepartment; + +SELECT * FROM vsubdepartment ORDER BY name; + ---- Check reverse listing --SELECT pg_get_viewdef('vsubdepartment'::regclass); --SELECT pg_get_viewdef('vsubdepartment'::regclass, true); -- Another reverse-listing example --- [SPARK-24497] Support recursive SQL query ---CREATE VIEW sums_1_100 AS ---WITH RECURSIVE t(n) AS ( --- VALUES (1) ---UNION ALL --- SELECT n+1 FROM t WHERE n < 100 ---) ---SELECT sum(n) FROM t; --- ---\d+ sums_1_100 +CREATE VIEW sums_1_100 AS +WITH RECURSIVE t(n) AS ( + VALUES (1) +UNION ALL + SELECT n+1 FROM t WHERE n < 100 +) +SELECT sum(n) AS sum FROM t; + +SELECT * FROM sums_1_100; -- corner case in which sub-WITH gets initialized first --- [SPARK-24497] Support recursive SQL query +-- [NOTE] Spark SQL doesn't support recursive reference in an inner CTE --with recursive q as ( -- select * from department -- union all @@ -268,7 +301,7 @@ INSERT INTO department VALUES (7, 5, 'G'); -- ) --select * from q limit 24; --- [SPARK-24497] Support recursive SQL query +-- [NOTE] Spark SQL doesn't support recursive reference in an inner CTE --with recursive q as ( -- select * from department -- union all @@ -282,15 +315,14 @@ INSERT INTO department VALUES (7, 5, 'G'); --select * from q limit 32; -- recursive term has sub-UNION --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE t(i,j) AS ( --- VALUES (1,2) --- UNION ALL --- SELECT t2.i, t.j+1 FROM --- (SELECT 2 AS i UNION ALL SELECT 3 AS i) AS t2 --- JOIN t ON (t2.i = t.i+1)) --- --- SELECT * FROM t; +WITH RECURSIVE t(i,j) AS ( + VALUES (1,2) + UNION ALL + SELECT t2.i, t.j+1 FROM + (SELECT 2 AS i UNION ALL SELECT 3 AS i) AS t2 + JOIN t ON (t2.i = t.i+1)) + + SELECT * FROM t; -- -- different tree example @@ -312,7 +344,7 @@ VALUES (1, NULL), (2, 1), (3,1), (4,2), (5,2), (6,2), (7,3), (8,3), -- -- get all paths from "second level" nodes to leaf nodes -- --- [SPARK-24497] Support recursive SQL query +-- [ORIGINAL SQL] --WITH RECURSIVE t(id, path) AS ( -- VALUES(1,ARRAY[]::integer[]) --UNION ALL @@ -324,9 +356,20 @@ VALUES (1, NULL), (2, 1), (3,1), (4,2), (5,2), (6,2), (7,3), (8,3), -- array_upper(t1.path,1) = 1 AND -- array_upper(t2.path,1) > 1) -- ORDER BY t1.id, t2.id; +WITH RECURSIVE t(id, path) AS ( + VALUES(1,cast(array() as array)) +UNION ALL + SELECT tree.id, t.path || array(tree.id) + FROM tree JOIN t ON (tree.parent_id = t.id) +) +SELECT t1.*, t2.* FROM t AS t1 JOIN t AS t2 ON + (t1.path[0] = t2.path[0] AND + size(t1.path) = 1 AND + size(t2.path) > 1) + ORDER BY t1.id, t2.id; -- just count 'em --- [SPARK-24497] Support recursive SQL query +-- [ORIGINAL SQL] --WITH RECURSIVE t(id, path) AS ( -- VALUES(1,ARRAY[]::integer[]) --UNION ALL @@ -339,9 +382,21 @@ VALUES (1, NULL), (2, 1), (3,1), (4,2), (5,2), (6,2), (7,3), (8,3), -- array_upper(t2.path,1) > 1) -- GROUP BY t1.id -- ORDER BY t1.id; +WITH RECURSIVE t(id, path) AS ( + VALUES(1,cast(array() as array)) +UNION ALL + SELECT tree.id, t.path || array(tree.id) + FROM tree JOIN t ON (tree.parent_id = t.id) +) +SELECT t1.id, count(*) FROM t AS t1 JOIN t AS t2 ON + (t1.path[0] = t2.path[0] AND + size(t1.path) = 1 AND + size(t2.path) > 1) + GROUP BY t1.id + ORDER BY t1.id; -- this variant tickled a whole-row-variable bug in 8.4devel --- [SPARK-24497] Support recursive SQL query +-- [ORIGINAL SQL] --WITH RECURSIVE t(id, path) AS ( -- VALUES(1,ARRAY[]::integer[]) --UNION ALL @@ -350,6 +405,14 @@ VALUES (1, NULL), (2, 1), (3,1), (4,2), (5,2), (6,2), (7,3), (8,3), --) --SELECT t1.id, t2.path, t2 FROM t AS t1 JOIN t AS t2 ON --(t1.id=t2.id); +WITH RECURSIVE t(id, path) AS ( + VALUES(1,cast(array() as array)) +UNION ALL + SELECT tree.id, t.path || array(tree.id) + FROM tree JOIN t ON (tree.parent_id = t.id) +) +SELECT t1.id, t2.path, struct(t2.*) FROM t AS t1 JOIN t AS t2 ON +(t1.id=t2.id); -- -- test cycle detection @@ -366,7 +429,7 @@ insert into graph values (4, 5, 'arc 4 -> 5'), (5, 1, 'arc 5 -> 1'); --- [SPARK-24497] Support recursive SQL query +-- [ORIGINAL SQL] --with recursive search_graph(f, t, label, path, cycle) as ( -- select *, array[row(g.f, g.t)], false from graph g -- union all @@ -375,9 +438,17 @@ insert into graph values -- where g.f = sg.t and not cycle --) --select * from search_graph; +with recursive search_graph(f, t, label, path, cycle) as ( + select *, array(struct(g.f, g.t)), false from graph g + union all + select g.*, path || array(struct(g.f, g.t)), array_contains(path, struct(g.f, g.t)) + from graph g, search_graph sg + where g.f = sg.t and not cycle +) +select * from search_graph; -- ordering by the path column has same effect as SEARCH DEPTH FIRST --- [SPARK-24497] Support recursive SQL query +-- [ORIGINAL SQL] --with recursive search_graph(f, t, label, path, cycle) as ( -- select *, array[row(g.f, g.t)], false from graph g -- union all @@ -386,24 +457,31 @@ insert into graph values -- where g.f = sg.t and not cycle --) --select * from search_graph order by path; +with recursive search_graph(f, t, label, path, cycle) as ( + select *, array(struct(g.f, g.t)), false from graph g + union all + select g.*, path || array(struct(g.f, g.t)), array_contains(path, struct(g.f, g.t)) + from graph g, search_graph sg + where g.f = sg.t and not cycle +) +select * from search_graph order by path; -- -- test multiple WITH queries -- --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE --- y (id) AS (VALUES (1)), --- x (id) AS (SELECT * FROM y UNION ALL SELECT id+1 FROM x WHERE id < 5) ---SELECT * FROM x; +WITH RECURSIVE + y (id) AS (VALUES (1)), + x (id) AS (SELECT * FROM y UNION ALL SELECT id+1 FROM x WHERE id < 5) +SELECT * FROM x; -- forward reference OK --- [SPARK-24497] Support recursive SQL query +-- [NOTE] Spark SQL doesn't support forward references --WITH RECURSIVE -- x(id) AS (SELECT * FROM y UNION ALL SELECT id+1 FROM x WHERE id < 5), -- y(id) AS (values (1)) -- SELECT * FROM x; --- [SPARK-24497] Support recursive SQL query +-- [SPARK-28405] Join with USING caluse doesn't hide original tables --WITH RECURSIVE -- x(id) AS -- (VALUES (1) UNION ALL SELECT id+1 FROM x WHERE id < 5), @@ -411,7 +489,7 @@ insert into graph values -- (VALUES (1) UNION ALL SELECT id+1 FROM y WHERE id < 10) -- SELECT y.*, x.* FROM y LEFT JOIN x USING (id); --- [SPARK-24497] Support recursive SQL query +-- [SPARK-28405] Join with USING caluse doesn't hide original tables --WITH RECURSIVE -- x(id) AS -- (VALUES (1) UNION ALL SELECT id+1 FROM x WHERE id < 5), @@ -419,25 +497,23 @@ insert into graph values -- (VALUES (1) UNION ALL SELECT id+1 FROM x WHERE id < 10) -- SELECT y.*, x.* FROM y LEFT JOIN x USING (id); --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE --- x(id) AS --- (SELECT 1 UNION ALL SELECT id+1 FROM x WHERE id < 3 ), --- y(id) AS --- (SELECT * FROM x UNION ALL SELECT * FROM x), --- z(id) AS --- (SELECT * FROM x UNION ALL SELECT id+1 FROM z WHERE id < 10) --- SELECT * FROM z; - --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE --- x(id) AS --- (SELECT 1 UNION ALL SELECT id+1 FROM x WHERE id < 3 ), --- y(id) AS --- (SELECT * FROM x UNION ALL SELECT * FROM x), --- z(id) AS --- (SELECT * FROM y UNION ALL SELECT id+1 FROM z WHERE id < 10) --- SELECT * FROM z; +WITH RECURSIVE + x(id) AS + (SELECT 1 UNION ALL SELECT id+1 FROM x WHERE id < 3 ), + y(id) AS + (SELECT * FROM x UNION ALL SELECT * FROM x), + z(id) AS + (SELECT * FROM x UNION ALL SELECT id+1 FROM z WHERE id < 10) + SELECT * FROM z; + +WITH RECURSIVE + x(id) AS + (SELECT 1 UNION ALL SELECT id+1 FROM x WHERE id < 3 ), + y(id) AS + (SELECT * FROM x UNION ALL SELECT * FROM x), + z(id) AS + (SELECT * FROM y UNION ALL SELECT id+1 FROM z WHERE id < 10) + SELECT * FROM z; -- -- Test WITH attached to a data-modifying statement @@ -484,32 +560,26 @@ DROP TABLE y; -- -- INTERSECT --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE x(n) AS (SELECT 1 INTERSECT SELECT n+1 FROM x) --- SELECT * FROM x; +WITH RECURSIVE x(n) AS (SELECT 1 INTERSECT SELECT n+1 FROM x) + SELECT * FROM x; --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE x(n) AS (SELECT 1 INTERSECT ALL SELECT n+1 FROM x) --- SELECT * FROM x; +WITH RECURSIVE x(n) AS (SELECT 1 INTERSECT ALL SELECT n+1 FROM x) + SELECT * FROM x; -- EXCEPT --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE x(n) AS (SELECT 1 EXCEPT SELECT n+1 FROM x) --- SELECT * FROM x; +WITH RECURSIVE x(n) AS (SELECT 1 EXCEPT SELECT n+1 FROM x) + SELECT * FROM x; --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE x(n) AS (SELECT 1 EXCEPT ALL SELECT n+1 FROM x) --- SELECT * FROM x; +WITH RECURSIVE x(n) AS (SELECT 1 EXCEPT ALL SELECT n+1 FROM x) + SELECT * FROM x; -- no non-recursive term --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE x(n) AS (SELECT n FROM x) --- SELECT * FROM x; +WITH RECURSIVE x(n) AS (SELECT n FROM x) + SELECT * FROM x; -- recursive term in the left hand side (strictly speaking, should allow this) --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE x(n) AS (SELECT n FROM x UNION ALL SELECT 1) --- SELECT * FROM x; +WITH RECURSIVE x(n) AS (SELECT n FROM x UNION ALL SELECT 1) + SELECT * FROM x; -- [ORIGINAL SQL] --CREATE TEMPORARY TABLE y (a INTEGER); @@ -520,118 +590,110 @@ INSERT INTO y SELECT EXPLODE(SEQUENCE(1, 10)); -- LEFT JOIN --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE x(n) AS (SELECT a FROM y WHERE a = 1 --- UNION ALL --- SELECT x.n+1 FROM y LEFT JOIN x ON x.n = y.a WHERE n < 10) ---SELECT * FROM x; +WITH RECURSIVE x(n) AS (SELECT a FROM y WHERE a = 1 + UNION ALL + SELECT x.n+1 FROM y LEFT JOIN x ON x.n = y.a WHERE n < 10) +SELECT * FROM x; -- RIGHT JOIN --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE x(n) AS (SELECT a FROM y WHERE a = 1 --- UNION ALL --- SELECT x.n+1 FROM x RIGHT JOIN y ON x.n = y.a WHERE n < 10) ---SELECT * FROM x; +WITH RECURSIVE x(n) AS (SELECT a FROM y WHERE a = 1 + UNION ALL + SELECT x.n+1 FROM x RIGHT JOIN y ON x.n = y.a WHERE n < 10) +SELECT * FROM x; -- FULL JOIN --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE x(n) AS (SELECT a FROM y WHERE a = 1 --- UNION ALL --- SELECT x.n+1 FROM x FULL JOIN y ON x.n = y.a WHERE n < 10) ---SELECT * FROM x; +WITH RECURSIVE x(n) AS (SELECT a FROM y WHERE a = 1 + UNION ALL + SELECT x.n+1 FROM x FULL JOIN y ON x.n = y.a WHERE n < 10) +SELECT * FROM x; -- subquery --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE x(n) AS (SELECT 1 UNION ALL SELECT n+1 FROM x --- WHERE n IN (SELECT * FROM x)) --- SELECT * FROM x; +WITH RECURSIVE x(n) AS (SELECT 1 UNION ALL SELECT n+1 FROM x + WHERE n IN (SELECT * FROM x)) + SELECT * FROM x; -- aggregate functions --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE x(n) AS (SELECT 1 UNION ALL SELECT count(*) FROM x) --- SELECT * FROM x; +-- we need to cast 1 as bigint, as otherwise it will throw an error that the data types +-- are different +WITH RECURSIVE x(n) AS (SELECT cast(1 as bigint) UNION ALL SELECT count(*) FROM x) + SELECT * FROM x; --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE x(n) AS (SELECT 1 UNION ALL SELECT sum(n) FROM x) --- SELECT * FROM x; +WITH RECURSIVE x(n) AS (SELECT cast(1 as bigint) UNION ALL SELECT sum(n) FROM x) + SELECT * FROM x; -- ORDER BY --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE x(n) AS (SELECT 1 UNION ALL SELECT n+1 FROM x ORDER BY 1) --- SELECT * FROM x; +WITH RECURSIVE x(n) AS (SELECT 1 UNION ALL SELECT n+1 FROM x ORDER BY 1) + SELECT * FROM x; -- LIMIT/OFFSET --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE x(n) AS (SELECT 1 UNION ALL SELECT n+1 FROM x LIMIT 10 OFFSET 1) --- SELECT * FROM x; +WITH RECURSIVE x(n) AS (SELECT 1 UNION ALL SELECT n+1 FROM x LIMIT 10 OFFSET 1) + SELECT * FROM x; -- FOR UPDATE --- [SPARK-24497] Support recursive SQL query +-- [NOTE] Spark SQL doesn't support FOR UPDATE --WITH RECURSIVE x(n) AS (SELECT 1 UNION ALL SELECT n+1 FROM x FOR UPDATE) -- SELECT * FROM x; -- target list has a recursive query name --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE x(id) AS (values (1) --- UNION ALL --- SELECT (SELECT * FROM x) FROM x WHERE id < 5 ---) SELECT * FROM x; +WITH RECURSIVE x(id) AS (values (1) + UNION ALL + SELECT (SELECT * FROM x) FROM x WHERE id < 5 +) SELECT * FROM x; -- mutual recursive query (not implemented) --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE --- x (id) AS (SELECT 1 UNION ALL SELECT id+1 FROM y WHERE id < 5), --- y (id) AS (SELECT 1 UNION ALL SELECT id+1 FROM x WHERE id < 5) ---SELECT * FROM x; +WITH RECURSIVE + x (id) AS (SELECT 1 UNION ALL SELECT id+1 FROM y WHERE id < 5), + y (id) AS (SELECT 1 UNION ALL SELECT id+1 FROM x WHERE id < 5) +SELECT * FROM x; -- non-linear recursion is not allowed --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE foo(i) AS --- (values (1) --- UNION ALL --- (SELECT i+1 FROM foo WHERE i < 10 --- UNION ALL --- SELECT i+1 FROM foo WHERE i < 5) ---) SELECT * FROM foo; - --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE foo(i) AS --- (values (1) --- UNION ALL --- SELECT * FROM --- (SELECT i+1 FROM foo WHERE i < 10 --- UNION ALL --- SELECT i+1 FROM foo WHERE i < 5) AS t ---) SELECT * FROM foo; - --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE foo(i) AS --- (values (1) --- UNION ALL --- (SELECT i+1 FROM foo WHERE i < 10 --- EXCEPT --- SELECT i+1 FROM foo WHERE i < 5) ---) SELECT * FROM foo; - --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE foo(i) AS --- (values (1) --- UNION ALL --- (SELECT i+1 FROM foo WHERE i < 10 --- INTERSECT --- SELECT i+1 FROM foo WHERE i < 5) ---) SELECT * FROM foo; +WITH RECURSIVE foo(i) AS + (values (1) + UNION ALL + (SELECT i+1 FROM foo WHERE i < 10 + UNION ALL + SELECT i+1 FROM foo WHERE i < 5) +) SELECT * FROM foo; + +WITH RECURSIVE foo(i) AS + (values (1) + UNION ALL + SELECT * FROM + (SELECT i+1 FROM foo WHERE i < 10 + UNION ALL + SELECT i+1 FROM foo WHERE i < 5) AS t +) SELECT * FROM foo; + +WITH RECURSIVE foo(i) AS + (values (1) + UNION ALL + (SELECT i+1 FROM foo WHERE i < 10 + EXCEPT + SELECT i+1 FROM foo WHERE i < 5) +) SELECT * FROM foo; + +WITH RECURSIVE foo(i) AS + (values (1) + UNION ALL + (SELECT i+1 FROM foo WHERE i < 10 + INTERSECT + SELECT i+1 FROM foo WHERE i < 5) +) SELECT * FROM foo; -- Wrong type induced from non-recursive term --- [SPARK-24497] Support recursive SQL query +-- [ORIGINAL SQL] --WITH RECURSIVE foo(i) AS -- (SELECT i FROM (VALUES(1),(2)) t(i) -- UNION ALL -- SELECT (i+1)::numeric(10,0) FROM foo WHERE i < 10) --SELECT * FROM foo; +WITH RECURSIVE foo(i) AS + (SELECT i FROM (VALUES(1),(2)) t(i) + UNION ALL + SELECT cast((i+1) AS decimal(10,0)) FROM foo WHERE i < 10) +SELECT * FROM foo; -- rejects different typmod, too (should we allow this?) --- [SPARK-24497] Support recursive SQL query --WITH RECURSIVE foo(i) AS -- (SELECT i::numeric(3,0) FROM (VALUES(1),(2)) t(i) -- UNION ALL @@ -668,18 +730,17 @@ with cte(foo) as ( select 42 ) select * from ((select foo from cte)) q; -- -- test for nested-recursive-WITH bug -- --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE t(j) AS ( --- WITH RECURSIVE s(i) AS ( --- VALUES (1) --- UNION ALL --- SELECT i+1 FROM s WHERE i < 10 --- ) --- SELECT i FROM s --- UNION ALL --- SELECT j+1 FROM t WHERE j < 10 ---) ---SELECT * FROM t; +WITH RECURSIVE t(j) AS ( + WITH RECURSIVE s(i) AS ( + VALUES (1) + UNION ALL + SELECT i+1 FROM s WHERE i < 10 + ) + SELECT i FROM s + UNION ALL + SELECT j+1 FROM t WHERE j < 10 +) +SELECT * FROM t; -- -- test WITH attached to intermediate-level set operation @@ -701,22 +762,20 @@ WITH outermost(x) AS ( ) SELECT * FROM outermost ORDER BY 1; --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE outermost(x) AS ( --- SELECT 1 --- UNION (WITH innermost as (SELECT 2) --- SELECT * FROM outermost --- UNION SELECT * FROM innermost) ---) ---SELECT * FROM outermost ORDER BY 1; +WITH RECURSIVE outermost(x) AS ( + SELECT 1 + UNION (WITH innermost as (SELECT 2) + SELECT * FROM outermost + UNION SELECT * FROM innermost) +) +SELECT * FROM outermost ORDER BY 1; --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE outermost(x) AS ( --- WITH innermost as (SELECT 2 FROM outermost) -- fail --- SELECT * FROM innermost --- UNION SELECT * from outermost ---) ---SELECT * FROM outermost ORDER BY 1; +WITH RECURSIVE outermost(x) AS ( + WITH innermost as (SELECT 2 FROM outermost) -- fail + SELECT * FROM innermost + UNION SELECT * from outermost +) +SELECT * FROM outermost ORDER BY 1; -- -- This test will fail with the old implementation of PARAM_EXEC parameter @@ -737,8 +796,7 @@ SELECT * FROM outermost ORDER BY 1; -- Test CTEs read in non-initialization orders -- --- [SPARK-24497] Support recursive SQL query ---WITH RECURSIVE +-- [NOTE] Spark SQL doesn't support recursive reference in an inner CTE -- tab(id_key,link) AS (VALUES (1,17), (2,17), (3,17), (4,17), (6,17), (5,17)), -- iter (id_key, row_type, link) AS ( -- SELECT 0, 'base', 17 @@ -764,7 +822,7 @@ SELECT * FROM outermost ORDER BY 1; -- ) --SELECT * FROM iter; --- [SPARK-24497] Support recursive SQL query +-- [NOTE] Spark SQL doesn't support recursive reference in an inner CTE --WITH RECURSIVE -- tab(id_key,link) AS (VALUES (1,17), (2,17), (3,17), (4,17), (6,17), (5,17)), -- iter (id_key, row_type, link) AS ( @@ -796,7 +854,7 @@ SELECT * FROM outermost ORDER BY 1; -- -- INSERT ... RETURNING --- [SPARK-28147] Support RETURNING clause +-- [NOTE] Spark SQL doesn't support RETURNING --WITH t AS ( -- INSERT INTO y -- VALUES @@ -895,7 +953,7 @@ SELECT * FROM outermost ORDER BY 1; --SELECT * FROM bug6051_2; -- a truly recursive CTE in the same list --- [SPARK-24497] Support recursive SQL query +-- [NOTE] Spark SQL doesn't support RETURNING --WITH RECURSIVE t(a) AS ( -- SELECT 0 -- UNION ALL @@ -1003,7 +1061,6 @@ INSERT INTO y SELECT EXPLODE(SEQUENCE(1, 3)); --CREATE TEMPORARY TABLE yy (a INTEGER); CREATE TABLE yy (a INTEGER) USING parquet; --- [SPARK-24497] Support recursive SQL query -- [SPARK-28147] Support RETURNING clause --WITH RECURSIVE t1 AS ( -- INSERT INTO y SELECT * FROM y RETURNING * @@ -1015,7 +1072,6 @@ CREATE TABLE yy (a INTEGER) USING parquet; SELECT * FROM y; SELECT * FROM yy; --- [SPARK-24497] Support recursive SQL query -- [SPARK-28147] Support RETURNING clause --WITH RECURSIVE t1 AS ( -- INSERT INTO yy SELECT * FROM t2 RETURNING * @@ -1148,7 +1204,7 @@ SELECT * FROM parent; -- error cases -- data-modifying WITH tries to use its own output --- [SPARK-24497] Support recursive SQL query +-- [NOTE] Spark SQL doesn't support INSERT in WITH --WITH RECURSIVE t AS ( -- INSERT INTO y -- SELECT * FROM t @@ -1156,7 +1212,7 @@ SELECT * FROM parent; --VALUES(FALSE); -- no RETURNING in a referenced data-modifying WITH --- [SPARK-24497] Support recursive SQL query +-- [NOTE] Spark SQL doesn't support INSERT in WITH --WITH t AS ( -- INSERT INTO y VALUES(0) --) @@ -1199,6 +1255,9 @@ drop table test; -- -- Clean up -- +DROP VIEW nums; +DROP VIEW vsubdepartment; +DROP VIEW sums_1_100; DROP TABLE department; DROP TABLE tree; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/replacing-missing-expression-with-alias.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/replacing-missing-expression-with-alias.sql new file mode 100644 index 00000000000..0f238033fad --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/replacing-missing-expression-with-alias.sql @@ -0,0 +1,33 @@ +-- Replace expression with alias that has semantically equal child if expression is not in output +SELECT col1 + 1 AS a FROM VALUES(1) GROUP BY a ORDER BY col1 + 1; +SELECT col1 + 1 AS a, a AS b FROM VALUES(1) GROUP BY a ORDER BY col1 + 1; +SELECT col1 + 1 AS a FROM VALUES(1) GROUP BY a HAVING col1 + 1 > 0; +SELECT col1 + 1 AS a, a AS b FROM VALUES(1) GROUP BY a HAVING col1 + 1 > 0; + +SELECT col1, col2, GROUPING(col1) FROM VALUES("abc", 1) GROUP BY CUBE(col1, col2) ORDER BY GROUPING(col1); +SELECT col1, col2, GROUPING(col1) FROM VALUES("abc", 1) GROUP BY CUBE(col1, col2) HAVING GROUPING(col1) != NULL; + + +SELECT make_date(col1, col2, col3) AS a FROM VALUES(1,2,3) GROUP BY make_date(col1, col2, col3) ORDER BY make_date(col1, col2, col3); +SELECT make_date(col1, col2, col3) AS a, a AS b FROM VALUES(1,2,3) GROUP BY make_date(col1, col2, col3) ORDER BY make_date(col1, col2, col3); +SELECT make_date(col1, col2, col3) AS a FROM VALUES(1,2,3) GROUP BY make_date(col1, col2, col3) HAVING make_date(col1, col2, col3) > '2025-01-01'; +SELECT make_date(col1, col2, col3) AS a, a AS b FROM VALUES(1,2,3) GROUP BY make_date(col1, col2, col3) HAVING make_date(col1, col2, col3) > '2025-01-01'; + +-- Don't replace expression with alias that has semantically equal child if expression is not grouping +SELECT make_date(col1, col2, col3) AS a FROM VALUES(1,2,3) ORDER BY make_date(col1, col2, col3); +SELECT make_date(col1, col2, col3) AS a, a AS b FROM VALUES(1,2,3) ORDER BY make_date(col1, col2, col3); + +-- Don't replace expression with alias that has semantically equal child if expression is in output +SELECT col1, col1 AS a FROM VALUES(1) GROUP BY col1 ORDER BY col1 ASC; +SELECT col1 AS a, col1 FROM VALUES(1) GROUP BY col1 ORDER BY col1 ASC; +SELECT col1, col1 AS a FROM VALUES(1) GROUP BY col1 HAVING col1 > 0; +SELECT col1 AS a, col1 FROM VALUES(1) GROUP BY col1 HAVING col1 > 0; + +SELECT col2 AS b, col2 FROM VALUES(1,2) GROUP BY 1,2 ORDER BY ALL; +SELECT col2 AS b, col2 FROM VALUES(1,2) GROUP BY 1,2 HAVING col2 > 0 ORDER BY ALL; +SELECT col2 AS b, col2, b as c FROM VALUES(1,2) GROUP BY 1,2 ORDER BY ALL; +SELECT col2 AS b, col2, b as c FROM VALUES(1,2) GROUP BY 1,2 HAVING col2 > 0 ORDER BY ALL; + +-- Fixed point doesn't know to correctly replace `col1` with `a` because HAVING adds an artificial Project node +SELECT col1 AS a FROM VALUES(1,2) GROUP BY col1, col2 HAVING col2 > 1 ORDER BY col1; +SELECT col1 AS a, a AS b FROM VALUES(1,2) GROUP BY col1, col2 HAVING col2 > 1 ORDER BY col1; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/runtime-replaceable-edge-cases.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/runtime-replaceable-edge-cases.sql new file mode 100644 index 00000000000..948c034a5ab --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/runtime-replaceable-edge-cases.sql @@ -0,0 +1,2 @@ +-- Check that replacement in RuntimeReplaceable is resolved +SELECT xpath_string('abc', date_format('X', 'unknown')); diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/scripting/randomly_generated_scripts.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/scripting/randomly_generated_scripts.sql new file mode 100644 index 00000000000..83906bad428 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/scripting/randomly_generated_scripts.sql @@ -0,0 +1,6883 @@ +---- SETUP + +-- Table: products +CREATE TABLE products ( + product_id INT, + product_name STRING, + product_category STRING, + product_price DOUBLE, + product_cost DECIMAL(10, 2), + supplier_id INT, + supplier_name STRING, + supplier_contact STRING, + supplier_address STRING, + product_quantity INT, + product_color STRING, + product_size STRING, + product_weight DOUBLE, + product_description STRING, + product_rating DOUBLE, + product_reviews INT, + product_launch_date TIMESTAMP, + product_last_update TIMESTAMP, + product_is_active BOOLEAN, + product_discount DOUBLE, + product_vat DOUBLE +); + +-- Table: customers +CREATE TABLE customers ( + customer_id INT, + customer_name STRING, + customer_email STRING, + customer_phone STRING, + customer_address_1 STRING, + customer_address_2 STRING, + customer_city STRING, + customer_state STRING, + customer_zip STRING, + customer_country STRING, + customer_type STRING, + customer_membership_date TIMESTAMP, + customer_total_spent DOUBLE, + customer_last_order_id INT, + customer_last_order_date TIMESTAMP, + customer_last_payment_date TIMESTAMP, + customer_active_status BOOLEAN, + customer_opt_in_newsletter BOOLEAN, + customer_discount_percentage DOUBLE, + customer_vat_number STRING, + customer_billing_contact STRING +); + +-- Table: orders +CREATE TABLE orders ( + order_id INT, + customer_id INT, + order_date TIMESTAMP, + order_status STRING, + order_total DOUBLE, + order_tax DOUBLE, + order_discount DOUBLE, + order_shipping DOUBLE, + order_shipping_address_1 STRING, + order_shipping_address_2 STRING, + order_shipping_city STRING, + order_shipping_state STRING, + order_shipping_zip STRING, + order_shipping_country STRING, + order_billing_identifier STRING, + order_payment_method STRING, + order_payment_status STRING, + order_payment_date TIMESTAMP, + order_cancelation_date TIMESTAMP, + order_return_request_date TIMESTAMP, + order_completion_date TIMESTAMP, + order_source STRING, + order_device STRING, + order_channel STRING +); + +-- Table: order_items +CREATE TABLE order_items ( + order_item_id INT, + order_id INT, + product_id INT, + item_quantity INT, + item_price_per_unit DOUBLE, + item_discount DOUBLE, + item_tax DOUBLE, + item_total DOUBLE, + item_status STRING, + item_offer_code STRING, + item_shipping_date TIMESTAMP, + item_delivery_date TIMESTAMP, + item_return_date TIMESTAMP +); + +-- Table: employees +CREATE TABLE employees ( + employee_id INT, + employee_name STRING, + employee_email STRING, + employee_phone STRING, + employee_position STRING, + employee_department STRING, + employee_hire_date TIMESTAMP, + employee_termination_date TIMESTAMP, + employee_salary DOUBLE, + employee_commission DOUBLE, + employee_manager_id INT, + employee_address_1 STRING, + employee_address_2 STRING, + employee_city STRING, + employee_state STRING, + employee_zip STRING, + employee_country STRING, + employee_birth_date TIMESTAMP, + employee_gender STRING, + employee_marital_status STRING, + employee_dependents INT +); + +-- Table: suppliers +CREATE TABLE suppliers ( + supplier_id INT, + supplier_name STRING, + supplier_contact STRING, + supplier_contact_role STRING, + supplier_contact_email STRING, + supplier_contact_phone_1 STRING, + supplier_contact_phone_2 STRING, + supplier_address_1 STRING, + supplier_address_2 STRING, + supplier_address_3 STRING, + supplier_city STRING, + supplier_state STRING, + supplier_zip STRING, + supplier_country STRING, + supplier_region STRING, + supplier_main_products STRING, + supplier_website STRING, + supplier_pricing_agreement_date TIMESTAMP, + supplier_last_order_date TIMESTAMP, + supplier_last_contact_date TIMESTAMP, + supplier_rating DOUBLE, + supplier_active BOOLEAN +); + +-- INSERT example data (for each table, a few typical rows) +INSERT INTO products VALUES (1, 'Super Widget', 'Electronics', 155.99, 99.99, 1, 'Acme Inc', 'John D.', '123 Main St', 25, 'Blue', 'Large', 1.2, 'High quality widget', 4.5, 120, TIMESTAMP '2022-01-01', TIMESTAMP '2023-01-01', true, 0.0, 0.21); +INSERT INTO products VALUES (2, 'Deluxe Gadget', 'Electronics', 89.99, 60.00, 2, 'Widgets Co', 'Mary K.', '456 Elm St', 100, 'Red', 'Small', 0.5, 'Portable gadget', 4.2, 200, TIMESTAMP '2022-02-15', TIMESTAMP '2023-02-15', true, 0.1, 0.19); +INSERT INTO products VALUES (3, 'Classic Toy', 'Toys', 19.95, 12.00, 3, 'Toy Supply', 'Ann T.', '789 Oak St', 50, 'Multicolor', 'Medium', 0.8, 'Classic wooden toy', 4.7, 80, TIMESTAMP '2021-11-01', TIMESTAMP '2023-01-10', true, 0.05, 0.15); + +INSERT INTO customers VALUES (1, 'Alice Johnson', 'alice@example.com', '555-1000', '101 Maple Ave', NULL, 'Springfield', 'IL', '12345', 'USA', 'Retail', TIMESTAMP '2020-05-01', 899.99, 1001, TIMESTAMP '2023-01-20', TIMESTAMP '2023-01-21', true, true, 5.0, 'US123456', 'Alice Johnson'); +INSERT INTO customers VALUES (2, 'Bob Smith', 'bob@example.com', '555-1002', '202 Oak St', 'Apt 3', 'Oakville', 'CA', '67890', 'USA', 'Wholesale', TIMESTAMP '2021-03-15', 1200.50, 1002, TIMESTAMP '2023-02-10', TIMESTAMP '2023-02-11', true, false, 10.0, 'US923456', 'Bob Smith'); +INSERT INTO customers VALUES (3, 'Cathy Lee', 'cathy@example.com', '555-1003', '303 Pine Ln', NULL, 'Pineville', 'TX', '54321', 'USA', 'Retail', TIMESTAMP '2022-07-01', 400.75, 1003, TIMESTAMP '2023-03-05', TIMESTAMP '2023-03-06', true, true, 0.0, 'US563456', 'Cathy Lee'); + +INSERT INTO orders VALUES (1001, 1, TIMESTAMP '2023-01-20', 'Completed', 155.99, 15.89, 0.0, 10.00, '101 Maple Ave', NULL, 'Springfield', 'IL', '12345', 'USA', 'ORD1001', 'Credit Card', 'Paid', TIMESTAMP '2023-01-21', NULL, NULL, TIMESTAMP '2023-01-25', 'Web', 'Desktop', 'Online'); +INSERT INTO orders VALUES (1002, 2, TIMESTAMP '2023-02-10', 'Completed', 179.89, 18.99, 10.0, 8.99, '202 Oak St', 'Apt 3', 'Oakville', 'CA', '67890', 'USA', 'ORD1002', 'Credit Card', 'Paid', TIMESTAMP '2023-02-11', NULL, NULL, TIMESTAMP '2023-02-15', 'Mobile', 'iOS', 'Online'); +INSERT INTO orders VALUES (1003, 3, TIMESTAMP '2023-03-05', 'Processing', 19.95, 3.99, 1.0, 5.99, '303 Pine Ln', NULL, 'Pineville', 'TX', '54321', 'USA', 'ORD1003', 'PayPal', 'Pending', NULL, NULL, NULL, NULL, 'App', 'Android', 'Mobile App'); + +INSERT INTO order_items VALUES (101, 1001, 1, 1, 155.99, 0.0, 15.89, 171.88, 'Shipped', 'SPRING2023', TIMESTAMP '2023-01-20', NULL, NULL); +INSERT INTO order_items VALUES (102, 1002, 2, 2, 89.99, 8.99, 8.99, 170.97, 'Shipped', 'SUMMER2023', TIMESTAMP '2023-02-10', NULL, NULL); +INSERT INTO order_items VALUES (103, 1003, 3, 1, 19.95, 1.0, 3.99, 22.94, 'Processing', 'FALL2023', NULL, NULL, NULL); + +INSERT INTO employees VALUES (1, 'Dan Miller', 'dan@example.com', '555-2001', 'Manager', 'Sales', TIMESTAMP '2018-01-01', NULL, 75000.0, 2500.0, NULL, '404 Birch St', NULL, 'Birchville', 'NY', '00123', 'USA', TIMESTAMP '1980-07-10', 'Male', 'Married', 2); +INSERT INTO employees VALUES (2, 'Eva Perez', 'eva@example.com', '555-2002', 'Salesperson', 'Sales', TIMESTAMP '2019-03-01', NULL, 50000.0, 1500.0, 1, '505 Cedar Dr', 'Unit 2', 'Cedarville', 'NJ', '00234', 'USA', TIMESTAMP '1992-09-25', 'Female', 'Single', 0); +INSERT INTO employees VALUES (3, 'Frank Wong', 'frank@example.com', '555-2003', 'Warehouse', 'Operations', TIMESTAMP '2020-06-15', NULL, 40000.0, 0.0, 2, '606 Walnut Ln', NULL, 'Walnut', 'CA', '00345', 'USA', TIMESTAMP '1988-02-14', 'Male', 'Married', 1); + +INSERT INTO suppliers VALUES (1, 'Acme Inc', 'John D.', 'Sales Manager', 'john@acme.com', '555-3001', '555-3002', '123 Main St', NULL, NULL, 'Springfield', 'IL', '12345', 'USA', 'Midwest', 'Widgets, Gadgets', 'https://acme.com', TIMESTAMP '2020-01-01', NULL, TIMESTAMP '2023-01-10', 4.8, true); +INSERT INTO suppliers VALUES (2, 'Widgets Co', 'Mary K.', 'Customer Success', 'mary@widgets.com', '555-4001', NULL, '456 Elm St', NULL, NULL, 'Oakville', 'CA', '67890', 'USA', 'West', 'Gadgets, Toys', 'https://widgetsco.com', TIMESTAMP '2021-02-01', NULL, TIMESTAMP '2023-02-15', 4.6, true); +INSERT INTO suppliers VALUES (3, 'Toy Supply', 'Ann T.', 'Director', 'ann@toysupply.com', '555-5001', NULL, '789 Oak St', NULL, NULL, 'Pineville', 'TX', '54321', 'USA', 'South', 'Toys, Games', 'https://toysupply.com', TIMESTAMP '2019-03-01', NULL, TIMESTAMP '2023-03-01', 4.4, true); + +---- Scripts + +-- Script 1 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_inventory_threshold INT DEFAULT 20; + DECLARE v_low_stock_products INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Stock error'); END; + -- Nested compound statements, labels, mixed control flow + main_block: BEGIN + DECLARE v_product_id INT; + DECLARE v_product_name STRING; + DECLARE v_supplier_id INT; + DECLARE v_action_taken STRING; + FOR product AS SELECT p.product_id, p.product_name, p.supplier_id, p.product_quantity FROM products p JOIN suppliers s ON p.supplier_id = s.supplier_id LIMIT 5 DO + SET v_product_id = product.product_id; + SET v_product_name = product.product_name; + SET v_supplier_id = product.supplier_id; + L1: BEGIN + CASE + WHEN product.product_quantity < v_inventory_threshold THEN + SET v_action_taken = 'Restock needed'; + SET v_low_stock_products = v_low_stock_products + 1; + INSERT INTO orders (order_id, customer_id, order_date, order_status, order_total, order_tax, order_discount, order_shipping) + VALUES (v_product_id * 1000, (SELECT MIN(customer_id) FROM customers), CURRENT_TIMESTAMP, 'Restock', (SELECT product_cost FROM products WHERE product_id = v_product_id) * 10, 0.0, 0.0, 0.0); + INSERT INTO order_items (order_item_id, order_id, product_id, item_quantity, item_price_per_unit, item_discount, item_tax, item_total) + VALUES (v_product_id * 100 + 1, v_product_id * 1000, v_product_id, 10, (SELECT product_cost FROM products WHERE product_id = v_product_id), 0.0, 0.0, (SELECT product_cost FROM products WHERE product_id = v_product_id) * 10); + ELSE + SET v_action_taken = 'Sufficient stock'; + END CASE; + BEGIN + DECLARE v_supplier_active BOOLEAN; + SET v_supplier_active = (SELECT supplier_active FROM suppliers WHERE supplier_id = v_supplier_id); + IF NOT v_supplier_active THEN + SET v_action_taken = CONCAT(v_action_taken, ' (Supplier inactive)'); + BEGIN + DECLARE v_temp_id INT; + SET v_temp_id = (SELECT COALESCE(MAX(supplier_id), 0) + 1 FROM suppliers); + INSERT INTO suppliers VALUES (v_temp_id, 'Temp Supplier', 'Temp Contact', 'Temp Role', 'temp@temp.com', '555-0000', NULL, 'Temp Address', NULL, NULL, 'Temp City', 'TX', '00000', 'USA', 'South', 'Temporary', 'http://temp.com', CURRENT_TIMESTAMP, NULL, CURRENT_TIMESTAMP, 3.0, true); + END; + END IF; + END; + END L1; + END FOR; + END main_block; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, CASE, IF, DML, nested-scopes, exception-handler, mixed-logic +-- EXPECTED: Random restock orders, supplier inserts, status logic +-- EXECUTES: FOR, CASE, IF, nested BEGIN...END + +-- Script 2 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_city_count INT; + DECLARE v_state_count INT; + DECLARE v_city_shortage_found BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Geo error'); END; + -- Deep, wide, and random nesting with labels + city_loop: FOR city AS SELECT DISTINCT customer_city FROM customers LIMIT 3 DO + SET v_city_count = (SELECT COUNT(*) FROM customers WHERE customer_city = city.customer_city); + state_scope: BEGIN + DECLARE v_state STRING; + SET v_state = (SELECT MAX(customer_state) FROM customers WHERE customer_city = city.customer_city); + IF v_state IS NOT NULL THEN + SET v_state_count = (SELECT COUNT(*) FROM customers WHERE customer_state = v_state); + L1: BEGIN + DECLARE v_region_ok BOOLEAN DEFAULT true; + FOR region AS SELECT DISTINCT supplier_region FROM suppliers LIMIT 1 DO + IF region.supplier_region IS NULL THEN + SET v_region_ok = false; + END IF; + END FOR; + IF NOT v_region_ok THEN + SET v_city_shortage_found = true; + END IF; + END L1; + END IF; + END state_scope; + BEGIN + DECLARE v_employee_id INT; + SET v_employee_id = (SELECT MIN(employee_id) FROM employees); + IF v_city_count < 2 AND NOT v_city_shortage_found THEN + BEGIN + DECLARE v_new_customer_id INT; + SET v_new_customer_id = (SELECT COALESCE(MAX(customer_id), 0) + 1 FROM customers); + INSERT INTO customers VALUES (v_new_customer_id, 'New Customer', 'new@customer.com', '555-1111', '555 Place', city.customer_city, (SELECT DISTINCT customer_state FROM customers WHERE customer_city = city.customer_city LIMIT 1), '00000', 'USA', 'Retail', CURRENT_TIMESTAMP, 0.0, NULL, NULL, NULL, true, true, 0.0, NULL, NULL); + END; + END IF; + WHILE v_employee_id < 3 DO + SET v_employee_id = v_employee_id + 1; + BEGIN + DECLARE v_customer_address STRING; + SET v_customer_address = (SELECT customer_address_1 FROM customers WHERE customer_city = city.customer_city LIMIT 1); + IF v_customer_address IS NULL THEN + SET v_customer_address = 'Unknown'; + END IF; + END; + END WHILE; + END; + END FOR city_loop; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, WHILE, DML, deep-nesting, wide-scopes, exception-handler, geo-logic +-- EXPECTED: Random customer inserts, geo checks, possible city shortage +-- EXECUTES: FOR, IF, WHILE, nested BEGIN...END, exception handler + +-- Script 3 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_total_orders INT; + DECLARE v_customer_id INT; + DECLARE v_order_id INT; + DECLARE v_last_order_date TIMESTAMP; + DECLARE v_product_count INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Orders processing error'); END; + -- Wide and deep, with mixed control structures + customer_block: BEGIN + DECLARE v_customer_threshold INT DEFAULT 2; + FOR cust AS SELECT customer_id, customer_name FROM customers LIMIT 5 DO + SET v_customer_id = cust.customer_id; + SET v_total_orders = (SELECT COUNT(*) FROM orders WHERE customer_id = cust.customer_id); + SET v_last_order_date = (SELECT MAX(order_date) FROM orders WHERE customer_id = cust.customer_id); + IF v_total_orders < v_customer_threshold THEN + SET v_order_id = (SELECT COALESCE(MAX(order_id), 0) + 1 FROM orders); + INSERT INTO orders (order_id, customer_id, order_date, order_status, order_total, order_tax, order_discount, order_shipping) + VALUES (v_order_id, v_customer_id, CURRENT_TIMESTAMP, 'New', 10.0, 1.0, 0.0, 2.0); + L1: BEGIN + DECLARE v_item_id INT; + SET v_product_count = (SELECT COUNT(*) FROM products); + IF v_product_count > 0 THEN + FOR prod AS SELECT product_id FROM products LIMIT 3 DO + SET v_item_id = (SELECT COALESCE(MAX(order_item_id), 0) + 1 FROM order_items); + INSERT INTO order_items (order_item_id, order_id, product_id, item_quantity, item_price_per_unit, item_discount, item_tax, item_total) + VALUES (v_item_id, v_order_id, prod.product_id, 1, (SELECT product_price FROM products WHERE product_id = prod.product_id), 0.0, 0.0, (SELECT product_price FROM products WHERE product_id = prod.product_id)); + END FOR; + END IF; + END L1; + ELSE + L2: BEGIN + DECLARE v_days_since_last_order INT; + SET v_days_since_last_order = DATEDIFF(DAY, v_last_order_date, CURRENT_TIMESTAMP); + IF v_days_since_last_order > 30 THEN + L3: BEGIN + DECLARE v_random_product_id INT; + SET v_random_product_id = (SELECT product_id FROM products LIMIT 1); + INSERT INTO order_items (order_item_id, order_id, product_id, item_quantity, item_price_per_unit, item_discount, item_tax, item_total) + VALUES ((SELECT COALESCE(MAX(order_item_id), 0) + 1 FROM order_items), (SELECT MIN(order_id) FROM orders WHERE customer_id = v_customer_id), v_random_product_id, 1, (SELECT product_price FROM products WHERE product_id = v_random_product_id), 0.0, 0.0, (SELECT product_price FROM products WHERE product_id = v_random_product_id)); + END L3; + SET v_last_order_date = CURRENT_TIMESTAMP; + ELSE + BEGIN + DECLARE v_orders_to_delete INT; + SET v_orders_to_delete = (SELECT COUNT(*) FROM orders WHERE order_status = 'Processing' AND customer_id = v_customer_id); + WHILE v_orders_to_delete > 1 DO + DELETE FROM orders WHERE order_id IN (SELECT order_id FROM orders WHERE order_status = 'Processing' AND customer_id = v_customer_id LIMIT 1); + SET v_orders_to_delete = v_orders_to_delete - 1; + END WHILE; + END; + END IF; + END L2; + END IF; + END FOR; + END customer_block; + BEGIN + DECLARE v_max_order_total DOUBLE; + SET v_max_order_total = (SELECT MAX(order_total) FROM orders); + IF v_max_order_total > 200 THEN + L4: BEGIN + DECLARE v_large_orders INT; + SET v_large_orders = (SELECT COUNT(*) FROM orders WHERE order_total > 200); + IF v_large_orders > 1 THEN + REPEAT + UPDATE orders SET order_shipping = order_shipping * 0.9 WHERE order_status = 'Completed' AND order_total > 200; + SET v_large_orders = (SELECT COUNT(*) FROM orders WHERE order_total > 200); + UNTIL v_large_orders < 2 END REPEAT; + END IF; + END L4; + END IF; + END; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, WHILE, REPEAT, DML, nested-scopes, exception-handler, mixed-logic +-- EXPECTED: Orders and items created, updated, or deleted; conditional logic on customer activity +-- EXECUTES: FOR, IF, WHILE, REPEAT, nested BEGIN...END, exception handler + +-- Script 4 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_first_name STRING; + DECLARE v_last_name STRING; + DECLARE v_employee_name STRING; + DECLARE v_is_manager BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Employee processing error'); END; + -- Deep, wide, variable nesting, labels + staff_scope: BEGIN + DECLARE v_emp_count INT DEFAULT 0; + DECLARE v_manager_id INT; + SET v_manager_id = (SELECT MIN(employee_id) FROM employees WHERE employee_position = 'Manager'); + FOR emp AS SELECT employee_id, employee_name, employee_position FROM employees LIMIT 4 DO + SET v_employee_name = emp.employee_name; + SET v_emp_count = v_emp_count + 1; + L1: BEGIN + DECLARE v_split_result ARRAY; + SET v_split_result = split(v_employee_name, ' '); + CASE v_split_result[0] + WHEN 'Dan' THEN SET v_is_manager = true; + ELSE SET v_is_manager = false; + END CASE; + IF v_is_manager AND v_emp_count > 1 THEN + L2: BEGIN + DECLARE v_subordinates INT; + SET v_subordinates = (SELECT COUNT(*) FROM employees WHERE employee_manager_id = emp.employee_id); + IF v_subordinates > 0 THEN + FOR sub_emp AS SELECT employee_id, employee_name FROM employees WHERE employee_manager_id = emp.employee_id LIMIT 2 DO + L3: BEGIN + DECLARE v_name_part STRING; + SET v_name_part = (SELECT CONCAT(split(sub_emp.employee_name, ' ')[0], '_', ROUND(RANDOM() * 100))); + INSERT INTO customers (customer_id, customer_name, customer_email, customer_phone, customer_address_1, customer_city, customer_state, customer_zip, customer_country, customer_active_status) + VALUES (sub_emp.employee_id + 9999, v_name_part, CONCAT(v_name_part, '@company.com'), '555-8888', '123 HR St', 'HQ City', 'CA', '00000', 'USA', true); + END L3; + END FOR; + END IF; + END L2; + ELSE + REPEAT + SET v_emp_count = v_emp_count + 1; + L4: BEGIN + DECLARE v_todays_date STRING; + SET v_todays_date = DATE_FORMAT(CURRENT_TIMESTAMP, 'yyyy-MM-dd'); + INSERT INTO suppliers (supplier_id, supplier_name, supplier_contact, supplier_contact_role, supplier_contact_email, supplier_contact_phone_1, supplier_address_1, supplier_city, supplier_state, supplier_zip, supplier_country, supplier_region, supplier_main_products, supplier_active) + VALUES (emp.employee_id + 10000, CONCAT('Emp_', emp.employee_id), emp.employee_name, 'Employee', CONCAT(emp.employee_name, '@temp.com'), '555-9999', '123 Emp St', 'Emp City', 'CA', '00001', 'USA', 'West', 'Misc', true); + END L4; + UNTIL v_emp_count > 3 END REPEAT; + END IF; + END L1; + END FOR; + END staff_scope; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, CASE, REPEAT, DML, nested-scopes, exception-handler, string-manipulation +-- EXPECTED: Customer and supplier inserts based on staff data, string manipulation, manager checks +-- EXECUTES: FOR, IF, CASE, REPEAT, nested BEGIN...END, exception handler + +-- Script 5 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_category STRING; + DECLARE v_total_reviews INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product review error'); END; + -- Wide, deep, random nested logic + prod_category: BEGIN + DECLARE v_category_count INT; + SET v_category_count = (SELECT COUNT(DISTINCT product_category) FROM products); + FOR cat AS SELECT DISTINCT product_category FROM products LIMIT 3 DO + SET v_category = cat.product_category; + SET v_total_reviews = (SELECT SUM(product_reviews) FROM products WHERE product_category = cat.product_category); + IF v_total_reviews > 0 THEN + L1: BEGIN + DECLARE v_average_rating DOUBLE; + SET v_average_rating = (SELECT AVG(product_rating) FROM products WHERE product_category = cat.product_category); + BEGIN + DECLARE v_price_range DOUBLE; + SET v_price_range = (SELECT MAX(product_price) - MIN(product_price) FROM products WHERE product_category = cat.product_category); + IF v_average_rating > 4.5 AND v_price_range > 50 THEN + L2: BEGIN + DECLARE v_updated_products INT DEFAULT 0; + FOR prod AS SELECT product_id FROM products WHERE product_category = cat.product_category LIMIT 2 DO + UPDATE products SET product_price = product_price * 0.95, product_description = CONCAT('***Premium*** ', product_description) WHERE product_id = prod.product_id; + SET v_updated_products = v_updated_products + 1; + END FOR; + END L2; + ELSE + BEGIN + DECLARE v_new_product_id INT; + SET v_new_product_id = (SELECT COALESCE(MAX(product_id), 0) + 1 FROM products); + INSERT INTO products VALUES (v_new_product_id, 'New ' || v_category, v_category, 49.99, 39.99, 2, 'Widgets Co', 'Sales', '123 Widget St', 30, 'Black', 'Medium', 1.5, 'New arrival', 5.0, 0, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, true, 0.0, 0.19); + END; + END IF; + END; + END L1; + ELSE + L3: BEGIN + DECLARE v_fake_reviews INT DEFAULT 0; + REPEAT + UPDATE products SET product_reviews = product_reviews + 5, product_rating = LEAST(product_rating + 0.1, 5.0) WHERE product_category = cat.product_category AND product_reviews < 10; + SET v_fake_reviews = v_fake_reviews + 1; + UNTIL v_fake_reviews > 2 END REPEAT; + END L3; + END IF; + END FOR; + END prod_category; + BEGIN + DECLARE v_total_product_types INT; + SET v_total_product_types = (SELECT COUNT(DISTINCT product_name) FROM products); + IF v_total_product_types < 10 THEN + L4: BEGIN + DECLARE v_missing_color STRING; + SET v_missing_color = 'Red'; + IF NOT EXISTS (SELECT 1 FROM products WHERE product_color = v_missing_color) THEN + INSERT INTO products VALUES ((SELECT COALESCE(MAX(product_id), 0) + 1 FROM products), 'Rare ' || v_missing_color, 'Special', 99.99, 69.99, 1, 'Acme Inc', 'Sales', '123 Rare St', 2, v_missing_color, 'Unique', 2.0, 'Extremely rare', 5.0, 0, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, true, 0.0, 0.21); + END IF; + END L4; + END IF; + END; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, nested-scopes, exception-handler, string-manipulation, arithmetic-logic +-- EXPECTED: Random product updates, inserts, and deletes; fake reviews if needed; checks for missing colors +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 6 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_hq_state STRING DEFAULT 'CA'; + DECLARE v_regional_office_count INT DEFAULT 0; + DECLARE v_wrong_city_found BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Office location error'); END; + + -- Wide, deep, random logic with labels + main_office: BEGIN + DECLARE v_total_offices INT; + SET v_total_offices = (SELECT COUNT(DISTINCT customer_city) FROM customers); + FOR city AS SELECT DISTINCT customer_city FROM customers LIMIT 2 DO + SET v_wrong_city_found = true; + IF city.customer_city LIKE '%ville' THEN + SET v_wrong_city_found = false; + L1: BEGIN + DECLARE v_region_check BOOLEAN DEFAULT true; + FOR supplier_region AS SELECT supplier_region FROM suppliers WHERE supplier_region LIKE '%est%' LIMIT 1 DO + IF supplier_region IS NULL THEN + SET v_region_check = false; + END IF; + END FOR; + IF NOT v_region_check THEN + INSERT INTO suppliers ( + supplier_id, supplier_name, supplier_contact, supplier_contact_role, + supplier_contact_email, supplier_contact_phone_1, supplier_address_1, + supplier_city, supplier_state, supplier_zip, supplier_country, supplier_region + ) VALUES ( + (SELECT MAX(supplier_id) + 1 FROM suppliers), + 'Regional Supplier', + 'Regional Contact', + 'Regional Manager', + 'region@supplier.com', + '555-1212', + '123 Regional St', + city.customer_city, + 'CA', + '00001', + 'USA', + 'West' + ); + END IF; + END L1; + SET v_regional_office_count = v_regional_office_count + 1; + END IF; + END FOR; + END main_office; + BEGIN + DECLARE v_hq_exists BOOLEAN; + SET v_hq_exists = (SELECT COUNT(*) FROM suppliers WHERE supplier_state = v_hq_state); + IF NOT v_hq_exists OR v_wrong_city_found THEN + L2: BEGIN + DECLARE v_emp_in_city INT; + SET v_emp_in_city = (SELECT COUNT(*) FROM employees WHERE employee_state = v_hq_state AND employee_city LIKE '%town%'); + IF v_emp_in_city > 0 THEN + REPEAT + INSERT INTO suppliers ( + supplier_id, supplier_name, supplier_contact, supplier_contact_role, + supplier_contact_email, supplier_contact_phone_1, supplier_address_1, + supplier_city, supplier_state, supplier_zip, supplier_country, supplier_region, supplier_active + ) VALUES ( + (SELECT MAX(supplier_id) + 1 FROM suppliers), + 'Main Office Supplier', + 'HQ Contact', + 'HQ Manager', + 'hq@supplier.com', + '555-1111', + '123 Main St', + (SELECT employee_city FROM employees WHERE employee_state = v_hq_state LIMIT 1), + v_hq_state, + '00000', + 'USA', + 'HQ', + true + ); + SET v_hq_exists = (SELECT COUNT(*) FROM suppliers WHERE supplier_state = v_hq_state); + UNTIL v_hq_exists = 0 OR v_hq_exists > 2 END REPEAT; + END IF; + END L2; + END IF; + END; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, geo-logic +-- EXPECTED: Random supplier inserts based on city, region, and state logic +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 7 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_total_orders INT DEFAULT 0; + DECLARE v_order_counter INT DEFAULT 0; + DECLARE v_order_status_count INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order status analysis error'); END; + + -- Wide, deep, random nesting, labels + BEGIN + DECLARE v_limit_orders INT DEFAULT 3; + FOR status AS SELECT DISTINCT order_status FROM orders LIMIT 2 DO + SET v_order_counter = (SELECT COUNT(*) FROM orders WHERE order_status = status.order_status); + IF v_order_counter > 0 THEN + L1: BEGIN + DECLARE v_avg_order_total DOUBLE; + SET v_avg_order_total = (SELECT AVG(order_total) FROM orders WHERE order_status = status.order_status); + IF v_avg_order_total > 100 THEN + L2: BEGIN + DECLARE v_order_tax_avg DOUBLE; + SET v_order_tax_avg = (SELECT AVG(order_tax) FROM orders WHERE order_status = status.order_status); + IF v_order_tax_avg > 10 THEN + REPEAT + UPDATE orders SET order_tax = order_tax * 0.95 WHERE order_status = status.order_status; + SET v_order_tax_avg = (SELECT AVG(order_tax) FROM orders WHERE order_status = status.order_status); + UNTIL v_order_tax_avg <= 10 END REPEAT; + END IF; + SET v_limit_orders = v_limit_orders + 1; + END L2; + ELSE + BEGIN + DECLARE v_new_order_id INT; + SET v_new_order_id = (SELECT COALESCE(MAX(order_id), 0) + 1 FROM orders); + INSERT INTO orders ( + order_id, customer_id, order_date, order_status, order_total, order_tax, order_discount, order_shipping + ) VALUES ( + v_new_order_id, + (SELECT MAX(customer_id) FROM customers), + CURRENT_TIMESTAMP, + status.order_status, + 100.0, + 10.0, + 0.0, + 2.0 + ); + SET v_limit_orders = v_limit_orders - 1; + END; + END IF; + END L1; + END IF; + SET v_order_status_count = v_order_status_count + 1; + END FOR; + WHILE v_order_status_count < 3 DO + BEGIN + DECLARE v_fake_status STRING; + SET v_fake_status = CONCAT('Fake_Status_', v_order_status_count); + INSERT INTO orders ( + order_id, customer_id, order_date, order_status, order_total, order_tax, order_discount, order_shipping + ) VALUES ( + (SELECT COALESCE(MAX(order_id), 0) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + v_fake_status, + 10.0, + 1.0, + 0.0, + 2.0 + ); + SET v_order_status_count = v_order_status_count + 1; + END; + END WHILE; + END; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, WHILE, REPEAT, DML, deep-nesting, exception-handler, order-status-logic +-- EXPECTED: Random order status updates, inserts, and status logic +-- EXECUTES: FOR, IF, WHILE, REPEAT, nested BEGIN...END, exception handler + +-- Script 8 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_supplier_id INT; + DECLARE v_supplier_active BOOLEAN; + DECLARE v_contact_orders INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier contact management error'); END; + + -- Wide, deep, random logic, labels + supplier_loop: FOR supplier AS SELECT supplier_id, supplier_active, supplier_contact FROM suppliers LIMIT 3 DO + SET v_supplier_id = supplier.supplier_id; + SET v_supplier_active = supplier.supplier_active; + IF v_supplier_active THEN + BEGIN + DECLARE v_contact_has_orders BOOLEAN DEFAULT false; + SET v_contact_orders = (SELECT COUNT(*) FROM products WHERE supplier_id = v_supplier_id); + IF v_contact_orders > 0 THEN + SET v_contact_has_orders = true; + L1: BEGIN + DECLARE v_new_product_id INT; + SET v_new_product_id = (SELECT COALESCE(MAX(product_id), 0) + 1 FROM products); + INSERT INTO products VALUES ( + v_new_product_id, + 'Supplementary Item', + 'Accessories', + 19.99, + 12.99, + v_supplier_id, + supplier.supplier_contact, + supplier.supplier_contact, + 'Extra St', + 10, + 'Black', + 'Medium', + 1.2, + 'Supplementary product', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + BEGIN + DECLARE v_days_since_last_order INT; + SET v_days_since_last_order = DATEDIFF(DAY, (SELECT MAX(product_launch_date) FROM products WHERE supplier_id = v_supplier_id), CURRENT_TIMESTAMP); + IF v_days_since_last_order > 30 THEN + L2: BEGIN + DECLARE v_temp_id INT; + REPEAT + SET v_temp_id = (SELECT MIN(supplier_id) FROM suppliers WHERE supplier_active = true AND supplier_id != v_supplier_id); + IF v_temp_id IS NOT NULL THEN + UPDATE products SET supplier_id = v_temp_id WHERE product_id = v_new_product_id; + END IF; + UNTIL v_temp_id IS NULL OR v_days_since_last_order < 20 END REPEAT; + END L2; + END IF; + END; + END L1; + ELSE + L3: BEGIN + DECLARE v_supplier_emails INT; + SET v_supplier_emails = (SELECT COUNT(*) FROM suppliers WHERE supplier_contact_email IS NOT NULL AND supplier_id = v_supplier_id); + IF v_supplier_emails = 0 THEN + BEGIN + DECLARE v_fake_email STRING; + SET v_fake_email = CONCAT(supplier.supplier_contact, '@fake.com'); + INSERT INTO customers ( + customer_id, customer_name, customer_email, customer_phone, + customer_address_1, customer_city, customer_state, customer_zip, + customer_country, customer_active_status + ) VALUES ( + v_supplier_id + 9000, + supplier.supplier_contact, + v_fake_email, + '555-7777', + '123 Fake St', + 'Fakeville', + 'CA', + '00000', + 'USA', + false + ); + END; + END IF; + END L3; + END IF; + BEGIN + DECLARE v_orders_with_supplier INT; + SET v_orders_with_supplier = (SELECT COUNT(*) FROM order_items oi JOIN products p ON oi.product_id = p.product_id WHERE p.supplier_id = v_supplier_id); + IF v_orders_with_supplier > 0 THEN + L4: BEGIN + DECLARE v_total_value DOUBLE; + SET v_total_value = (SELECT SUM(oi.item_total) FROM order_items oi JOIN products p ON oi.product_id = p.product_id WHERE p.supplier_id = v_supplier_id); + IF v_total_value > 200 THEN + BEGIN + DECLARE v_new_discount DOUBLE; + SET v_new_discount = CASE WHEN v_total_value < 500 THEN 0.05 ELSE 0.10 END; + UPDATE suppliers SET supplier_rating = supplier_rating + 0.1 WHERE supplier_id = v_supplier_id; + UPDATE products SET product_discount = product_discount + v_new_discount WHERE supplier_id = v_supplier_id; + END; + END IF; + END L4; + END IF; + END; + END; + ELSE + L5: BEGIN + DECLARE v_inactive_supplier_orders INT; + SET v_inactive_supplier_orders = (SELECT COUNT(*) FROM products p JOIN order_items oi ON p.product_id = oi.product_id WHERE p.supplier_id = v_supplier_id); + IF v_inactive_supplier_orders > 0 THEN + REPEAT + DELETE FROM order_items + WHERE order_item_id IN ( + SELECT oi.order_item_id + FROM order_items oi + JOIN products p ON oi.product_id = p.product_id + WHERE p.supplier_id = v_supplier_id + LIMIT 1 + ); + SET v_inactive_supplier_orders = v_inactive_supplier_orders - 1; + UNTIL v_inactive_supplier_orders = 0 END REPEAT; + END IF; + END L5; + END IF; + END FOR supplier_loop; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, supplier-management +-- EXPECTED: Random product inserts, supplier updates, order item deletes, and discount logic +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 9 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_employee_id INT; + DECLARE v_employee_commission DOUBLE; + DECLARE v_employee_total DOUBLE DEFAULT 0.0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Commission calculation error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_total_emp INT; + SET v_total_emp = (SELECT COUNT(*) FROM employees); + FOR emp AS SELECT employee_id, employee_commission FROM employees LIMIT 3 DO + SET v_employee_id = emp.employee_id; + SET v_employee_commission = emp.employee_commission; + L1: BEGIN + DECLARE v_order_count INT; + SET v_order_count = (SELECT COUNT(*) FROM orders WHERE customer_id = (SELECT MIN(customer_id) FROM customers)); + IF v_order_count > 0 THEN + L2: BEGIN + DECLARE v_commission_changed BOOLEAN DEFAULT false; + WHILE v_employee_commission > 0 AND v_employee_commission < 2000 DO + UPDATE employees SET employee_commission = employee_commission + 100.0 WHERE employee_id = v_employee_id; + SET v_employee_total = v_employee_total + 100.0; + SET v_employee_commission = (SELECT employee_commission FROM employees WHERE employee_id = v_employee_id); + SET v_commission_changed = true; + END WHILE; + IF v_commission_changed THEN + REPEAT + SET v_employee_total = v_employee_total - 50.0; + UPDATE employees SET employee_commission = employee_commission - 50.0 WHERE employee_id = v_employee_id; + UNTIL v_employee_total <= 1500 END REPEAT; + END IF; + END L2; + END IF; + END L1; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, WHILE, REPEAT, DML, deep-nesting, exception-handler, commission-logic +-- EXPECTED: Random commission updates based on order logic +-- EXECUTES: FOR, IF, WHILE, REPEAT, nested BEGIN...END, exception handler + +-- Script 10 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_customer_category STRING; + DECLARE v_order_count INT DEFAULT 0; + DECLARE v_customer_total DOUBLE DEFAULT 0.0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Customer order calculation error'); END; + + -- Wide, deep, random logic, labels + customer_category_loop: FOR category AS SELECT DISTINCT customer_type FROM customers LIMIT 2 DO + SET v_customer_category = category.customer_type; + SET v_order_count = (SELECT COUNT(*) FROM orders o JOIN customers c ON o.customer_id = c.customer_id WHERE c.customer_type = v_customer_category); + IF v_order_count > 0 THEN + L1: BEGIN + DECLARE v_average_order DOUBLE; + SET v_average_order = (SELECT AVG(o.order_total) FROM orders o JOIN customers c ON o.customer_id = c.customer_id WHERE c.customer_type = v_customer_category); + L2: BEGIN + IF v_average_order > 100 THEN + SET v_customer_total = v_customer_total + v_average_order; + BEGIN + DECLARE v_order_limit INT DEFAULT 3; + FOR order_row AS SELECT o.order_id FROM orders o JOIN customers c ON o.customer_id = c.customer_id WHERE c.customer_type = v_customer_category LIMIT v_order_limit DO + BEGIN + DECLARE v_order_items_count INT; + SET v_order_items_count = (SELECT COUNT(*) FROM order_items WHERE order_id = order_row.order_id); + IF v_order_items_count < 1 THEN + BEGIN + REPEAT + INSERT INTO order_items (order_item_id, order_id, product_id, item_quantity, item_price_per_unit, item_discount, item_tax, item_total) + VALUES ((SELECT MAX(order_item_id) + 1 FROM order_items), order_row.order_id, (SELECT MIN(product_id) FROM products), 1, 10.0, 0.0, 1.0, 11.0); + SET v_order_items_count = v_order_items_count + 1; + UNTIL v_order_items_count >= 1 END REPEAT; + END; + END IF; + END; + END FOR; + END; + ELSE + L3: BEGIN + REPEAT + SET v_customer_total = v_customer_total + 10.0; + INSERT INTO orders (order_id, customer_id, order_date, order_status, order_total, order_tax, order_discount, order_shipping) + VALUES ((SELECT MAX(order_id) + 1 FROM orders), (SELECT MIN(customer_id) FROM customers WHERE customer_type = v_customer_category), CURRENT_TIMESTAMP, 'Low Value', 10.0, 1.0, 0.0, 2.0); + SET v_order_count = v_order_count + 1; + UNTIL v_customer_total > 100 END REPEAT; + END L3; + END IF; + END L2; + END L1; + END IF; + END FOR customer_category_loop; + L4: BEGIN + DECLARE v_min_orders INT DEFAULT 1; + IF v_order_count < v_min_orders THEN + BEGIN + DECLARE v_new_order_id INT; + SET v_new_order_id = (SELECT MAX(order_id) + 1 FROM orders); + INSERT INTO orders (order_id, customer_id, order_date, order_status, order_total, order_tax, order_discount, order_shipping) + VALUES (v_new_order_id, (SELECT MIN(customer_id) FROM customers), CURRENT_TIMESTAMP, 'Auto Insert', 15.0, 1.5, 0.0, 2.5); + END; + END IF; + END L4; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, customer-logic +-- EXPECTED: Random order/item inserts, conditional logic on customer types +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 11 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_max_manager_id INT DEFAULT 2; + DECLARE v_employee_count INT DEFAULT 0; + DECLARE v_department_levels INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Employee hierarchy error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_manager_exists BOOLEAN DEFAULT false; + WHILE v_manager_exists = false AND v_max_manager_id < 4 DO + SET v_manager_exists = (SELECT COUNT(*) > 0 FROM employees WHERE employee_manager_id = v_max_manager_id); + IF v_manager_exists THEN + L1: BEGIN + REPEAT + SET v_department_levels = v_department_levels + 1; + SET v_employee_count = (SELECT COUNT(*) FROM employees WHERE employee_manager_id = v_max_manager_id); + WHILE v_employee_count > 0 AND v_employee_count < 10 DO + BEGIN + DECLARE v_new_id INT; + SET v_new_id = (SELECT COALESCE(MAX(employee_id), 0) + 1 FROM employees); + INSERT INTO employees VALUES (v_new_id, 'New Emp ' || v_new_id, 'new' || v_new_id || '@company.com', '555-0000', 'Intern', 'Ops', CURRENT_TIMESTAMP, NULL, 30000.0, 0.0, v_max_manager_id, '123 New St', NULL, 'Newtown', 'CA', '00000', 'USA', CURRENT_TIMESTAMP, 'Male', 'Single', 0); + SET v_employee_count = v_employee_count + 1; + END; + END WHILE; + SET v_max_manager_id = v_max_manager_id + 1; + SET v_manager_exists = (SELECT COUNT(*) > 0 FROM employees WHERE employee_manager_id = v_max_manager_id); + UNTIL v_max_manager_id >= 4 OR v_department_levels > 2 END REPEAT; + END L1; + ELSE + BEGIN + DECLARE v_temp_id INT; + SET v_temp_id = v_max_manager_id + 1; + INSERT INTO employees VALUES (v_temp_id, 'Manager ' || v_temp_id, 'manager' || v_temp_id || '@company.com', '555-0000', 'Manager', 'HR', CURRENT_TIMESTAMP, NULL, 60000.0, 0.0, NULL, '123 Mgmt St', NULL, 'Newtown', 'CA', '00000', 'USA', CURRENT_TIMESTAMP, 'Male', 'Married', 1); + SET v_manager_exists = true; + SET v_max_manager_id = v_temp_id; + END; + END IF; + END WHILE; + END L0; + L2: BEGIN + DECLARE v_low_level_emp INT DEFAULT 0; + REPEAT + SET v_low_level_emp = v_low_level_emp + 1; + INSERT INTO employees VALUES (v_low_level_emp + 10, 'Temp Emp ' || v_low_level_emp, 'temp' || v_low_level_emp || '@company.com', '555-0000', 'Temp', 'Temp', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 20000.0, 0.0, NULL, '123 Temp St', NULL, 'Temp City', 'TX', '00000', 'USA', CURRENT_TIMESTAMP, 'Female', 'Single', 0); + UNTIL v_low_level_emp > 2 END REPEAT; + END L2; +END; +--QUERY-DELIMITER-END +-- TAGS: WHILE, REPEAT, IF, DML, deep-nesting, exception-handler, employee-management +-- EXPECTED: Random employee inserts, hierarchy construction, loop termination +-- EXECUTES: WHILE, REPEAT, IF, nested BEGIN...END, exception handler + +-- Script 12 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_shipping_cost DOUBLE DEFAULT 0.0; + DECLARE v_shipping_city STRING; + DECLARE v_shipping_orders INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Shipping analysis error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_max_orders INT DEFAULT 3; + FOR city AS SELECT DISTINCT order_shipping_city FROM orders LIMIT 2 DO + SET v_shipping_city = city.order_shipping_city; + SET v_shipping_cost = (SELECT SUM(order_shipping) FROM orders WHERE order_shipping_city = v_shipping_city); + IF v_shipping_cost > 5 THEN + L1: BEGIN + REPEAT + SET v_shipping_cost = v_shipping_cost - 1.0; + UPDATE orders SET order_shipping = order_shipping - 0.5 WHERE order_shipping_city = v_shipping_city; + UNTIL v_shipping_cost < 5 END REPEAT; + END L1; + BEGIN + DECLARE v_customer_in_shipping_city INT; + SET v_customer_in_shipping_city = (SELECT COUNT(*) FROM customers c WHERE c.customer_city = v_shipping_city); + IF v_customer_in_shipping_city = 0 THEN + BEGIN + DECLARE v_new_customer_id INT; + SET v_new_customer_id = (SELECT MAX(customer_id) + 1 FROM customers); + INSERT INTO customers VALUES ( + v_new_customer_id, + 'Local Customer', + 'local@' || v_shipping_city || '.com', + '555-0000', + '123 Main St', + v_shipping_city, + (SELECT DISTINCT order_shipping_state FROM orders WHERE order_shipping_city = v_shipping_city LIMIT 1), + '00000', + 'USA', + 'Retail', + CURRENT_TIMESTAMP, 0.0, NULL, NULL, NULL, true, true, 0.0, NULL, NULL + ); + END; + END IF; + END; + ELSE + L2: BEGIN + SET v_shipment_orders = (SELECT COUNT(*) FROM orders WHERE order_shipping_city = v_shipping_city); + WHILE v_shipping_orders < v_max_orders DO + BEGIN + DECLARE v_new_order_id INT; + SET v_new_order_id = (SELECT MAX(order_id) + 1 FROM orders); + INSERT INTO orders ( + order_id, customer_id, order_date, order_status, order_total, + order_tax, order_discount, order_shipping, order_shipping_city, + order_shipping_state, order_shipping_zip, order_shipping_country + ) VALUES ( + v_new_order_id, + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, 'Local Insert', 10.0, 1.0, 0.0, 2.0, + v_shipping_city, 'TX', '00000', 'USA' + ); + SET v_shipping_orders = v_shipping_orders + 1; + END; + END WHILE; + END L2; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, WHILE, DML, deep-nesting, exception-handler, shipping-logic +-- EXPECTED: Random shipping cost adjustments, customer/order inserts for local cities +-- EXECUTES: FOR, IF, REPEAT, WHILE, nested BEGIN...END, exception handler + +-- Script 13 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_supplier_contact_count INT DEFAULT 0; + DECLARE v_supplier_rating_change DOUBLE DEFAULT 0.0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier contact error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_supplier_count INT; + SET v_supplier_count = (SELECT COUNT(*) FROM suppliers WHERE supplier_active = true); + FOR supplier AS SELECT supplier_id, supplier_contact, supplier_rating FROM suppliers WHERE supplier_active = true LIMIT 2 DO + SET v_supplier_contact_count = v_supplier_contact_count + 1; + L1: BEGIN + DECLARE v_supplier_orders INT; + SET v_supplier_orders = (SELECT COUNT(*) FROM products p JOIN order_items oi ON p.product_id = oi.product_id WHERE p.supplier_id = supplier.supplier_id); + IF v_supplier_orders > 0 THEN + L2: BEGIN + SET v_supplier_rating_change = 0.1; + REPEAT + SET v_supplier_rating_change = v_supplier_rating_change - 0.01; + UPDATE suppliers SET supplier_rating = supplier_rating + v_supplier_rating_change WHERE supplier_id = supplier.supplier_id; + UNTIL v_supplier_rating_change <= 0.0 END REPEAT; + END L2; + ELSE + BEGIN + DECLARE v_new_product_id INT; + SET v_new_product_id = (SELECT MAX(product_id) + 1 FROM products); + INSERT INTO products VALUES ( + v_new_product_id, + 'New Supplier Product', + 'General', + 39.99, + 29.99, + supplier.supplier_id, + supplier.supplier_contact, + supplier.supplier_contact, + '123 New St', + 5, + 'Blue', + 'M', + 0.9, + 'New supplier item', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + WHILE supplier.supplier_rating < 4.5 DO + UPDATE suppliers SET supplier_rating = supplier_rating + 0.1 WHERE supplier_id = supplier.supplier_id; + SET supplier.supplier_rating = (SELECT MAX(supplier_rating) FROM suppliers WHERE supplier_id = supplier.supplier_id); + END WHILE; + END; + END IF; + END L1; + END FOR; + END L0; + BEGIN + DECLARE v_few_contacts BOOLEAN DEFAULT false; + SET v_few_contacts = (v_supplier_contact_count < 2); + IF v_few_contacts THEN + L3: BEGIN + DECLARE v_new_contact_id INT; + SET v_new_contact_id = (SELECT MAX(supplier_id) + 1 FROM suppliers); + INSERT INTO suppliers VALUES ( + v_new_contact_id, + 'Supplier for Contact', + 'Contact', + 'Contact', + 'contact@supplier.com', + '555-0000', + '123 Contact St', + 'Contact City', + 'CA', + '00000', + 'USA', + 'West', + 'Contacts only', + true + ); + SET v_supplier_contact_count = v_supplier_contact_count + 1; + END L3; + END IF; + END; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, WHILE, DML, deep-nesting, exception-handler, supplier-contact-logic +-- EXPECTED: Random supplier rating adjustments, product inserts, supplier contact actions +-- EXECUTES: FOR, IF, REPEAT, WHILE, nested BEGIN...END, exception handler + +-- Script 14 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_employee_hire_year INT; + DECLARE v_employee_tenure_years INT; + DECLARE v_salary_bin INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Tenure analysis error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_emp_count INT DEFAULT 0; + FOR emp AS SELECT employee_id, employee_hire_date, employee_salary FROM employees LIMIT 3 DO + SET v_employee_hire_year = YEAR(emp.employee_hire_date); + SET v_employee_tenure_years = DATEDIFF(YEAR, emp.employee_hire_date, CURRENT_TIMESTAMP); + SET v_salary_bin = FLOOR(emp.employee_salary / 20000.0) + 1; + IF v_employee_tenure_years > 1 AND v_employee_tenure_years <= 7 THEN + L1: BEGIN + CASE v_salary_bin + WHEN 1 THEN + UPDATE employees SET employee_salary = employee_salary * 1.1 WHERE employee_id = emp.employee_id; + WHEN 2 THEN + BEGIN + REPEAT + SET v_salary_bin = v_salary_bin + 1; + SET v_emp_count = v_emp_count + 1; + UPDATE employees SET employee_commission = employee_commission * 1.05 WHERE employee_id = emp.employee_id; + UNTIL v_salary_bin > 3 OR v_emp_count > 2 END REPEAT; + END; + ELSE + L2: BEGIN + DECLARE v_hire_month INT; + SET v_hire_month = MONTH(emp.employee_hire_date); + IF v_hire_month % 2 = 0 THEN + BEGIN + SET v_hire_month = v_hire_month + 1; + UPDATE employees SET employee_salary = employee_salary * 0.95 WHERE employee_id = emp.employee_id; + END; + END IF; + END L2; + END CASE; + END L1; + SET v_emp_count = v_emp_count + 1; + ELSE + L3: BEGIN + DECLARE v_year_diff INT; + SET v_year_diff = (SELECT DATEDIFF(YEAR, MIN(employee_hire_date), CURRENT_TIMESTAMP) FROM employees); + WHILE v_year_diff > 5 DO + SET v_year_diff = v_year_diff - 1; + INSERT INTO employees VALUES ( + (SELECT MAX(employee_id) + 1 FROM employees), + 'Tenure Fill ' || v_year_diff, + 'tenure' || v_year_diff || '@company.com', + '555-0000', + 'Tenure', + 'Tenure', + CURRENT_TIMESTAMP, + NULL, + 35000.0, + 0.0, + NULL, + '123 Tenure St', + NULL, + 'Tenureville', + 'CA', + '00000', + 'USA', + CURRENT_TIMESTAMP, + 'Male', + 'Single', + 0 + ); + END WHILE; + END L3; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, CASE, REPEAT, WHILE, DML, deep-nesting, exception-handler, tenure-logic +-- EXPECTED: Random salary/commission adjustments, employee inserts based on tenure and salary +-- EXECUTES: FOR, IF, CASE, REPEAT, WHILE, nested BEGIN...END, exception handler + +-- Script 15 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_source STRING; + DECLARE v_order_total DOUBLE; + DECLARE v_order_date TIMESTAMP; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order source analysis error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_order_source_count INT DEFAULT 0; + FOR source AS SELECT DISTINCT order_source FROM orders LIMIT 2 DO + SET v_order_source = source.order_source; + SET v_order_total = (SELECT SUM(order_total) FROM orders WHERE order_source = source.order_source); + IF v_order_source = 'Web' OR v_order_source = 'Mobile' THEN + L1: BEGIN + REPEAT + SET v_order_source_count = v_order_source_count + 1; + SET v_order_date = (SELECT MAX(order_date) FROM orders WHERE order_source = source.order_source); + IF v_order_date < DATEADD(DAY, -30, CURRENT_TIMESTAMP) THEN + BEGIN + INSERT INTO orders ( + order_id, customer_id, order_date, order_status, order_total, + order_tax, order_discount, order_shipping, order_source + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Recent Web', + 50.0, + 5.0, + 0.0, + 5.0, + source.order_source + ); + SET v_order_date = CURRENT_TIMESTAMP; + END; + END IF; + UNTIL v_order_source_count > 1 OR v_order_date > DATEADD(DAY, -30, CURRENT_TIMESTAMP) END REPEAT; + END L1; + ELSE + BEGIN + DECLARE v_fake_source STRING DEFAULT CONCAT('Fake ', source.order_source); + INSERT INTO orders ( + order_id, customer_id, order_date, order_status, order_total, + order_tax, order_discount, order_shipping, order_source + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Generated', + 30.0, + 3.0, + 0.0, + 3.0, + v_fake_source + ); + END; + END IF; + END FOR; + END L0; + BEGIN + DECLARE v_source_total DOUBLE; + SET v_source_total = (SELECT SUM(order_total) FROM orders WHERE order_source LIKE 'Fake%'); + IF v_source_total < 100 THEN + REPEAT + INSERT INTO orders ( + order_id, customer_id, order_date, order_status, order_total, + order_tax, order_discount, order_shipping, order_source + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Fake Source', + 15.0, + 1.5, + 0.0, + 1.5, + 'Fake Source' + ); + SET v_source_total = (SELECT SUM(order_total) FROM orders WHERE order_source LIKE 'Fake%'); + UNTIL v_source_total >= 100 END REPEAT; + END IF; + END; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, source-analysis +-- EXPECTED: Random order inserts, source analysis, fake order generation +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 16 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_customer_active BOOLEAN; + DECLARE v_customer_lifetime_value DOUBLE DEFAULT 0.0; + DECLARE v_customer_order_count INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Customer profitability error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_target_value DOUBLE DEFAULT 500.0; + FOR cust AS SELECT customer_id, customer_active_status FROM customers LIMIT 3 DO + SET v_customer_active = cust.customer_active_status; + SET v_customer_lifetime_value = (SELECT SUM(order_total) FROM orders WHERE customer_id = cust.customer_id); + SET v_customer_order_count = (SELECT COUNT(*) FROM orders WHERE customer_id = cust.customer_id); + IF v_customer_active = true AND v_customer_lifetime_value > 0.0 THEN + L1: BEGIN + IF v_customer_lifetime_value < v_target_value THEN + L2: BEGIN + REPEAT + INSERT INTO orders ( + order_id, customer_id, order_date, order_status, + order_total, order_tax, order_discount, order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + cust.customer_id, + CURRENT_TIMESTAMP, + 'LTV Boost', + 40.0, + 4.0, + 0.0, + 4.0 + ); + SET v_customer_lifetime_value = (SELECT SUM(order_total) FROM orders WHERE customer_id = cust.customer_id); + UNTIL v_customer_lifetime_value >= v_target_value OR v_customer_order_count > 5 END REPEAT; + END L2; + END IF; + BEGIN + DECLARE v_discount_to_apply DOUBLE; + CASE v_customer_order_count + WHEN 1 THEN SET v_discount_to_apply = 0.10; + WHEN 2 THEN SET v_discount_to_apply = 0.05; + ELSE SET v_discount_to_apply = 0.0; + END CASE; + IF v_discount_to_apply > 0 THEN + L3: BEGIN + REPEAT + UPDATE customers SET customer_discount_percentage = v_discount_to_apply WHERE customer_id = cust.customer_id; + SET v_discount_to_apply = v_discount_to_apply - 0.01; + UNTIL v_discount_to_apply <= 0.0 END REPEAT; + END L3; + END IF; + END; + END L1; + ELSE + BEGIN + DECLARE v_inactive_customer_count INT; + SET v_inactive_customer_count = (SELECT COUNT(*) FROM customers WHERE customer_active_status = false); + IF v_inactive_customer_count > 0 THEN + L4: BEGIN + WHILE v_inactive_customer_count > 0 AND v_customer_lifetime_value < 200 DO + SET v_inactive_customer_count = v_inactive_customer_count - 1; + INSERT INTO orders ( + order_id, customer_id, order_date, order_status, + order_total, order_tax, order_discount, order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers WHERE customer_active_status = false), + CURRENT_TIMESTAMP, + 'Reactivation', + 20.0, + 2.0, + 0.0, + 2.0 + ); + SET v_customer_lifetime_value = (SELECT SUM(order_total) FROM orders WHERE customer_id = cust.customer_id); + END WHILE; + END L4; + END IF; + END; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, CASE, REPEAT, WHILE, DML, deep-nesting, exception-handler, customer-lifecycle +-- EXPECTED: Random order inserts, discount updates, customer lifecycle manipulation +-- EXECUTES: FOR, IF, CASE, REPEAT, WHILE, nested BEGIN...END, exception handler + +-- Script 17 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_supplier_region_count INT DEFAULT 0; + DECLARE v_supplier_rating_change DOUBLE DEFAULT 0.0; + DECLARE v_region_to_boost STRING; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier region analysis error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_min_supplier_count INT DEFAULT 2; + FOR region AS SELECT DISTINCT supplier_region FROM suppliers LIMIT 2 DO + SET v_region_to_boost = region.supplier_region; + SET v_supplier_region_count = (SELECT COUNT(*) FROM suppliers WHERE supplier_region = v_region_to_boost); + IF v_supplier_region_count > v_min_supplier_count THEN + L1: BEGIN + REPEAT + SET v_supplier_rating_change = 0.05; + REPEAT + UPDATE suppliers SET supplier_rating = supplier_rating + v_supplier_rating_change WHERE supplier_region = v_region_to_boost; + SET v_supplier_rating_change = v_supplier_rating_change - 0.01; + UNTIL v_supplier_rating_change <= 0.0 END REPEAT; + SET v_min_supplier_count = v_min_supplier_count + 1; + UNTIL v_min_supplier_count > 4 END REPEAT; + END L1; + BEGIN + DECLARE v_products_in_region INT; + SET v_products_in_region = (SELECT COUNT(*) FROM products p JOIN suppliers s ON p.supplier_id = s.supplier_id WHERE s.supplier_region = v_region_to_boost); + IF v_products_in_region < 3 THEN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Region Product', + 'General', + 39.99, + 29.99, + (SELECT MIN(supplier_id) FROM suppliers WHERE supplier_region = v_region_to_boost), + 'Region Contact', + 'Region Role', + '123 Main St', + 10, + 'Blue', + 'M', + 1.0, + 'Region product', + 3.5, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + UNTIL (SELECT COUNT(*) FROM products p JOIN suppliers s ON p.supplier_id = s.supplier_id WHERE s.supplier_region = v_region_to_boost) >= 3 END REPEAT; + END IF; + END; + ELSE + L2: BEGIN + DECLARE v_new_supplier_id INT; + SET v_new_supplier_id = (SELECT MAX(supplier_id) + 1 FROM suppliers); + INSERT INTO suppliers VALUES ( + v_new_supplier_id, + 'Region ' || v_region_to_boost, + 'Regional Contact', + 'Regional Contact', + 'contact@regional.com', + '555-0000', + '123 Regional St', + 'Regional City', + 'CA', + '00000', + 'USA', + v_region_to_boost, + 'Regional', + true + ); + SET v_supplier_region_count = v_supplier_region_count + 1; + END L2; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, region-analysis +-- EXPECTED: Random supplier rating updates, product inserts, supplier inserts as needed +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 18 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_employee_birth_year INT; + DECLARE v_employee_age INT; + DECLARE v_employee_city STRING; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Employee demographics error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_emp_count INT DEFAULT 0; + FOR emp AS SELECT employee_id, employee_birth_date, employee_city FROM employees LIMIT 3 DO + SET v_employee_birth_year = YEAR(emp.employee_birth_date); + SET v_employee_age = DATEDIFF(YEAR, emp.employee_birth_date, CURRENT_TIMESTAMP); + SET v_employee_city = emp.employee_city; + IF v_employee_age < 30 THEN + L1: BEGIN + DECLARE v_city_emp_count INT; + SET v_city_emp_count = (SELECT COUNT(*) FROM employees WHERE employee_city = v_employee_city); + IF v_city_emp_count < 2 THEN + REPEAT + SET v_emp_count = v_emp_count + 1; + INSERT INTO employees VALUES ( + (SELECT MAX(employee_id) + 1 FROM employees), + 'Young Emp ' || v_emp_count, + 'emp' || v_emp_count || '@company.com', + '555-0000', + 'Junior', + 'Ops', + CURRENT_TIMESTAMP, + NULL, + 35000.0, + 0.0, + NULL, + '123 Jun St', + NULL, + v_employee_city, + (SELECT DISTINCT employee_state FROM employees WHERE employee_city = v_employee_city LIMIT 1), + '00000', + 'USA', + DATEADD(YEAR, -(FLOOR(RAND() * 10) + 20), CURRENT_TIMESTAMP), + 'Male', + 'Single', + 0 + ); + UNTIL v_emp_count > 1 END REPEAT; + END IF; + END L1; + ELSE + BEGIN + DECLARE v_birth_month INT; + SET v_birth_month = MONTH(emp.employee_birth_date); + CASE v_birth_month + WHEN 1 THEN + UPDATE employees SET employee_commission = employee_commission + 100.0 WHERE employee_id = emp.employee_id; + WHEN 6 THEN + BEGIN + WHILE v_employee_age < 40 DO + SET v_employee_age = v_employee_age + 1; + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Age Group Customer', + 'age@group.com', + '555-0001', + '123 Age St', + v_employee_city, + (SELECT DISTINCT employee_state FROM employees WHERE employee_city = v_employee_city LIMIT 1), + '00000', + 'USA', + 'Senior', + CURRENT_TIMESTAMP, + 0.0, + NULL, + NULL, + NULL, + true, + true, + 0.0, + NULL, + NULL + ); + END WHILE; + END; + ELSE + L2: BEGIN + DECLARE v_new_birth_year INT; + SET v_new_birth_year = v_employee_birth_year - (FLOOR(RAND() * 5) + 1); + INSERT INTO employees VALUES ( + (SELECT MAX(employee_id) + 1 FROM employees), + 'Filler Emp', + 'filler@company.com', + '555-0000', + 'Filler', + 'Ops', + CURRENT_TIMESTAMP, + NULL, + 30000.0, + 0.0, + NULL, + '123 Filler St', + NULL, + v_employee_city, + (SELECT DISTINCT employee_state FROM employees WHERE employee_city = v_employee_city LIMIT 1), + '00000', + 'USA', + MAKE_DATE(v_new_birth_year, MONTH(CURRENT_TIMESTAMP), DAY(CURRENT_TIMESTAMP)), + 'Female', + 'Single', + 0 + ); + END L2; + END CASE; + END; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, CASE, REPEAT, WHILE, DML, deep-nesting, exception-handler, demographics +-- EXPECTED: Random employee/customer inserts, commission updates, age-based logic +-- EXECUTES: FOR, IF, CASE, REPEAT, WHILE, nested BEGIN...END, exception handlers + +-- Script 19 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_product_launch_year INT; + DECLARE v_active_product_count INT DEFAULT 0; + DECLARE v_new_composite_id INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product cohort error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + FOR product AS SELECT product_id, product_launch_date, product_name, product_is_active FROM products LIMIT 3 DO + SET v_product_launch_year = YEAR(product.product_launch_date); + L1: BEGIN + IF product.product_is_active = true THEN + SET v_active_product_count = v_active_product_count + 1; + IF v_product_launch_year < 2023 THEN + L2: BEGIN + REPEAT + SET v_new_composite_id = product.product_id * 100 + (SELECT COUNT(*) FROM products WHERE YEAR(product_launch_date) = v_product_launch_year); + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total + ) VALUES ( + v_new_composite_id, + (SELECT MIN(order_id) FROM orders), + product.product_id, + 1, + (SELECT product_price FROM products WHERE product_id = product.product_id), + 0.0, + 0.0, + (SELECT product_price FROM products WHERE product_id = product.product_id) + ); + SET v_active_product_count = v_active_product_count - 1; + UNTIL v_active_product_count < 1 END REPEAT; + END L2; + END IF; + ELSE + BEGIN + DECLARE v_launch_month INT; + SET v_launch_month = MONTH(product.product_launch_date); + WHILE v_launch_month < 12 DO + SET v_launch_month = v_launch_month + 1; + BEGIN + DECLARE v_new_product_id INT; + SET v_new_product_id = (SELECT MAX(product_id) + 1 FROM products); + INSERT INTO products VALUES ( + v_new_product_id, + 'Covert ' || product.product_name, + 'Specialty', + 49.99, + 34.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Stealth Contact', + 'Cloaked Role', + '123 Cloak St', + 2, + 'Black', + 'Medium', + 1.1, + 'Hidden product', + 0.0, + 0, + MAKE_DATE(v_product_launch_year, v_launch_month, 1), + CURRENT_TIMESTAMP, + true, + 0.0, + 0.21 + ); + END; + END WHILE; + END; + END IF; + END L1; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, WHILE, DML, deep-nesting, exception-handler, product-cohort +-- EXPECTED: Random order item and product inserts, launch cohort logic +-- EXECUTES: FOR, IF, REPEAT, WHILE, nested BEGIN...END, exception handler + +-- Script 20 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_product_cost_change DOUBLE DEFAULT 0.0; + DECLARE v_last_update_days INT; + DECLARE v_product_is_active BOOLEAN; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Cost adjustment error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + FOR product AS SELECT product_id, product_cost, product_last_update, product_is_active FROM products LIMIT 3 DO + SET v_last_update_days = DATEDIFF(DAY, product.product_last_update, CURRENT_TIMESTAMP); + SET v_product_is_active = product.product_is_active; + L1: BEGIN + IF v_product_is_active = true AND v_last_update_days > 60 THEN + L2: BEGIN + REPEAT + SET v_product_cost_change = v_product_cost_change + 0.05; + UPDATE products SET product_cost = product_cost * (1.0 + v_product_cost_change), product_last_update = CURRENT_TIMESTAMP WHERE product_id = product.product_id; + SET v_last_update_days = DATEDIFF(DAY, product.product_last_update, CURRENT_TIMESTAMP); + UNTIL v_product_cost_change > 0.15 OR v_last_update_days < 10 END REPEAT; + END L2; + ELSE + BEGIN + DECLARE v_min_cost DOUBLE; + SET v_min_cost = (SELECT MIN(product_cost) FROM products WHERE product_is_active = true); + IF v_min_cost > 10 THEN + L3: BEGIN + REPEAT + SET v_product_cost_change = v_product_cost_change - 0.02; + UPDATE products SET product_cost = product_cost * (1.0 + v_product_cost_change) WHERE product_id = product.product_id; + UNTIL v_product_cost_change < -0.10 OR (SELECT MIN(product_cost) FROM products WHERE product_is_active = true) <= 10 END REPEAT; + END L3; + END IF; + IF v_product_is_active = false THEN + BEGIN + DECLARE v_active_product_count INT; + SET v_active_product_count = (SELECT COUNT(*) FROM products WHERE product_is_active = true); + IF v_active_product_count < 5 THEN + UPDATE products SET product_is_active = true WHERE product_id = (SELECT MIN(product_id) FROM products WHERE product_is_active = false); + END IF; + END; + END IF; + END; + END IF; + END L1; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, cost-logic +-- EXPECTED: Random cost and status updates, last update refresh, activation logic +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 21 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_shipping_cost DOUBLE; + DECLARE v_region STRING; + DECLARE v_region_shipping_changed BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Shipping region logic error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_order_limit INT DEFAULT 3; + FOR region AS SELECT DISTINCT order_shipping_region FROM orders LIMIT 2 DO + SET v_region = region.order_shipping_region; + SET v_order_shipping_cost = (SELECT SUM(order_shipping) FROM orders WHERE order_shipping_region = v_region); + IF v_order_shipping_cost > 10 THEN + L1: BEGIN + REPEAT + SET v_order_shipping_cost = v_order_shipping_cost - 1.0; + SET v_region_shipping_changed = true; + UPDATE orders SET order_shipping = order_shipping - 0.5 WHERE order_shipping_region = v_region; + UNTIL v_order_shipping_cost < 10 END REPEAT; + END L1; + END IF; + BEGIN + IF v_region_shipping_changed THEN + L2: BEGIN + DECLARE v_supplier_in_region INT; + SET v_supplier_in_region = (SELECT COUNT(*) FROM suppliers WHERE supplier_region = v_region); + IF v_supplier_in_region = 0 THEN + INSERT INTO suppliers VALUES ( + (SELECT MAX(supplier_id) + 1 FROM suppliers), + 'Region Supplier', + 'Region Contact', + 'Region Manager', + 'region@supplier.com', + '555-0000', + '123 Region St', + 'Region City', + 'CA', + '00000', + 'USA', + v_region, + 'General', + true + ); + END IF; + END L2; + END IF; + END; + END FOR; + END L0; + BEGIN + DECLARE v_nonexistent_orders INT; + SET v_nonexistent_orders = (SELECT COUNT(*) FROM orders o LEFT JOIN customers c ON o.customer_id = c.customer_id WHERE c.customer_id IS NULL); + IF v_nonexistent_orders > 0 THEN + L3: BEGIN + WHILE v_nonexistent_orders > 0 DO + DELETE FROM orders WHERE order_id = (SELECT MIN(order_id) FROM orders o LEFT JOIN customers c ON o.customer_id = c.customer_id WHERE c.customer_id IS NULL); + SET v_nonexistent_orders = v_nonexistent_orders - 1; + END WHILE; + END L3; + END IF; + END; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, WHILE, DML, deep-nesting, exception-handler, shipping-region +-- EXPECTED: Random shipping cost adjustments, supplier inserts, orphaned order cleanup +-- EXECUTES: FOR, IF, REPEAT, WHILE, nested BEGIN...END, exception handler + +-- Script 22 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_product_color STRING; + DECLARE v_color_count INT; + DECLARE v_max_price_flag BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product color error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_min_products_per_color INT DEFAULT 2; + FOR color AS SELECT DISTINCT product_color FROM products LIMIT 3 DO + SET v_product_color = color.product_color; + SET v_color_count = (SELECT COUNT(*) FROM products WHERE product_color = v_product_color); + IF v_color_count < v_min_products_per_color THEN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Extra ' || v_product_color, + 'Accessory', + 19.99, + 12.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Color Contact', + 'Color Role', + '123 Color St', + 5, + v_product_color, + 'Small', + 0.5, + 'Extra color', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_color_count = v_color_count + 1; + UNTIL v_color_count >= v_min_products_per_color END REPEAT; + END IF; + BEGIN + DECLARE v_max_color_price DOUBLE; + SET v_max_color_price = (SELECT MAX(product_price) FROM products WHERE product_color = v_product_color); + IF v_max_color_price > 100 THEN + SET v_max_price_flag = true; + UPDATE products SET product_price = product_price * 0.85 WHERE product_color = v_product_color AND product_price > 100; + END IF; + END; + IF v_max_price_flag THEN + BEGIN + DECLARE v_products_updated INT; + SET v_products_updated = (SELECT COUNT(*) FROM products WHERE product_color = v_product_color AND product_price < 50); + IF v_products_updated = 0 THEN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Low Price ' || v_product_color, + 'Budget', + 29.99, + 19.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Budget Contact', + 'Budget Role', + '123 Budget St', + 10, + v_product_color, + 'Medium', + 0.8, + 'Low price option', + 3.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.05, + 0.19 + ); + UNTIL (SELECT COUNT(*) FROM products WHERE product_color = v_product_color AND product_price < 50) > 0 END REPEAT; + END IF; + END; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, product-color +-- EXPECTED: Random product inserts, price adjustments, ensures color diversity +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 23 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_total_tax DOUBLE; + DECLARE v_order_date_month INT; + DECLARE v_status_changed BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order tax logic error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_min_tax_month DOUBLE DEFAULT 100.0; + FOR order_row AS SELECT order_id, order_total, order_tax, order_date, order_status FROM orders LIMIT 3 DO + SET v_order_total_tax = order_row.order_total + order_row.order_tax; + SET v_order_date_month = MONTH(order_row.order_date); + IF v_order_date_month % 2 = 0 THEN + L1: BEGIN + IF order_row.order_status = 'Completed' THEN + SET v_status_changed = true; + UPDATE orders SET order_status = 'Closed' WHERE order_id = order_row.order_id; + END IF; + BEGIN + DECLARE v_adj_tax DOUBLE; + SET v_adj_tax = order_row.order_tax * 1.1; + SET v_order_total_tax = v_order_total_tax + (v_adj_tax - order_row.order_tax); + UPDATE orders SET order_tax = v_adj_tax WHERE order_id = order_row.order_id; + IF v_order_total_tax > v_min_tax_month THEN + L2: BEGIN + REPEAT + SET v_min_tax_month = v_min_tax_month + 10.0; + UNTIL v_min_tax_month > v_order_total_tax END REPEAT; + END L2; + END IF; + END; + END L1; + ELSE + L3: BEGIN + DECLARE v_order_items_added INT DEFAULT 0; + WHILE v_order_items_added < 2 DO + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + order_row.order_id, + (SELECT MIN(product_id) FROM products), + 1, + 10.0, + 0.0, + 1.0, + 11.0 + ); + SET v_order_items_added = v_order_items_added + 1; + END WHILE; + END L3; + END IF; + END FOR; + END L0; + BEGIN + DECLARE v_completed_orders INT; + SET v_completed_orders = (SELECT COUNT(*) FROM orders WHERE order_status = 'Completed'); + IF v_completed_orders = 0 THEN + L4: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Completed', + 50.0, + 5.0, + 0.0, + 5.0 + ); + UNTIL (SELECT COUNT(*) FROM orders WHERE order_status = 'Completed') > 1 END REPEAT; + END L4; + END IF; + END; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, WHILE, DML, deep-nesting, exception-handler, tax-logic +-- EXPECTED: Random tax increases, item additions, status updates, order completions +-- EXECUTES: FOR, IF, REPEAT, WHILE, nested BEGIN...END, exception handler + +-- Script 24 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_product_size STRING; + DECLARE v_size_count INT; + DECLARE v_min_size_count INT DEFAULT 2; + DECLARE v_size_has_price_flag BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product size error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + FOR size AS SELECT DISTINCT product_size FROM products LIMIT 3 DO + SET v_product_size = size.product_size; + SET v_size_count = (SELECT COUNT(*) FROM products WHERE product_size = v_product_size); + IF v_size_count < v_min_size_count THEN + L1: BEGIN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Extra ' || v_product_size, + 'General', + 24.99, + 15.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Size Contact', + 'Size Role', + '123 Size St', + 5, + 'Black', + v_product_size, + 0.6, + 'Extra ' || v_product_size || ' product', + 3.5, + 8, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_size_count = v_size_count + 1; + SET v_size_has_price_flag = true; + UNTIL v_size_count >= v_min_size_count END REPEAT; + END L1; + END IF; + IF v_size_has_price_flag THEN + BEGIN + DECLARE v_avg_size_price DOUBLE; + SET v_avg_size_price = (SELECT AVG(product_price) FROM products WHERE product_size = v_product_size); + IF v_avg_size_price > 30 THEN + REPEAT + UPDATE products SET product_discount = product_discount + 0.05 WHERE product_size = v_product_size AND product_discount < 0.15; + SET v_avg_size_price = (SELECT AVG(product_price) FROM products WHERE product_size = v_product_size); + UNTIL v_avg_size_price <= 30 END REPEAT; + END IF; + END; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, product-size +-- EXPECTED: Random product inserts, discount updates, ensures size diversity +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 25 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_department STRING; + DECLARE v_dept_emp_count INT; + DECLARE v_dept_avg_salary DOUBLE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Department error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + FOR dept AS SELECT DISTINCT employee_department FROM employees LIMIT 3 DO + SET v_department = dept.employee_department; +SET v_dept_emp_count = (SELECT COUNT(*) FROM employees WHERE employee_department = v_department); + SET v_dept_avg_salary = (SELECT AVG(employee_salary) FROM employees WHERE employee_department = v_department); + IF v_dept_emp_count < 2 THEN + L1: BEGIN + REPEAT + INSERT INTO employees VALUES ( + (SELECT MAX(employee_id) + 1 FROM employees), + v_department || ' Emp ' || v_dept_emp_count, + 'emp' || v_dept_emp_count || '@' || LOWER(v_department) || '.com', + '555-0000', + 'Member', + v_department, + CURRENT_TIMESTAMP, + NULL, + 35000.0, + 0.0, + NULL, + '123 Dept St', + NULL, + 'Dept City', + 'CA', + '00000', + 'USA', + CURRENT_TIMESTAMP, + 'Female', + 'Single', + 0 + ); + SET v_dept_emp_count = v_dept_emp_count + 1; + UNTIL v_dept_emp_count >= 2 END REPEAT; +END L1; +END IF; + IF v_dept_avg_salary > 40000 AND v_dept_emp_count >= 2 THEN +BEGIN + DECLARE v_salary_decrease DOUBLE; + SET v_salary_decrease = 0.95; + REPEAT +UPDATE employees SET employee_salary = employee_salary * v_salary_decrease WHERE employee_department = v_department; +SET v_dept_avg_salary = (SELECT AVG(employee_salary) FROM employees WHERE employee_department = v_department); + UNTIL v_dept_avg_salary <= 40000 END REPEAT; +END; + ELSEIF v_dept_avg_salary < 30000 AND v_dept_emp_count >= 2 THEN + REPEAT +UPDATE employees SET employee_salary = employee_salary * 1.05 WHERE employee_department = v_department AND employee_salary < 30000; +SET v_dept_avg_salary = (SELECT AVG(employee_salary) FROM employees WHERE employee_department = v_department); + UNTIL v_dept_avg_salary >= 30000 OR v_dept_avg_salary > 50000 END REPEAT; +END IF; +END FOR; +END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, department-logic +-- EXPECTED: Random employee inserts, salary adjustments, department balancing +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 26 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_product_rating DOUBLE; + DECLARE v_max_reviews INT DEFAULT 100; + DECLARE v_min_reviews_flag BOOLEAN DEFAULT true; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product review analysis error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + FOR product AS SELECT product_id, product_rating, product_reviews FROM products LIMIT 3 DO + SET v_product_rating = product.product_rating; + IF product.product_reviews < 10 THEN + REPEAT + SET v_min_reviews_flag = true; + UPDATE products SET product_reviews = product_reviews + 5, product_rating = LEAST(product_rating + 0.1, 5.0) WHERE product_id = product.product_id; + UNTIL product.product_reviews >= 10 END REPEAT; + END IF; + BEGIN + IF v_min_reviews_flag = true AND v_product_rating < 4.5 THEN + REPEAT + SET v_product_rating = (SELECT product_rating FROM products WHERE product_id = product.product_id); + UPDATE products SET product_rating = product_rating + 0.1 WHERE product_id = product.product_id; + UNTIL (SELECT product_rating FROM products WHERE product_id = product.product_id) >= 4.5 END REPEAT; + END IF; + END; + IF product.product_rating > 4.5 AND product.product_reviews > v_max_reviews THEN + BEGIN + REPEAT + UPDATE products SET product_reviews = product_reviews + 1 WHERE product_id = product.product_id; + SET v_max_reviews = v_max_reviews + 1; + UNTIL product.product_reviews > v_max_reviews * 2 END REPEAT; + END; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, review-analysis +-- EXPECTED: Random reviews and rating updates, rating boosting, review inflation +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 27 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_shipping_city STRING; + DECLARE v_shipping_fee_min DOUBLE DEFAULT 2.0; + DECLARE v_order_volume INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('City shipping error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + FOR city AS SELECT DISTINCT order_shipping_city FROM orders LIMIT 3 DO + SET v_order_shipping_city = city.order_shipping_city; + SET v_order_volume = (SELECT COUNT(*) FROM orders WHERE order_shipping_city = v_order_shipping_city); + IF v_order_volume > 1 THEN + L1: BEGIN + REPEAT + SET v_shipping_fee_min = v_shipping_fee_min + 0.1; + UPDATE orders SET order_shipping = order_shipping + 0.2 WHERE order_shipping_city = v_order_shipping_city AND order_shipping < v_shipping_fee_min; + UNTIL v_shipping_fee_min > 5.0 END REPEAT; + END L1; + BEGIN + DECLARE v_order_tax_avg DOUBLE; + SET v_order_tax_avg = (SELECT AVG(order_tax) FROM orders WHERE order_shipping_city = v_order_shipping_city); + IF v_order_tax_avg > 10 THEN + L2: BEGIN + REPEAT + SET v_order_tax_avg = v_order_tax_avg - 1.0; + UPDATE orders SET order_tax = order_tax * 0.9 WHERE order_shipping_city = v_order_shipping_city; + UNTIL v_order_tax_avg <= 10 END REPEAT; + END L2; + END IF; + END; + ELSE + L3: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping, + order_shipping_city + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Volume Insert', + 12.0, + 1.2, + 0.0, + 2.0, + v_order_shipping_city + ); + SET v_order_volume = (SELECT COUNT(*) FROM orders WHERE order_shipping_city = v_order_shipping_city); + UNTIL v_order_volume > 1 END REPEAT; + END L3; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, city-shipping +-- EXPECTED: Random shipping fee and tax updates, order volume manipulation +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 28 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_employee_salary DOUBLE; + DECLARE v_employee_manager_id INT; + DECLARE v_manager_has_subordinates BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Employee hierarchy error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + FOR emp AS SELECT employee_id, employee_salary, employee_manager_id FROM employees LIMIT 3 DO + SET v_employee_salary = emp.employee_salary; + SET v_employee_manager_id = emp.employee_manager_id; + IF v_employee_manager_id IS NOT NULL THEN + L1: BEGIN + SET v_manager_has_subordinates = (SELECT COUNT(*) > 0 FROM employees WHERE employee_manager_id = v_employee_manager_id); + IF v_manager_has_subordinates THEN + L2: BEGIN + BEGIN + DECLARE v_min_salary DOUBLE DEFAULT 0.0; + SET v_min_salary = (SELECT MIN(employee_salary) FROM employees WHERE employee_manager_id = v_employee_manager_id); + WHILE v_min_salary < 30000 DO + UPDATE employees SET employee_salary = employee_salary + 1000.0 WHERE employee_id = emp.employee_id; + SET v_employee_salary = v_employee_salary + 1000.0; + SET v_min_salary = (SELECT MIN(employee_salary) FROM employees WHERE employee_manager_id = v_employee_manager_id); + END WHILE; + END; + END L2; + ELSE + L3: BEGIN + REPEAT + SET v_employee_salary = v_employee_salary * 1.01; + UPDATE employees SET employee_salary = v_employee_salary WHERE employee_id = emp.employee_id; + UNTIL (SELECT COUNT(*) FROM employees WHERE employee_manager_id = emp.employee_id) > 0 OR v_employee_salary > 50000 END REPEAT; + END L3; + END IF; + END L1; + ELSE + BEGIN + DECLARE v_lowest_salary DOUBLE; + SET v_lowest_salary = (SELECT MIN(employee_salary) FROM employees WHERE employee_manager_id IS NULL); + IF v_lowest_salary < 40000 THEN + REPEAT + INSERT INTO employees VALUES ( + (SELECT MAX(employee_id) + 1 FROM employees), + 'Subordinate_' || v_lowest_salary, + 'subord' || v_lowest_salary || '@company.com', + '555-0000', + 'Subordinate', + 'HR', + CURRENT_TIMESTAMP, + NULL, + 30000.0, + 0.0, + emp.employee_id, + '123 Sub St', + NULL, + 'Sub City', + 'CA', + '00000', + 'USA', + CURRENT_TIMESTAMP, + 'Male', + 'Single', + 0 + ); + SET v_manager_has_subordinates = (SELECT COUNT(*) > 0 FROM employees WHERE employee_manager_id = emp.employee_id); + UNTIL v_manager_has_subordinates OR v_lowest_salary > 35000 END REPEAT; + END IF; + END; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, WHILE, REPEAT, DML, deep-nesting, exception-handler, hierarchy-logic +-- EXPECTED: Random salary adjustments, subordinate creation, manager checks +-- EXECUTES: FOR, IF, WHILE, REPEAT, nested BEGIN...END, exception handler + +-- Script 29 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_creation_date TIMESTAMP; + DECLARE v_order_status STRING; + DECLARE v_order_days_pending INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order backlog error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + FOR order_row AS SELECT order_id, order_date, order_status FROM orders LIMIT 3 DO + SET v_order_creation_date = order_row.order_date; + SET v_order_status = order_row.order_status; + SET v_order_days_pending = DATEDIFF(DAY, v_order_creation_date, CURRENT_TIMESTAMP); + IF v_order_days_pending > 5 AND v_order_status = 'Processing' THEN + L1: BEGIN + REPEAT + UPDATE orders SET order_status = 'Pending', order_shipping = order_shipping + 1.0 WHERE order_id = order_row.order_id; + SET v_order_creation_date = (SELECT order_date FROM orders WHERE order_id = order_row.order_id); + SET v_order_days_pending = DATEDIFF(DAY, v_order_creation_date, CURRENT_TIMESTAMP); + UNTIL v_order_days_pending < 3 END REPEAT; + END L1; + ELSEIF v_order_days_pending > 30 AND v_order_status = 'Pending' THEN + L2: BEGIN + WHILE v_order_days_pending > 10 DO + SET v_order_status = 'Cancelled'; + UPDATE orders SET order_status = v_order_status, order_shipping = 0.0 WHERE order_id = order_row.order_id; + SET v_order_days_pending = DATEDIFF(DAY, (SELECT order_date FROM orders WHERE order_id = order_row.order_id), CURRENT_TIMESTAMP); + END WHILE; + END L2; + ELSE + BEGIN + DECLARE v_backlog_order_count INT; + SET v_backlog_order_count = (SELECT COUNT(*) FROM orders WHERE order_status = 'Processing' AND DATEDIFF(DAY, order_date, CURRENT_TIMESTAMP) > 5); + IF v_backlog_order_count > 0 THEN + L3: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Escalated', + 20.0, + 2.0, + 0.0, + 0.0 + ); + SET v_backlog_order_count = v_backlog_order_count - 1; + UNTIL v_backlog_order_count = 0 END REPEAT; + END L3; + END IF; + END; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, WHILE, DML, deep-nesting, exception-handler, backlog-logic +-- EXPECTED: Random status updates, shipping changes, order inserts for backlog maintenance +-- EXECUTES: FOR, IF, REPEAT, WHILE, nested BEGIN...END, exception handler + +-- Script 30 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_item_id INT; + DECLARE v_order_item_status STRING; + DECLARE v_shipped_item_count INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order item error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + FOR order_item AS SELECT order_item_id, item_status FROM order_items LIMIT 3 DO + SET v_order_item_id = order_item.order_item_id; + SET v_order_item_status = order_item.item_status; + IF v_order_item_status = 'Shipped' THEN + SET v_shipped_item_count = v_shipped_item_count + 1; + L1: BEGIN + DECLARE v_item_shipping_delay INT; + SET v_item_shipping_delay = (SELECT DATEDIFF(DAY, (SELECT item_shipping_date FROM order_items WHERE order_item_id = v_order_item_id), CURRENT_TIMESTAMP)); + IF v_item_shipping_delay > 7 THEN + REPEAT + UPDATE order_items SET item_discount = item_discount + 0.05 WHERE order_item_id = v_order_item_id; + SET v_item_shipping_delay = (SELECT DATEDIFF(DAY, (SELECT item_shipping_date FROM order_items WHERE order_item_id = v_order_item_id), CURRENT_TIMESTAMP)); + UNTIL v_item_shipping_delay < 4 END REPEAT; + END IF; + END L1; + END IF; + END FOR; + BEGIN + IF v_shipped_item_count < 1 THEN + L2: BEGIN + REPEAT + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total, + item_status, + item_shipping_date + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MIN(order_id) FROM orders), + (SELECT MIN(product_id) FROM products), + 1, + 10.0, + 0.0, + 1.0, + 11.0, + 'Shipped', + CAST(CURRENT_TIMESTAMP AS DATE) + ); + SET v_shipped_item_count = v_shipped_item_count + 1; + UNTIL v_shipped_item_count > 0 END REPEAT; + END L2; + END IF; + END; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, item-logic +-- EXPECTED: Random item discount and status updates, shipped item guarantees +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 31 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_supplier_contact_emails INT DEFAULT 0; + DECLARE v_active_supplier_count INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier contact error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + FOR supplier AS SELECT supplier_id, supplier_active, supplier_contact_email FROM suppliers LIMIT 3 DO + IF supplier.supplier_active = true AND supplier.supplier_contact_email IS NOT NULL THEN + SET v_active_supplier_count = v_active_supplier_count + 1; + L1: BEGIN + REPEAT + SET v_supplier_contact_emails = v_supplier_contact_emails + 1; + UPDATE suppliers SET supplier_contact_email = 'new_' || supplier.supplier_contact_email WHERE supplier_id = supplier.supplier_id; + UNTIL v_supplier_contact_emails > 1 END REPEAT; + END L1; + L2: BEGIN + DECLARE v_supplier_products INT; + SET v_supplier_products = (SELECT COUNT(*) FROM products WHERE supplier_id = supplier.supplier_id); + IF v_supplier_products = 0 THEN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'New Supplier Item', + 'Specialty', + 35.99, + 25.99, + supplier.supplier_id, + 'New Contact', + 'New Role', + '123 New St', + 3, + 'Red', + 'Small', + 0.7, + 'New supplier item', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + UNTIL (SELECT COUNT(*) FROM products WHERE supplier_id = supplier.supplier_id) > 0 END REPEAT; + END IF; + END L2; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, supplier-contact-logic +-- EXPECTED: Random supplier contact and product updates, ensures active supplier content +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 32 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_product_discount_avg DOUBLE; + DECLARE v_max_discount_products INT DEFAULT 2; + DECLARE v_discount_changed BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product price error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_discount_category STRING DEFAULT 'GENERAL'; + FOR category AS SELECT DISTINCT product_category FROM products LIMIT 2 DO + SET v_product_discount_avg = (SELECT AVG(product_discount) FROM products WHERE product_category = category.product_category); + IF v_product_discount_avg > 0.1 THEN + L1: BEGIN + REPEAT + SET v_product_discount_avg = v_product_discount_avg - 0.01; + UPDATE products SET product_discount = product_discount - 0.01 WHERE product_category = category.product_category; + SET v_discount_changed = true; + UNTIL v_product_discount_avg <= 0.1 END REPEAT; + END L1; + END IF; + IF v_discount_changed = false THEN + L2: BEGIN + REPEAT + INSERT INTO products VALUES ( + (SELECT COALESCE(MAX(product_id), 0) + 1 FROM products), + v_discount_category, + 'Discount', + 49.99, + 39.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Discounter', + 'Discount Role', + '123 Discount St', + 5, + 'Blue', + 'Large', + 1.2, + 'Maximum discount', + 0.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.9, + 0.19 + ); + SET v_discount_category = v_discount_category || '_EXTRA'; + SET v_max_discount_products = v_max_discount_products - 1; + UNTIL v_max_discount_products < 0 END REPEAT; + END L2; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, price-discount +-- EXPECTED: Random discount changes and product inserts, category balancing +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 33 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_employee_gender STRING; + DECLARE v_gender_count INT DEFAULT 0; + DECLARE v_min_gender_emp INT DEFAULT 1; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Employee diversity error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + FOR gender AS SELECT DISTINCT employee_gender FROM employees LIMIT 2 DO + SET v_employee_gender = gender.employee_gender; + SET v_gender_count = (SELECT COUNT(*) FROM employees WHERE employee_gender = v_employee_gender); + IF v_gender_count < v_min_gender_emp THEN + L1: BEGIN + REPEAT + INSERT INTO employees VALUES ( + (SELECT COALESCE(MAX(employee_id), 0) + 1 FROM employees), + v_employee_gender || ' Equality', + 'diverse@' || LOWER(v_employee_gender) || '.com', + '555-0000', + 'Balancer', + 'HR', + CURRENT_TIMESTAMP, + NULL, + 40000.0, + 0.0, + NULL, + '123 Balancer St', + NULL, + 'Balancer City', + 'CA', + '00000', + 'USA', + CURRENT_TIMESTAMP, + v_employee_gender, + 'Single', + 0 + ); + SET v_gender_count = v_gender_count + 1; + UNTIL v_gender_count >= v_min_gender_emp END REPEAT; + END L1; + END IF; + END FOR; + END L0; + L2: BEGIN + DECLARE v_fill_role STRING; + SET v_fill_role = 'Filler'; + REPEAT + INSERT INTO employees VALUES ( + (SELECT COALESCE(MAX(employee_id), 0) + 1 FROM employees), + v_fill_role, + 'fill@company.com', + '555-0000', + v_fill_role, + v_fill_role, + CURRENT_TIMESTAMP, + NULL, + 30000.0, + 0.0, + NULL, + '123 Filler St', + NULL, + v_fill_role || 'ville', + 'CA', + '00000', + 'USA', + CURRENT_TIMESTAMP, + 'Female', + 'Married', + 1 + ); + SET v_fill_role = v_fill_role || '_R'; + UNTIL (SELECT COUNT(*) FROM employees WHERE employee_position = 'Filler') > 1 END REPEAT; + END L2; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, diversity-logic +-- EXPECTED: Random employee inserts, gender diversity, position filling +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 34 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_channel STRING; + DECLARE v_channel_orders INT DEFAULT 0; + DECLARE v_channel_returns INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Channel analysis error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + FOR channel AS SELECT DISTINCT order_channel FROM orders LIMIT 3 DO + SET v_order_channel = channel.order_channel; + SET v_channel_orders = (SELECT COUNT(*) FROM orders WHERE order_channel = v_order_channel); + SET v_channel_returns = (SELECT COUNT(*) FROM orders o JOIN order_items oi ON o.order_id = oi.order_id WHERE o.order_channel = v_order_channel AND oi.item_status = 'Returned'); + IF v_channel_orders > 0 THEN + L1: BEGIN + IF v_channel_returns > 0 THEN + REPEAT + UPDATE orders + SET order_status = 'Processing', + order_tax = order_tax * 0.9 + WHERE order_id IN ( + SELECT o.order_id + FROM orders o + JOIN order_items oi ON o.order_id = oi.order_id + WHERE o.order_channel = v_order_channel + AND oi.item_status = 'Returned' + ); + SET v_channel_returns = v_channel_returns - 1; + UNTIL v_channel_returns = 0 END REPEAT; + END IF; + BEGIN + DECLARE v_low_revenue_orders INT; + SET v_low_revenue_orders = (SELECT COUNT(*) FROM orders WHERE order_channel = v_order_channel AND order_total < 25); + IF v_low_revenue_orders > 1 THEN + L2: BEGIN + REPEAT + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MIN(order_id) FROM orders WHERE order_channel = v_order_channel AND order_total < 25), + (SELECT MIN(product_id) FROM products), + 1, + 10.0, + 0.0, + 1.0, + 11.0 + ); + SET v_low_revenue_orders = v_low_revenue_orders - 1; + UNTIL v_low_revenue_orders < 1 END REPEAT; + END L2; + END IF; + END; + END L1; + ELSE + L3: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping, + order_channel + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Channel Fill', + 15.0, + 1.5, + 0.0, + 2.0, + v_order_channel + ); + SET v_channel_orders = v_channel_orders + 1; + UNTIL v_channel_orders > 0 END REPEAT; + END L3; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, channel-logic +-- EXPECTED: Multi-channel order and item updates, random DML +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 35 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_customer_type STRING; + DECLARE v_type_order_count INT; + DECLARE v_type_customer_count INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Customer type error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_min_orders_per_type INT DEFAULT 2; +FOR customer_type AS SELECT DISTINCT customer_type FROM customers LIMIT 3 DO + SET v_customer_type = customer_type.customer_type; +SET v_type_order_count = (SELECT COUNT(*) FROM orders o JOIN customers c ON o.customer_id = c.customer_id WHERE c.customer_type = v_customer_type); + SET v_type_customer_count = (SELECT COUNT(*) FROM customers WHERE customer_type = v_customer_type); + IF v_type_order_count < v_min_orders_per_type AND v_type_customer_count > 0 THEN + L1: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers WHERE customer_type = v_customer_type), + CURRENT_TIMESTAMP, + 'Type Fill', + 18.0, + 1.8, + 0.0, + 2.2 + ); + SET v_type_order_count = v_type_order_count + 1; + UNTIL v_type_order_count >= v_min_orders_per_type OR v_type_customer_count = 0 END REPEAT; +END L1; + ELSEIF v_type_customer_count = 0 THEN + L2: BEGIN + REPEAT + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Type ' || v_customer_type, + 'type_' || LOWER(v_customer_type) || '@example.com', + '555-0000', + '123 Type St', + 'Type City', + 'CA', + '00000', + 'USA', + v_customer_type, + CURRENT_TIMESTAMP, + 0.0, + NULL, + NULL, + NULL, + true, + true, + 0.0, + NULL, + NULL + ); + SET v_type_customer_count = v_type_customer_count + 1; + UNTIL v_type_customer_count > 0 END REPEAT; +END L2; +END IF; +END FOR; +END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, customer-type-logic +-- EXPECTED: Order and customer inserts, ensures coverage by customer type +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 36 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_zip_code STRING; + DECLARE v_zip_orders INT DEFAULT 0; + DECLARE v_zip_customers INT DEFAULT 0; + DECLARE v_zip_customer_total DOUBLE DEFAULT 0.0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Zip code analysis error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_min_zip_orders INT DEFAULT 3; + FOR zip AS SELECT DISTINCT customer_zip FROM customers LIMIT 2 DO + SET v_zip_code = zip.customer_zip; + SET v_zip_orders = (SELECT COUNT(*) FROM orders o JOIN customers c ON o.customer_id = c.customer_id WHERE c.customer_zip = v_zip_code); + SET v_zip_customers = (SELECT COUNT(*) FROM customers WHERE customer_zip = v_zip_code); + IF v_zip_orders < v_min_zip_orders AND v_zip_customers > 0 THEN + L1: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers WHERE customer_zip = v_zip_code), + CURRENT_TIMESTAMP, + 'Zip Fill', + 20.0, + 2.0, + 0.0, + 3.0 + ); + SET v_zip_orders = v_zip_orders + 1; + UNTIL v_zip_orders >= v_min_zip_orders END REPEAT; + END L1; + ELSEIF v_zip_customers = 0 THEN + L2: BEGIN + REPEAT + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Zip Filler ' || v_zip_code, + 'zip_' || v_zip_code || '@example.com', + '555-0000', + '123 Zip St', + 'Zip City', + 'CA', + v_zip_code, + 'USA', + 'Retail', + CURRENT_TIMESTAMP, + 0.0, + NULL, + NULL, + NULL, + true, + true, + 0.0, + NULL, + NULL + ); + SET v_zip_customers = v_zip_customers + 1; + UNTIL v_zip_customers > 0 END REPEAT; + END L2; + END IF; + SET v_zip_customer_total = (SELECT SUM(customer_total_spent) FROM customers WHERE customer_zip = v_zip_code); + IF v_zip_customer_total > 200.0 AND v_zip_customers > 0 THEN + L3: BEGIN + REPEAT + UPDATE customers + SET customer_discount_percentage = customer_discount_percentage + 0.05 + WHERE customer_zip = v_zip_code + AND customer_discount_percentage < 0.2; + SET v_zip_customer_total = (SELECT SUM(customer_total_spent) FROM customers WHERE customer_zip = v_zip_code); + UNTIL v_zip_customer_total <= 200.0 OR v_zip_customers = 0 END REPEAT; + END L3; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, zip-code-logic +-- EXPECTED: Order and customer inserts, zip-level discount logic, balancing +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 37 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_shipping_region STRING; + DECLARE v_region_shipping_total DOUBLE; + DECLARE v_region_discount_offered BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Shipping region error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_max_discount_region_order DOUBLE DEFAULT 100.0; + FOR shipping_region AS SELECT DISTINCT order_shipping_region FROM orders LIMIT 2 DO + SET v_order_shipping_region = shipping_region.order_shipping_region; + SET v_region_shipping_total = (SELECT SUM(order_shipping) FROM orders WHERE order_shipping_region = v_order_shipping_region); + IF v_region_shipping_total > 20 AND v_region_shipping_total < 50 THEN + L1: BEGIN + REPEAT + SET v_region_discount_offered = true; + UPDATE orders SET order_shipping = order_shipping - 0.5 WHERE order_shipping_region = v_order_shipping_region; + SET v_region_shipping_total = (SELECT SUM(order_shipping) FROM orders WHERE order_shipping_region = v_order_shipping_region); + UNTIL v_region_shipping_total <= 15 OR v_region_discount_offered = false END REPEAT; + END L1; + IF v_region_discount_offered = true THEN + BEGIN + DECLARE v_low_region_products INT; + SET v_low_region_products = (SELECT COUNT(*) FROM order_items oi JOIN orders o ON oi.order_id = o.order_id JOIN products p ON oi.product_id = p.product_id WHERE o.order_shipping_region = v_order_shipping_region AND p.product_discount > 0.1); + IF v_low_region_products < 1 THEN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Region Special', + v_order_shipping_region, + 44.99, + 29.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Region Contact', + 'Region Role', + '123 Region St', + 3, + 'Blue', + 'Medium', + 0.9, + 'Region special', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.15, + 0.19 + ); + UNTIL (SELECT COUNT(*) FROM order_items oi JOIN orders o ON oi.order_id = o.order_id JOIN products p ON oi.product_id = p.product_id WHERE o.order_shipping_region = v_order_shipping_region AND p.product_discount > 0.1) > 0 END REPEAT; + END IF; + END; + END IF; + ELSE + L2: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping, + order_shipping_region + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Region Fill', + 22.0, + 2.2, + 0.0, + 5.0, + v_order_shipping_region + ); + SET v_region_shipping_total = (SELECT SUM(order_shipping) FROM orders WHERE order_shipping_region = v_order_shipping_region); + UNTIL v_region_shipping_total > 10 END REPEAT; + END L2; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, shipping-region-logic +-- EXPECTED: Shipping and product updates, region-specific logic, DML +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 38 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_customer_email_domain STRING; + DECLARE v_domain_customer_count INT; + DECLARE v_domain_order_count INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Email domain error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_min_orders_per_domain INT DEFAULT 1; + FOR customer AS SELECT SUBSTRING(customer_email, POSITION('@' IN customer_email)) AS domain, customer_id FROM customers LIMIT 3 DO + SET v_customer_email_domain = customer.domain; + SET v_domain_customer_count = (SELECT COUNT(*) FROM customers WHERE customer_email LIKE '%' || v_customer_email_domain); + SET v_domain_order_count = (SELECT COUNT(*) FROM orders WHERE customer_id IN (SELECT customer_id FROM customers WHERE customer_email LIKE '%' || v_customer_email_domain)); + IF v_domain_order_count < v_min_orders_per_domain AND v_domain_customer_count > 0 THEN + L1: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + customer.customer_id, + CURRENT_TIMESTAMP, + 'Domain Fill', + 15.0, + 1.5, + 0.0, + 2.0 + ); + SET v_domain_order_count = v_domain_order_count + 1; + UNTIL v_domain_order_count >= v_min_orders_per_domain END REPEAT; + END L1; + END IF; + END FOR; + END L0; + BEGIN + DECLARE v_empty_domain_count INT; + SET v_empty_domain_count = (SELECT COUNT(*) FROM customers WHERE customer_email IS NULL OR customer_email = ''); + IF v_empty_domain_count > 0 THEN + L2: BEGIN + REPEAT + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MIN(order_id) FROM orders), + (SELECT MIN(product_id) FROM products), + 1, + 10.0, + 0.0, + 1.0, + 11.0 + ); + SET v_empty_domain_count = v_empty_domain_count - 1; + UNTIL v_empty_domain_count = 0 END REPEAT; + END L2; + END IF; + END; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, email-domain-logic +-- EXPECTED: Order and item inserts, email domain logic, DML +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 39 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_department_emp_count INT; + DECLARE v_department_avg_yearly_salary DOUBLE; + DECLARE v_salary_change_needed BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Department salary error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_min_dept_size INT DEFAULT 2; + FOR department AS SELECT DISTINCT employee_department FROM employees LIMIT 3 DO + SET v_department_emp_count = (SELECT COUNT(*) FROM employees WHERE employee_department = department.employee_department); + SET v_department_avg_yearly_salary = (SELECT AVG(employee_salary) FROM employees WHERE employee_department = department.employee_department); + IF v_department_emp_count > v_min_dept_size THEN + L1: BEGIN + IF v_department_avg_yearly_salary > 60000 THEN + L2: BEGIN + SET v_salary_change_needed = true; + REPEAT + UPDATE employees SET employee_salary = employee_salary * 0.97 WHERE employee_department = department.employee_department AND employee_salary > 40000; + SET v_department_avg_yearly_salary = (SELECT AVG(employee_salary) FROM employees WHERE employee_department = department.employee_department); + UNTIL v_department_avg_yearly_salary < 60000 OR v_salary_change_needed = false END REPEAT; + END L2; + END IF; + END L1; + ELSE + L3: BEGIN + DECLARE v_new_emp_id INT; + SET v_new_emp_id = (SELECT MAX(employee_id) + 1 FROM employees); + INSERT INTO employees VALUES ( + v_new_emp_id, + 'Dept Filler', + 'dept_' || LOWER(department.employee_department) || '@company.com', + '555-0000', + 'Member', + department.employee_department, + CURRENT_TIMESTAMP, + NULL, + 45000.0, + 0.0, + NULL, + '123 Dept St', + NULL, + 'Dept City', + 'CA', + '00000', + 'USA', + CURRENT_TIMESTAMP, + 'Female', + 'Single', + 0 + ); + SET v_department_emp_count = v_department_emp_count + 1; + END L3; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, department-salary-logic +-- EXPECTED: Random salary and department updates, DML +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 40 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_status STRING; + DECLARE v_status_count INT; + DECLARE v_status_order_total DOUBLE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order status error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_min_status_orders INT DEFAULT 2; + FOR order_stat AS SELECT DISTINCT order_status FROM orders LIMIT 3 DO + SET v_order_status = order_stat.order_status; + SET v_status_count = (SELECT COUNT(*) FROM orders WHERE order_status = v_order_status); + SET v_status_order_total = (SELECT SUM(order_total) FROM orders WHERE order_status = v_order_status); + IF v_status_count < v_min_status_orders THEN + L1: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + v_order_status, + 15.0, + 1.5, + 0.0, + 2.0 + ); + SET v_status_count = (SELECT COUNT(*) FROM orders WHERE order_status = v_order_status); + UNTIL v_status_count >= v_min_status_orders END REPEAT; + END L1; + END IF; + IF v_status_order_total > 200 AND v_status_count > 1 THEN + L2: BEGIN + REPEAT + SET v_status_order_total = v_status_order_total - 10.0; + UPDATE orders + SET order_total = order_total - 10.0 + WHERE order_status = v_order_status + AND order_total > 30.0; + UNTIL v_status_order_total <= 200 OR v_status_count < 2 END REPEAT; + END L2; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, status-order-logic +-- EXPECTED: Random order inserts, status balancing, revenue control +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 41 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_emp_department_size_counts INT; + DECLARE v_dept_name STRING; + DECLARE v_dept_average_age INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Department diversity error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_min_dept_diversity INT DEFAULT 2; + FOR dept AS SELECT DISTINCT employee_department FROM employees LIMIT 3 DO + SET v_dept_name = dept.employee_department; + SET v_emp_department_size_counts = (SELECT COUNT(*) FROM employees WHERE employee_department = v_dept_name); + IF v_emp_department_size_counts < v_min_dept_diversity THEN + L1: BEGIN + REPEAT + INSERT INTO employees VALUES ( + (SELECT MAX(employee_id) + 1 FROM employees), + 'Diverse Dept ' || v_dept_name, + 'diverse_' || LOWER(v_dept_name) || '@company.com', + '555-0000', + 'Balancer', + v_dept_name, + CURRENT_TIMESTAMP, + NULL, + 35000.0, + 0.0, + NULL, + '123 Balance St', + NULL, + 'Balance City', + 'CA', + '00000', + 'USA', + CASE WHEN MOD((SELECT COUNT(*) FROM employees WHERE employee_department = v_dept_name), 2) = 0 THEN 'Male' ELSE 'Female' END, + 'Single', + 0 + ); + SET v_emp_department_size_counts = v_emp_department_size_counts + 1; + UNTIL v_emp_department_size_counts >= v_min_dept_diversity END REPEAT; + END L1; + END IF; + SET v_dept_average_age = (SELECT AVG(DATEDIFF(YEAR, employee_birth_date, CURRENT_TIMESTAMP)) FROM employees WHERE employee_department = v_dept_name); + IF v_dept_average_age IS NULL THEN + L2: BEGIN + REPEAT + INSERT INTO employees VALUES ( + (SELECT MAX(employee_id) + 1 FROM employees), + 'Age Dept ' || v_dept_name, + 'age_' || LOWER(v_dept_name) || '@company.com', + '555-0000', + 'Age', + v_dept_name, + CURRENT_TIMESTAMP, + NULL, + 30000.0, + 0.0, + NULL, + '123 Age St', + NULL, + 'Age City', + 'CA', + '00000', + 'USA', + DATEADD(YEAR, -30, CURRENT_TIMESTAMP), + 'Female', + 'Married', + 1 + ); + SET v_dept_average_age = (SELECT AVG(DATEDIFF(YEAR, employee_birth_date, CURRENT_TIMESTAMP)) FROM employees WHERE employee_department = v_dept_name); + UNTIL v_dept_average_age IS NOT NULL END REPEAT; + END L2; + ELSEIF v_dept_average_age < 30 THEN + L3: BEGIN + REPEAT + INSERT INTO employees VALUES ( + (SELECT MAX(employee_id) + 1 FROM employees), + 'Mature ' || v_dept_name, + 'mature_' || LOWER(v_dept_name) || '@company.com', + '555-0000', + 'Senior', + v_dept_name, + CURRENT_TIMESTAMP, + NULL, + 55000.0, + 0.0, + NULL, + '123 Senior St', + NULL, + 'Senior City', + 'CA', + '00000', + 'USA', + DATEADD(YEAR, -40, CURRENT_TIMESTAMP), + 'Male', + 'Married', + 3 + ); + SET v_dept_average_age = (SELECT AVG(DATEDIFF(YEAR, employee_birth_date, CURRENT_TIMESTAMP)) FROM employees WHERE employee_department = v_dept_name); + UNTIL v_dept_average_age > 30 END REPEAT; + END L3; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, department-diversity-logic +-- EXPECTED: Employee inserts, age and gender balancing, DML +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 42 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_supplier_type STRING; + DECLARE v_supplier_product_count INT; + DECLARE v_products_per_type_min INT DEFAULT 3; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier product error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + FOR supplier AS SELECT supplier_id, supplier_main_products FROM suppliers LIMIT 3 DO + SET v_supplier_type = supplier.supplier_main_products; + SET v_supplier_product_count = (SELECT COUNT(*) FROM products WHERE supplier_id = supplier.supplier_id AND product_category = v_supplier_type); + IF v_supplier_product_count < v_products_per_type_min THEN + L1: BEGIN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Type ' || v_supplier_type, + v_supplier_type, + 39.99, + 29.99, + supplier.supplier_id, + supplier.supplier_main_products || ' Contact', + supplier.supplier_main_products || ' Role', + '123 Type St', + 7, + 'Mixed', + 'Standard', + 0.8, + 'Type product', + 3.5, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_supplier_product_count = v_supplier_product_count + 1; + UNTIL v_supplier_product_count >= v_products_per_type_min END REPEAT; + END L1; + END IF; + END FOR; + END L0; + BEGIN + DECLARE v_no_match_product_count INT; + SET v_no_match_product_count = ( + SELECT COUNT(*) + FROM products p + JOIN suppliers s + ON p.supplier_id = s.supplier_id + WHERE p.product_category != s.supplier_main_products + ); + IF v_no_match_product_count > 0 THEN + L2: BEGIN + REPEAT + UPDATE products + SET product_category = ( + SELECT supplier_main_products + FROM suppliers + WHERE supplier_id = products.supplier_id + LIMIT 1 + ) + WHERE product_id = ( + SELECT MIN(product_id) + FROM products p + JOIN suppliers s + ON p.ssupplier_id = s.supplier_id + WHERE p.product_category != s.supplier_main_products + LIMIT 1 + ); + SET v_no_match_product_count = ( + SELECT COUNT(*) + FROM products p + JOIN suppliers s + ON p.supplier_id = s.supplier_id + WHERE p.product_category != s.supplier_main_products + ); + UNTIL v_no_match_product_count = 0 END REPEAT; + END L2; + END IF; + END; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, supplier-product-logic +-- EXPECTED: Random product inserts, supplier-category matching, DML +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 43 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_customer_zip_orders_total DOUBLE; + DECLARE v_zip_code STRING; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Customer zip order error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_zip_min_orders_total DOUBLE DEFAULT 100.0; + FOR zip AS SELECT DISTINCT customer_zip FROM customers LIMIT 3 DO + SET v_zip_code = zip.customer_zip; + SET v_customer_zip_orders_total = ( + SELECT SUM(order_total) + FROM orders + WHERE customer_id IN ( + SELECT customer_id + FROM customers + WHERE customer_zip = v_zip_code + ) + ); + IF v_customer_zip_orders_total < v_zip_min_orders_total THEN + L1: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers WHERE customer_zip = v_zip_code), + CURRENT_TIMESTAMP, + 'Zip Revenue', + 20.0, + 2.0, + 0.0, + 2.0 + ); + SET v_customer_zip_orders_total = ( + SELECT SUM(order_total) + FROM orders + WHERE customer_id IN ( + SELECT customer_id + FROM customers + WHERE customer_zip = v_zip_code + ) + ); + UNTIL v_customer_zip_orders_total >= v_zip_min_orders_total END REPEAT; + END L1; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, zip-revenue-logic +-- EXPECTED: Order inserts, local revenue control, DML +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 44 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_device_type STRING; + DECLARE v_device_order_count INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order device error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_min_device_orders INT DEFAULT 1; + FOR device AS SELECT DISTINCT order_device FROM orders LIMIT 3 DO + SET v_order_device_type = device.order_device; + SET v_device_order_count = (SELECT COUNT(*) FROM orders WHERE order_device = v_order_device_type); + IF v_device_order_count < v_min_device_orders THEN + L1: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping, + order_device + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Device Fill', + 15.0, + 1.5, + 0.0, + 2.0, + v_order_device_type + ); + SET v_device_order_count = v_device_order_count + 1; + UNTIL v_device_order_count >= v_min_device_orders END REPEAT; + END L1; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, device-logic +-- EXPECTED: Order inserts, device diversity, DML +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 45 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_product_cost DOUBLE; + DECLARE v_product_discount DOUBLE; + DECLARE v_low_margin_flag BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product margin error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_min_products_margin_check INT DEFAULT 2; + FOR product AS SELECT product_id, product_cost, product_discount FROM products LIMIT 3 DO + SET v_product_cost = product.product_cost; + SET v_product_discount = product.product_discount; + L1: BEGIN + DECLARE v_sale_price DOUBLE; + SET v_sale_price = (SELECT product_price FROM products WHERE product_id = product.product_id); + IF v_sale_price - v_product_cost < 10 THEN + SET v_low_margin_flag = true; + L2: BEGIN + REPEAT + UPDATE products + SET product_price = product_price * 1.05 + WHERE product_id = product.product_id; + SET v_sale_price = (SELECT product_price FROM products WHERE product_id = product.product_id); + UNTIL v_sale_price - v_product_cost >= 10 OR v_low_margin_flag = false END REPEAT; + END L2; + END IF; + IF v_product_discount > 0.1 AND v_low_margin_flag = true THEN + REPEAT + UPDATE products + SET product_discount = product_discount - 0.02 + WHERE product_id = product.product_id; + SET v_product_discount = (SELECT product_discount FROM products WHERE product_id = product.product_id); + UNTIL v_product_discount <= 0.1 END REPEAT; + END IF; + END L1; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, margin-logic +-- EXPECTED: Random price and discount updates, margin control, DML +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 46 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_item_count INT; + DECLARE v_order_id INT; + DECLARE v_order_total DOUBLE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order item counting error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + FOR order_id_row AS SELECT order_id FROM orders LIMIT 3 DO + SET v_order_id = order_id_row.order_id; + SET v_order_total = (SELECT order_total FROM orders WHERE order_id = v_order_id); + SET v_order_item_count = (SELECT COUNT(*) FROM order_items WHERE order_id = v_order_id); + IF v_order_item_count = 0 THEN + L1: BEGIN + REPEAT + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + v_order_id, + (SELECT MIN(product_id) FROM products), + 1, + 10.0, + 0.0, + 1.0, + 11.0 + ); + SET v_order_item_count = (SELECT COUNT(*) FROM order_items WHERE order_id = v_order_id); + UNTIL v_order_item_count > 0 END REPEAT; + END L1; + END IF; + IF v_order_total < 10 AND v_order_item_count > 0 THEN + L2: BEGIN + REPEAT + UPDATE orders + SET order_total = order_total + 5.0 + WHERE order_id = v_order_id; + SET v_order_total = (SELECT order_total FROM orders WHERE order_id = v_order_id); + UNTIL v_order_total >= 10 END REPEAT; + END L2; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, order-item-logic +-- EXPECTED: Order item and total updates, order content enforcement, DML +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 47 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_payment_balance DOUBLE; + DECLARE v_payment_status STRING; + DECLARE v_unpaid_orders INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order payment error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_payment_update_needed BOOLEAN DEFAULT false; + FOR payment_row AS SELECT order_id, order_total, order_tax, order_payment_status FROM orders LIMIT 3 DO + SET v_order_payment_balance = payment_row.order_total + payment_row.order_tax; + SET v_payment_status = payment_row.order_payment_status; + IF v_payment_status = 'Pending' AND v_order_payment_balance > 20 THEN + L1: BEGIN + SET v_payment_update_needed = true; + REPEAT + UPDATE orders + SET order_payment_status = 'Paid' + WHERE order_id = payment_row.order_id; + SET v_payment_status = (SELECT order_payment_status FROM orders WHERE order_id = payment_row.order_id); + UNTIL v_payment_status != 'Pending' OR v_payment_update_needed = false END REPEAT; + END L1; + END IF; + END FOR; + END L0; + BEGIN + SET v_unpaid_orders = (SELECT COUNT(*) FROM orders WHERE order_payment_status = 'Pending' AND (order_total + order_tax) > 20); + IF v_unpaid_orders > 0 THEN + L2: BEGIN + REPEAT + INSERT INTO customers ( + customer_id, + customer_name, + customer_email, + customer_phone, + customer_address_1, + customer_city, + customer_state, + customer_zip, + customer_country, + customer_type, + customer_total_spent, + customer_active_status + ) VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Pending Payee', + 'pending@payment.com', + '555-0000', + '123 Pending St', + 'Paymentville', + 'CA', + '00000', + 'USA', + 'Wholesale', + 0.0, + true + ); + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping, + order_payment_status + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MAX(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Generated', + 25.0, + 2.5, + 0.0, + 3.0, + 'Pending' + ); + SET v_unpaid_orders = v_unpaid_orders - 1; + UNTIL v_unpaid_orders = 0 END REPEAT; + END L2; + END IF; + END; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, payment-logic +-- EXPECTED: Payment status updates, customer/order inserts, unpaid order control +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 48 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_supplier_active BOOLEAN; + DECLARE v_suppliers_per_region_target INT DEFAULT 2; + DECLARE v_region_suppliers_current INT; + DECLARE v_region_to_balance STRING; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier region error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + FOR region AS SELECT DISTINCT supplier_region FROM suppliers LIMIT 3 DO + SET v_region_to_balance = region.supplier_region; + SET v_region_suppliers_current = (SELECT COUNT(*) FROM suppliers WHERE supplier_active = true AND supplier_region = v_region_to_balance); + IF v_region_suppliers_current < v_suppliers_per_region_target THEN + L1: BEGIN + REPEAT + INSERT INTO suppliers VALUES ( + (SELECT MAX(supplier_id) + 1 FROM suppliers), + 'Regional Filler', + 'Regional Manager', + 'Contact Role', + 'region_' || v_region_to_balance || '@example.com', + '555-0001', + '123 Regional St', + 'Regional City', + 'CA', + '00000', + 'USA', + v_region_to_balance, + 'Diverse', + 'http://regional.com', + CURRENT_TIMESTAMP, + NULL, + NULL, + 4.0, + true + ); + SET v_region_suppliers_current = (SELECT COUNT(*) FROM suppliers WHERE supplier_active = true AND supplier_region = v_region_to_balance); + UNTIL v_region_suppliers_current >= v_suppliers_per_region_target END REPEAT; + END L1; + END IF; + END FOR; + END L0; + BEGIN + DECLARE v_no_region_suppliers_count INT; + SET v_no_region_suppliers_count = (SELECT COUNT(DISTINCT supplier_region) FROM suppliers); + IF v_no_region_suppliers_count < 5 THEN + L2: BEGIN + REPEAT + INSERT INTO suppliers VALUES ( + (SELECT MAX(supplier_id) + 1 FROM suppliers), + 'New Region Corp', + 'Region Manager', + 'Contact', + 'newregion@example.com', + '555-0002', + '123 Main St', + 'New City', + 'CA', + '00001', + 'USA', + CONCAT('Region_', v_no_region_suppliers_count + 1), + 'General', + 'http://newregion.com', + CURRENT_TIMESTAMP, + NULL, + NULL, + 4.5, + true + ); + SET v_no_region_suppliers_count = (SELECT COUNT(DISTINCT supplier_region) FROM suppliers); + UNTIL v_no_region_suppliers_count >= 5 END REPEAT; + END L2; + END IF; + END; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, region-logic +-- EXPECTED: Supplier inserts, region balancing, diversity control +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 49 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_product_color_diversity INT; + DECLARE v_color_product_count INT; + DECLARE v_color_to_boost STRING; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Color diversity error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_min_color_products INT DEFAULT 2; + FOR color AS SELECT DISTINCT product_color FROM products LIMIT 3 DO + SET v_color_to_boost = color.product_color; + SET v_color_product_count = (SELECT COUNT(*) FROM products WHERE product_color = v_color_to_boost); + IF v_color_product_count < v_min_color_products THEN + L1: BEGIN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Boost ' || v_color_to_boost, + 'Diverse', + 29.99, + 19.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Color Contact', + 'Color Role', + '123 Color St', + 5, + v_color_to_boost, + 'Standard', + 0.7, + 'Diverse color', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.05, + 0.19 + ); + SET v_color_product_count = (SELECT COUNT(*) FROM products WHERE product_color = v_color_to_boost); + UNTIL v_color_product_count >= v_min_color_products END REPEAT; + END L1; + END IF; + END FOR; + END L0; + BEGIN + SET v_product_color_diversity = (SELECT COUNT(DISTINCT product_color) FROM products); + IF v_product_color_diversity < 6 THEN + L2: BEGIN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Colorful New', + 'General', + 24.99, + 14.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Diverse Contact', + 'Diverse Role', + '123 Diverse St', + 8, + CASE v_product_color_diversity + WHEN 0 THEN 'Red' + WHEN 1 THEN 'Green' + WHEN 2 THEN 'Blue' + WHEN 3 THEN 'Yellow' + WHEN 4 THEN 'Purple' + ELSE 'Orange' + END, + 'Small', + 0.5, + 'Expanding diversity', + 3.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_product_color_diversity = (SELECT COUNT(DISTINCT product_color) FROM products); + UNTIL v_product_color_diversity >= 6 END REPEAT; + END L2; + END IF; + END; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, color-diversity +-- EXPECTED: Product color diversity, inserts, DML +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 50 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_product_origin_diversity INT; + DECLARE v_origin_supplier_pairs INT; + DECLARE v_origin_to_activate STRING; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product origin error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_min_origin_types INT DEFAULT 3; + SET v_product_origin_diversity = (SELECT COUNT(DISTINCT supplier_country) FROM products p JOIN suppliers s ON p.supplier_id = s.supplier_id); + IF v_product_origin_diversity < v_min_origin_types THEN + L1: BEGIN + REPEAT + SET v_origin_to_activate = CASE v_product_origin_diversity + WHEN 0 THEN 'Canada' + WHEN 1 THEN 'Mexico' + WHEN 2 THEN 'UK' + ELSE 'Australia' + END; + INSERT INTO suppliers VALUES ( + (SELECT MAX(supplier_id) + 1 FROM suppliers), + v_origin_to_activate || ' Exports', + 'Export Manager', + 'Contact', + 'exports@' || LOWER(v_origin_to_activate) || '.com', + '555-0003', + '123 Export St', + v_origin_to_activate || ' City', + v_origin_to_activate, + '00000', + v_origin_to_activate, + v_origin_to_activate, + 'General', + 'http://exports.com', + CURRENT_TIMESTAMP, + NULL, + NULL, + 4.0, + true + ); + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + v_origin_to_activate || ' Import', + 'Specialty', + 34.99, + 24.99, + (SELECT MAX(supplier_id) FROM suppliers WHERE supplier_country = v_origin_to_activate), + 'Importer', + 'Import Role', + '123 Import St', + 4, + 'Any', + 'Medium', + 0.6, + 'Imported', + 4.5, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_product_origin_diversity = (SELECT COUNT(DISTINCT supplier_country) FROM products p JOIN suppliers s ON p.supplier_id = s.supplier_id); + UNTIL v_product_origin_diversity >= v_min_origin_types END REPEAT; + END L1; + END IF; + SET v_origin_supplier_pairs = (SELECT COUNT(*) FROM products p JOIN suppliers s ON p.supplier_id = s.supplier_id WHERE p.product_category = 'Specialty'); + IF v_origin_supplier_pairs < 2 THEN + L2: BEGIN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Diverse Import', + 'Specialty', + 39.99, + 29.99, + (SELECT MIN(supplier_id) FROM suppliers WHERE supplier_country != 'USA'), + 'Diverse Contact', + 'Diverse Role', + '123 Diverse St', + 5, + 'Multi', + 'Large', + 0.8, + 'Diverse', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_origin_supplier_pairs = (SELECT COUNT(*) FROM products p JOIN suppliers s ON p.supplier_id = s.supplier_id WHERE p.product_category = 'Specialty'); + UNTIL v_origin_supplier_pairs >= 2 END REPEAT; + END L2; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, REPEAT, DML, deep-nesting, exception-handler, origin-diversity +-- EXPECTED: Product and supplier origin diversity, international coverage, DML +-- EXECUTES: FOR, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 51 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_customer_city STRING; + DECLARE v_city_order_count INT; + DECLARE v_city_supplier_count INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('City order diversity error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_min_orders_per_city INT DEFAULT 1; + DECLARE v_min_suppliers_per_city INT DEFAULT 1; + FOR city AS SELECT DISTINCT customer_city FROM customers LIMIT 3 DO + SET v_customer_city = city.customer_city; + SET v_city_order_count = (SELECT COUNT(*) FROM orders WHERE customer_id IN (SELECT customer_id FROM customers WHERE customer_city = v_customer_city)); + IF v_city_order_count = 0 THEN + L1: BEGIN + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers WHERE customer_city = v_customer_city), + CURRENT_TIMESTAMP, + 'City Fill', + 25.0, + 2.5, + 0.0, + 2.5 + ); + SET v_city_order_count = (SELECT COUNT(*) FROM orders WHERE customer_id IN (SELECT customer_id FROM customers WHERE customer_city = v_customer_city)); + END L1; + L2: BEGIN + SET v_city_supplier_count = (SELECT COUNT(*) FROM suppliers WHERE supplier_city = v_customer_city); + IF v_city_supplier_count = 0 THEN + INSERT INTO suppliers VALUES ( + (SELECT MAX(supplier_id) + 1 FROM suppliers), + 'City ' || v_customer_city, + 'City Contact', + 'City Role', + 'city@example.com', + '555-0000', + '123 City St', + v_customer_city, + 'CA', + '00000', + 'USA', + v_customer_city, + 'General', + 'http://city.com', + CURRENT_TIMESTAMP, + NULL, + NULL, + 4.0, + true + ); + SET v_city_supplier_count = v_city_supplier_count + 1; + END IF; + END L2; + END IF; + IF EXISTS (SELECT 1 FROM customers WHERE customer_city = v_customer_city) THEN + L3: BEGIN + CASE + WHEN v_city_order_count % 2 = 0 THEN + UPDATE customers + SET customer_active_status = true + WHERE customer_city = v_customer_city; + ELSE + UPDATE customers + SET customer_active_status = false + WHERE customer_city = v_customer_city + AND customer_id = ( + SELECT MIN(customer_id) + FROM customers + WHERE customer_city = v_customer_city + ); + END CASE; + END L3; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, CASE, DML, deep-nesting, exception-handler, city-diversity-logic +-- EXPECTED: Order, supplier, and status updates, city diversity, DML +-- EXECUTES: FOR, IF, CASE, nested BEGIN...END, exception handler + +-- Script 52 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_product_size STRING; + DECLARE v_size_variety INT; + DECLARE v_new_sizes_to_add INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product size error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + SET v_size_variety = (SELECT COUNT(DISTINCT product_size) FROM products); + SET v_new_sizes_to_add = 5 - v_size_variety; + IF v_new_sizes_to_add > 0 THEN + L1: BEGIN + WHILE v_new_sizes_to_add > 0 DO + SET v_product_size = CASE v_new_sizes_to_add + WHEN 5 THEN 'XS' + WHEN 4 THEN 'S' + WHEN 3 THEN 'M' + WHEN 2 THEN 'L' + WHEN 1 THEN 'XL' + END; + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Size Booster ' || v_product_size, + 'Diverse', + 24.99, + 14.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Diverse Contact', + 'Size Role', + '123 Size St', + 6, + 'Blue', + v_product_size, + 0.6, + 'Size variety', + 3.5, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.05, + 0.19 + ); + SET v_new_sizes_to_add = v_new_sizes_to_add - 1; + SET v_size_variety = (SELECT COUNT(DISTINCT product_size) FROM products); + END WHILE; + END L1; + END IF; + L2: BEGIN + FOR size AS SELECT DISTINCT product_size FROM products LIMIT 1 DO + SET v_product_size = size.product_size; + IF (SELECT COUNT(*) FROM products WHERE product_size = v_product_size) < 2 THEN + BEGIN + SET v_new_sizes_to_add = 2 - (SELECT COUNT(*) FROM products WHERE product_size = v_product_size); + WHILE v_new_sizes_to_add > 0 DO + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Extra ' || v_product_size, + 'General', + 29.99, + 19.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Extra Contact', + 'Extra Role', + '123 Extra St', + 4, + 'Red', + v_product_size, + 0.5, + 'Extra size', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_new_sizes_to_add = v_new_sizes_to_add - 1; + END WHILE; + END; + END IF; + END FOR; + END L2; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, CASE, WHILE, DML, deep-nesting, exception-handler, size-diversity-logic +-- EXPECTED: Product size balancing, inserts, size coverage enforcement, DML +-- EXECUTES: FOR, IF, CASE, WHILE, nested BEGIN...END, exception handler + +-- Script 53 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_customer_country STRING; + DECLARE v_country_order_count INT; + DECLARE v_country_supplier_count INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Country diversity error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_min_orders_per_country INT DEFAULT 1; + DECLARE v_min_suppliers_per_country INT DEFAULT 1; + FOR country AS SELECT DISTINCT customer_country FROM customers LIMIT 3 DO + SET v_customer_country = country.customer_country; + SET v_country_order_count = (SELECT COUNT(*) FROM orders WHERE customer_id IN (SELECT customer_id FROM customers WHERE customer_country = v_customer_country)); + IF v_country_order_count < v_min_orders_per_country THEN + L1: BEGIN + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers WHERE customer_country = v_customer_country), + CURRENT_TIMESTAMP, + 'Country Fill', + 20.0, + 2.0, + 0.0, + 2.0 + ); + END L1; + END IF; + BEGIN + DECLARE v_country_customer_count INT; + SET v_country_customer_count = (SELECT COUNT(*) FROM customers WHERE customer_country = v_customer_country); + IF v_country_customer_count < 2 THEN + L2: BEGIN + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Country ' || v_customer_country, + 'country_' || LOWER(v_customer_country) || '@example.com', + '555-0000', + '123 Country St', + 'Country City', + v_customer_country, + '00000', + v_customer_country, + 'Retail', + CURRENT_TIMESTAMP, + 0.0, + NULL, + NULL, + NULL, + true, + true, + 0.0, + NULL, + NULL + ); + END L2; + END IF; + END; + SET v_country_supplier_count = (SELECT COUNT(*) FROM suppliers WHERE supplier_country = v_customer_country); + IF v_country_supplier_count < v_min_suppliers_per_country THEN + L3: BEGIN + INSERT INTO suppliers VALUES ( + (SELECT MAX(supplier_id) + 1 FROM suppliers), + v_customer_country || ' Supplier', + 'Supplier Contact', + 'Supplier Role', + 'supplier@' || LOWER(v_customer_country) || '.com', + '555-0001', + '123 Supplier St', + 'Supplier City', + v_customer_country, + '00000', + v_customer_country, + v_customer_country, + 'General', + 'http://supplier.com', + CURRENT_TIMESTAMP, + NULL, + NULL, + 4.0, + true + ); + END L3; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, DML, deep-nesting, exception-handler, country-diversity +-- EXPECTED: Order, customer, and supplier inserts, country diversity, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 54 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_product_weight DOUBLE; + DECLARE v_product_category STRING; + DECLARE v_category_weights INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Category weight error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_min_category_weight_count INT DEFAULT 3; + FOR category AS SELECT DISTINCT product_category FROM products LIMIT 3 DO + SET v_product_category = category.product_category; + SET v_category_weights = (SELECT COUNT(*) FROM products WHERE product_category = v_product_category AND product_weight IS NOT NULL); + IF v_category_weights < v_min_category_weight_count THEN + L1: BEGIN + BEGIN + DECLARE v_weight_to_set DOUBLE; + SET v_weight_to_set = 0.5 + (SELECT COUNT(*) FROM products WHERE product_category = v_product_category); + WHILE v_weight_to_set < 2.5 DO + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + v_product_category || ' Weight', + v_product_category, + 39.99, + 29.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Weight Contact', + 'Weight Role', + '123 Weight St', + 4, + CASE WHEN MOD((SELECT COUNT(*) FROM products WHERE product_category = v_product_category), 2) = 0 THEN 'Black' ELSE 'Gray' END, + 'Standard', + v_weight_to_set, + 'Weighted item', + 3.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_weight_to_set = v_weight_to_set + 0.2; + SET v_category_weights = v_category_weights + 1; + END WHILE; + END; + END L1; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, WHILE, DML, deep-nesting, exception-handler, weight-diversity +-- EXPECTED: Product weight inserts, weight diversity, DML +-- EXECUTES: FOR, IF, WHILE, nested BEGIN...END, exception handler + +-- Script 55 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_customer_opt_in BOOLEAN; + DECLARE v_opt_in_count INT; + DECLARE v_no_opt_in_count INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Opt-in error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + SET v_opt_in_count = (SELECT COUNT(*) FROM customers WHERE customer_opt_in_newsletter = true); + SET v_no_opt_in_count = (SELECT COUNT(*) FROM customers WHERE customer_opt_in_newsletter = false); + IF v_no_opt_in_count > v_opt_in_count THEN + L1: BEGIN + FOR customer AS SELECT customer_id FROM customers WHERE customer_opt_in_newsletter = false LIMIT 2 DO + IF v_no_opt_in_count > v_opt_in_count THEN + BEGIN + UPDATE customers + SET customer_opt_in_newsletter = true + WHERE customer_id = customer.customer_id; + SET v_opt_in_count = v_opt_in_count + 1; + SET v_no_opt_in_count = v_no_opt_in_count - 1; + END; + ELSE + BEGIN + DECLARE v_new_customer_id INT; + SET v_new_customer_id = (SELECT MAX(customer_id) + 1 FROM customers); + INSERT INTO customers VALUES ( + v_new_customer_id, + 'New Subscriber', + 'subscriber@example.com', + '555-0002', + '123 Subscriber St', + 'Newsletterville', + 'CA', + '00000', + 'USA', + 'Retail', + CURRENT_TIMESTAMP, + 0.0, + NULL, + NULL, + NULL, + true, + true, + 0.0, + NULL, + NULL + ); + SET v_opt_in_count = v_opt_in_count + 1; + END; + END IF; + END FOR; + END L1; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, DML, deep-nesting, exception-handler, opt-in-logic +-- EXPECTED: Opt-in updates, customer inserts, opt-in balance, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 56 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_customer_city STRING; + DECLARE v_city_customer_age INT; + DECLARE v_average_customer_age DOUBLE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Customer age diversity error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_min_cities_for_age_diversity INT DEFAULT 3; + FOR city AS SELECT DISTINCT customer_city FROM customers LIMIT v_min_cities_for_age_diversity DO + SET v_customer_city = city.customer_city; + BEGIN + SET v_average_customer_age = (SELECT AVG(DATEDIFF(YEAR, customer_birth_date, CURRENT_TIMESTAMP)) FROM customers WHERE customer_city = v_customer_city); + IF v_average_customer_age IS NULL THEN + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Balanced City Customer', + 'balanced@city.com', + '555-0001', + '123 Balance St', + v_customer_city, + 'CA', + '00000', + 'USA', + 'Retail', + CURRENT_TIMESTAMP, + 0.0, + NULL, + DATEADD(YEAR, -35, CURRENT_TIMESTAMP), + NULL, + true, + true, + 0.0, + NULL, + NULL + ); + SET v_average_customer_age = (SELECT AVG(DATEDIFF(YEAR, customer_birth_date, CURRENT_TIMESTAMP)) FROM customers WHERE customer_city = v_customer_city); + END IF; + IF v_average_customer_age < 25 THEN + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Older City Customer', + 'older@city.com', + '555-0002', + '123 Senior St', + v_customer_city, + 'CA', + '00000', + 'USA', + 'Retail', + CURRENT_TIMESTAMP, + 0.0, + NULL, + DATEADD(YEAR, -50, CURRENT_TIMESTAMP), + NULL, + true, + true, + 0.0, + NULL, + NULL + ); + SET v_average_customer_age = (SELECT AVG(DATEDIFF(YEAR, customer_birth_date, CURRENT_TIMESTAMP)) FROM customers WHERE customer_city = v_customer_city); + END IF; + IF v_average_customer_age > 40 THEN + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Younger City Customer', + 'younger@city.com', + '555-0003', + '123 Junior St', + v_customer_city, + 'CA', + '00000', + 'USA', + 'Retail', + CURRENT_TIMESTAMP, + 0.0, + NULL, + DATEADD(YEAR, -20, CURRENT_TIMESTAMP), + NULL, + true, + true, + 0.0, + NULL, + NULL + ); + SET v_average_customer_age = (SELECT AVG(DATEDIFF(YEAR, customer_birth_date, CURRENT_TIMESTAMP)) FROM customers WHERE customer_city = v_customer_city); + END IF; + END; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, DML, deep-nesting, exception-handler, age-diversity +-- EXPECTED: Customer age inserts, city age balancing, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 57 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_product_review DOUBLE; + DECLARE v_product_rating DOUBLE; + DECLARE v_reviews_per_category INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product review/rating error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + DECLARE v_min_reviews_per_category INT DEFAULT 1; + FOR category AS SELECT DISTINCT product_category FROM products LIMIT 3 DO + SET v_reviews_per_category = (SELECT SUM(product_reviews) FROM products WHERE product_category = category.product_category); + SET v_product_rating = (SELECT AVG(product_rating) FROM products WHERE product_category = category.product_category); + L1: BEGIN + IF v_reviews_per_category < v_min_reviews_per_category THEN + BEGIN + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Review Filler', + category.product_category, + 39.99, + 29.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Review Contact', + 'Review Role', + '123 Reviews St', + 6, + 'Blue', + 'Large', + 1.2, + 'Filled with reviews', + 4.0, + 25, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_reviews_per_category = v_reviews_per_category + 25; + END; + END IF; + IF v_product_rating IS NULL OR v_product_rating < 3.0 THEN + BEGIN + UPDATE products + SET product_rating = 4.0 + WHERE product_category = category.product_category AND product_reviews > 0; + SET v_product_rating = (SELECT AVG(product_rating) FROM products WHERE product_category = category.product_category); + END; + END IF; + END L1; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, DML, deep-nesting, exception-handler, review-diversity +-- EXPECTED: Product review and rating updates, review coverage, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 58 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_product_id INT; + DECLARE v_product_description STRING; + DECLARE v_description_length INT; + DECLARE v_descriptive_product_count INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Description diversity error'); END; + + L0: BEGIN + DECLARE v_min_description_length INT DEFAULT 20; + DECLARE v_max_description_length INT DEFAULT 100; + DECLARE v_target_descriptive_products INT DEFAULT 5; + FOR product AS SELECT product_id, product_description FROM products LIMIT 3 DO + SET v_product_id = product.product_id; + SET v_product_description = product.product_description; + SET v_description_length = LENGTH(v_product_description); + CASE + WHEN v_description_length < v_min_description_length THEN + L1: BEGIN + DECLARE v_word_count INT DEFAULT v_min_description_length - v_description_length; + DECLARE v_new_description STRING; + REPEAT + SET v_new_description = CONCAT(v_product_description, ' detail'); + SET v_word_count = v_word_count - 1; + UNTIL v_word_count <= 0 + END REPEAT; + UPDATE products + SET product_description = v_new_description + WHERE product_id = v_product_id; + SET v_descriptive_product_count = v_descriptive_product_count + 1; + END L1; + WHEN v_description_length > v_max_description_length THEN + BEGIN + UPDATE products + SET product_description = SUBSTRING(product_description, 1, v_max_description_length) + WHERE product_id = v_product_id; + END; + ELSE + SET v_descriptive_product_count = v_descriptive_product_count + 1; + END CASE; + END FOR; + IF v_descriptive_product_count < v_target_descriptive_products THEN + L2: BEGIN + DECLARE v_new_product_num INT DEFAULT v_target_descriptive_products - v_descriptive_product_count; + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Item with Long Description', + 'General', + 29.99, + 19.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Description Contact', + 'Description Role', + '123 Desc St', + 4, + 'Blue', + 'Medium', + 0.8, + 'This product has a long, detailed, and diverse description to maintain variability in the dataset.', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_new_product_num = v_new_product_num - 1; + UNTIL v_new_product_num <= 0 + END REPEAT; + END L2; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, CASE, REPEAT, IF, DML, deep-nesting, exception-handler, description-diversity +-- EXPECTED: Product description diversity, updates and inserts, DML +-- EXECUTES: FOR, CASE, REPEAT, IF, nested BEGIN...END, exception handler + +-- Script 59 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_item_status_nulls INT DEFAULT 0; + DECLARE v_order_id INT; + DECLARE v_order_item_id INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order item status error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + SET v_order_item_status_nulls = (SELECT COUNT(*) FROM order_items WHERE item_status IS NULL); + IF v_order_item_status_nulls > 0 THEN + L1: BEGIN + FOR order_item AS SELECT order_id, order_item_id FROM order_items WHERE item_status IS NULL LIMIT 2 DO + SET v_order_id = order_item.order_id; + SET v_order_item_id = order_item.order_item_id; + BEGIN + DECLARE v_order_status STRING; + SET v_order_status = (SELECT order_status FROM orders WHERE order_id = v_order_id); + CASE v_order_status + WHEN 'Completed' THEN + UPDATE order_items + SET item_status = 'Shipped' + WHERE order_item_id = v_order_item_id AND order_id = v_order_id; + WHEN 'Processing' THEN + UPDATE order_items + SET item_status = 'Preparing' + WHERE order_item_id = v_order_item_id AND order_id = v_order_id; + ELSE + UPDATE order_items + SET item_status = 'Received' + WHERE order_item_id = v_order_item_id AND order_id = v_order_id; + END CASE; + END; + END FOR; + SET v_order_item_status_nulls = (SELECT COUNT(*) FROM order_items WHERE item_status IS NULL); + IF v_order_item_status_nulls > 1 THEN + REPEAT + UPDATE order_items + SET item_status = 'Cancelled' + WHERE order_item_id = (SELECT MIN(order_item_id) FROM order_items WHERE item_status IS NULL); + SET v_order_item_status_nulls = (SELECT COUNT(*) FROM order_items WHERE item_status IS NULL); + UNTIL v_order_item_status_nulls <= 1 + END REPEAT; + END IF; + END L1; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, CASE, IF, REPEAT, DML, deep-nesting, exception-handler, status-diversity +-- EXPECTED: Item status filling, status logic, DML +-- EXECUTES: FOR, CASE, IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 60 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_customer_is_prime BOOLEAN DEFAULT false; + DECLARE v_prime_customer_count INT; + DECLARE v_min_prime_customers INT DEFAULT 2; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Prime customer error'); END; + + L0: BEGIN + SET v_prime_customer_count = (SELECT COUNT(*) FROM customers WHERE customer_is_prime_member = true); + IF v_prime_customer_count < v_min_prime_customers THEN + FOR cust AS SELECT customer_id FROM customers WHERE customer_is_prime_member IS NULL LIMIT v_min_prime_customers DO + UPDATE customers + SET customer_is_prime_member = true, + customer_prime_customer_since = CURRENT_TIMESTAMP + WHERE customer_id = cust.customer_id; + SET v_customer_is_prime = true; + END FOR; + IF v_customer_is_prime = false AND v_prime_customer_count < v_min_prime_customers THEN + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Prime Customer', + 'prime@example.com', + '555-0000', + '123 Prime St', + 'Prime City', + 'CA', + '00000', + 'USA', + 'Retail', + CURRENT_TIMESTAMP, + 0.0, + NULL, + NULL, + NULL, + true, + true, + 0.0, + CURRENT_TIMESTAMP, + NULL, + true + ); + SET v_customer_is_prime = true; + END IF; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, DML, deep-nesting, exception-handler, prime-customer-logic +-- EXPECTED: Prime customer status updates/inserts, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 61 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_employee_department STRING; + DECLARE v_department_commission_total DOUBLE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Department commission error'); END; + + -- Wide, deep, random logic, labels + L0: BEGIN + FOR dept AS SELECT DISTINCT employee_department FROM employees LIMIT 2 DO + SET v_employee_department = dept.employee_department; + SET v_department_commission_total = (SELECT SUM(employee_commission) FROM employees WHERE employee_department = v_employee_department); + BEGIN + DECLARE v_commission_threshold DOUBLE DEFAULT 2000; + IF v_department_commission_total > v_commission_threshold THEN + L1: BEGIN + DECLARE v_commission_excess DOUBLE; + SET v_commission_excess = v_department_commission_total - v_commission_threshold; + WHILE v_commission_excess > 0 DO + SET v_commission_threshold = v_commission_threshold + 100; + UPDATE employees + SET employee_commission = employee_commission * 0.9 + WHERE employee_department = v_employee_department; + SET v_department_commission_total = (SELECT SUM(employee_commission) FROM employees WHERE employee_department = v_employee_department); + SET v_commission_excess = v_department_commission_total - v_commission_threshold; + END WHILE; + END L1; + END IF; + END; + END FOR; + BEGIN + DECLARE v_no_commission_employees INT; + SET v_no_commission_employees = (SELECT COUNT(*) FROM employees WHERE employee_commission IS NULL OR employee_commission = 0); + IF v_no_commission_employees > 0 THEN + REPEAT + UPDATE employees + SET employee_commission = 100 + WHERE employee_id = (SELECT MIN(employee_id) FROM employees WHERE employee_commission IS NULL OR employee_commission = 0); + SET v_no_commission_employees = v_no_commission_employees - 1; + UNTIL v_no_commission_employees <= 1 + END REPEAT; + END IF; + END; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, WHILE, REPEAT, DML, deep-nesting, exception-handler, commission-diversity +-- EXPECTED: Commission balancing, updates, null handling, DML +-- EXECUTES: FOR, IF, WHILE, REPEAT, nested BEGIN...END, exception handler + +-- Script 62 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_item_customizable_flag BOOLEAN DEFAULT false; + DECLARE v_customizable_order_items_count INT; + DECLARE v_min_customizable_items INT DEFAULT 2; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Customizable item error'); END; + + L0: BEGIN + SET v_customizable_order_items_count = (SELECT COUNT(*) FROM order_items WHERE item_customization IS NOT NULL); + IF v_customizable_order_items_count < v_min_customizable_items THEN + FOR oi AS SELECT order_item_id FROM order_items WHERE item_customization IS NULL LIMIT v_min_customizable_items DO + UPDATE order_items + SET item_customization = CASE + WHEN MOD(oi.order_item_id, 2) = 0 THEN 'Engraved' + ELSE 'Monogrammed' + END + WHERE order_item_id = oi.order_item_id; + SET v_order_item_customizable_flag = true; + END FOR; + IF v_order_item_customizable_flag = false AND v_customizable_order_items_count < v_min_customizable_items THEN + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total, + item_customization + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MIN(order_id) FROM orders), + (SELECT MIN(product_id) FROM products), + 1, + 10.0, + 0.0, + 1.0, + 11.0, + 'Engraved' + ); + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total, + item_customization + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MIN(order_id) FROM orders), + (SELECT MIN(product_id) FROM products), + 1, + 10.0, + 0.0, + 1.0, + 11.0, + 'Monogrammed' + ); + END IF; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, DML, deep-nesting, exception-handler, customizable-item-logic +-- EXPECTED: Customized order item updates/inserts, item personalization, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 63 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_status STRING; + DECLARE v_orders_with_items INT; + DECLARE v_empty_orders INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order-item linkage error'); END; + + L0: BEGIN + SET v_orders_with_items = (SELECT COUNT(DISTINCT oi.order_id) FROM order_items oi); + SET v_empty_orders = (SELECT COUNT(*) FROM orders o WHERE NOT EXISTS (SELECT 1 FROM order_items oi WHERE oi.order_id = o.order_id)); + IF v_empty_orders > 0 THEN + L1: BEGIN + FOR empty_order AS SELECT order_id FROM orders o WHERE NOT EXISTS (SELECT 1 FROM order_items oi WHERE oi.order_id = o.order_id) LIMIT 2 DO + SET v_order_status = (SELECT order_status FROM orders WHERE order_id = empty_order.order_id); + L2: BEGIN + CASE + WHEN v_order_status = 'Completed' THEN + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + empty_order.order_id, + (SELECT MIN(product_id) FROM products), + 1, + 10.0, + 0.0, + 1.0, + 11.0 + ); + WHEN v_order_status = 'Processing' THEN + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total, + item_status + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + empty_order.order_id, + (SELECT MIN(product_id) FROM products), + 1, + 10.0, + 0.0, + 1.0, + 11.0, + 'Preparing' + ); + ELSE + BEGIN + DECLARE v_product_id INT; + SET v_product_id = (SELECT product_id FROM products WHERE product_category = 'Specialty' LIMIT 1); + IF v_product_id IS NULL THEN + SET v_product_id = (SELECT MIN(product_id) FROM products); + END IF; + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total, + item_status + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + empty_order.order_id, + v_product_id, + 1, + 20.0, + 0.0, + 2.0, + 22.0, + CASE + WHEN RANDOM() > 0.5 THEN 'Shipped' + ELSE 'Processing' + END + ); + END; + END CASE; + END L2; + SET v_empty_orders = v_empty_orders - 1; + END FOR; + END L1; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, CASE, DML, deep-nesting, exception-handler, order-item-linkage +-- EXPECTED: Order-item binding, status-based item creation, DML +-- EXECUTES: FOR, IF, CASE, nested BEGIN...END, exception handler + +-- Script 64 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_supplier_site_count INT; + DECLARE v_site_char_length INT; + DECLARE v_min_site_length INT DEFAULT 8; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier site error'); END; + + L0: BEGIN + SET v_supplier_site_count = (SELECT COUNT(*) FROM suppliers WHERE supplier_website IS NOT NULL); + IF v_supplier_site_count < 5 THEN + L1: BEGIN + FOR s1 AS SELECT supplier_id FROM suppliers WHERE supplier_website IS NULL OR supplier_website = '' LIMIT 3 DO + SET v_site_char_length = (SELECT LENGTH(supplier_website) FROM suppliers WHERE supplier_id = s1.supplier_id); + IF v_site_char_length < v_min_site_length THEN + L2: BEGIN + IF EXISTS (SELECT 1 FROM suppliers WHERE supplier_id = s1.supplier_id) THEN + UPDATE suppliers + SET supplier_website = CONCAT('https://', REPLACE(LOWER(supplier_name), ' ', ''), '.com') + WHERE supplier_id = s1.supplier_id; + END IF; + END L2; + END IF; + SET v_supplier_site_count = (SELECT COUNT(*) FROM suppliers WHERE supplier_website IS NOT NULL); + IF v_supplier_site_count >= 5 THEN + LEAVE L1; + END IF; + END FOR; + END L1; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, LEAVE, DML, deep-nesting, exception-handler, website-logic +-- EXPECTED: Supplier website diversity, format updates, DML +-- EXECUTES: FOR, IF, LEAVE, nested BEGIN...END, exception handler + +-- Script 65 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_product_units_sold DOUBLE; + DECLARE v_category_products_sold INT; + DECLARE v_sale_regrowth BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Inventory movement error'); END; + + L0: BEGIN + FOR cat AS SELECT DISTINCT product_category FROM products LIMIT 3 DO + SET v_product_units_sold = (SELECT SUM(oi.item_quantity) FROM order_items oi JOIN products p ON oi.product_id = p.product_id WHERE p.product_category = cat.product_category); + SET v_category_products_sold = (SELECT COUNT(DISTINCT p.product_id) FROM order_items oi JOIN products p ON oi.product_id = p.product_id WHERE p.product_category = cat.product_category); + IF v_product_units_sold < 10 THEN + L1: BEGIN + WHILE v_product_units_sold < 20 AND v_category_products_sold < 2 DO + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Fast-Moving ' || cat.product_category, + cat.product_category, + 35.99, + 25.99, + (SELECT MIN(supplier_id) FROM suppliers WHERE supplier_main_products LIKE '%' || cat.product_category || '%'), + 'Movement Contact', + 'Movement Role', + '123 Moving St', + 8, + 'Any', + 'Any', + 0.7, + 'Fast mover', + 4.5, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_category_products_sold = v_category_products_sold + 1; + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MIN(order_id) FROM orders), + (SELECT MAX(product_id) FROM products WHERE product_category = cat.product_category), + 2, + 35.99, + 0.0, + 2.0, + 37.99 + ); + SET v_product_units_sold = v_product_units_sold + 2; + END WHILE; + SET v_sale_regrowth = true; + END L1; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, WHILE, DML, deep-nesting, exception-handler, sales-velocity +-- EXPECTED: Product and sales velocity inserts, category balancing, DML +-- EXECUTES: FOR, WHILE, nested BEGIN...END, exception handler + +-- Script 66 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_supplier_product_match INT; + DECLARE v_is_supplier_core BOOLEAN; + DECLARE v_product_supplier_missing BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier-product match error'); END; + + L0: BEGIN + FOR sup AS SELECT supplier_id, supplier_main_products FROM suppliers LIMIT 2 DO + SET v_supplier_product_match = (SELECT COUNT(*) FROM products p WHERE p.supplier_id = sup.supplier_id AND p.product_category = sup.supplier_main_products); + IF v_supplier_product_match = 0 THEN + L1: BEGIN + SET v_is_supplier_core = (sup.supplier_main_products IS NOT NULL AND sup.supplier_main_products != ''); + IF v_is_supplier_core THEN + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + sup.supplier_main_products || ' Special', + sup.supplier_main_products, + 44.99, + 34.99, + sup.supplier_id, + sup.supplier_name, + 'Product Specialist', + '123 Main St', + 10, + 'Any', + 'Large', + 1.3, + 'Supplier-matched', + 4.2, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + END IF; + END L1; + END IF; + END FOR; + END L0; + + L2: BEGIN + IF EXISTS ( + SELECT 1 + FROM products + WHERE product_category NOT LIKE '%' || ( + SELECT supplier_main_products + FROM suppliers + WHERE supplier_id = products.supplier_id + ) || '%' + AND supplier_id IS NOT NULL + ) THEN + FOR prod AS SELECT product_id, product_category, supplier_id FROM products WHERE product_category NOT LIKE '%' || ( + SELECT supplier_main_products + FROM suppliers + WHERE supplier_id = products.supplier_id + ) || '%' LIMIT 2 DO + IF EXISTS ( + SELECT 1 + FROM suppliers + WHERE supplier_main_products LIKE '%' || prod.product_category || '%' + ) THEN + UPDATE products + SET supplier_id = ( + SELECT MIN(supplier_id) + FROM suppliers + WHERE supplier_main_products LIKE '%' || prod.product_category || '%' + ) + WHERE product_id = prod.product_id; + END IF; + END FOR; + END IF; + END L2; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, FOREACH, DML, deep-nesting, exception-handler, supplier-product-matching +-- EXPECTED: Supplier-product category matching, updates and inserts, DML +-- EXECUTES: FOR, IF, FOREACH, nested BEGIN...END, exception handler + +-- Script 67 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_employee_tenure_years INT; + DECLARE v_employee_salary DOUBLE; + DECLARE v_salary_differential DOUBLE DEFAULT 0.1; + DECLARE v_tenure_threshold INT DEFAULT 2; + DECLARE v_tenure_based_adjustments INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Tenure salary error'); END; + + L0: BEGIN + FOR emp AS SELECT employee_id, employee_salary, employee_hire_date FROM employees LIMIT 3 DO + IF emp.employee_hire_date IS NOT NULL THEN + SET v_employee_tenure_years = DATEDIFF(YEAR, emp.employee_hire_date, CURRENT_TIMESTAMP); + SET v_employee_salary = emp.employee_salary; + -- Use a simple IF to avoid repetitive control structures + IF v_employee_tenure_years > v_tenure_threshold THEN + UPDATE employees + SET employee_salary = ROUND(employee_salary * (1.0 + v_salary_differential), 2) + WHERE employee_id = emp.employee_id; + SET v_tenure_based_adjustments = v_tenure_based_adjustments + 1; + END IF; + -- Introduce some randomness and logic, but not with REPEAT/WHILE + IF v_employee_tenure_years = v_tenure_threshold THEN + UPDATE employees + SET employee_salary = ROUND(employee_salary * 0.95, 2), + employee_description = CONCAT('Provisional (', v_employee_tenure_years, ' years)') + WHERE employee_id = emp.employee_id; + END IF; + END IF; + END FOR; + -- Insert a new employee for diversity, but not in a loop + IF v_tenure_based_adjustments < 1 THEN + INSERT INTO employees VALUES ( + (SELECT MAX(employee_id) + 1 FROM employees), + 'New Hire', + 'hire@company.com', + '555-0000', + 'Associate', + 'Operations', + CURRENT_TIMESTAMP, + NULL, + 40000.0, + 0.0, + NULL, + '123 Hire St', + NULL, + 'New City', + 'CA', + '00000', + 'USA', + CURRENT_TIMESTAMP, + 'Other', + 'Single', + 0 + ); + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, DML, deep-nesting, exception-handler, salary-tenure-logic +-- EXPECTED: Tenure-based salary adjustments, diversity hire, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 68 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_shipping_region STRING; + DECLARE v_region_order_count INT; + DECLARE v_max_isolation_level INT DEFAULT 2; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Region isolation error'); END; + + L0: BEGIN + FOR region AS SELECT DISTINCT order_shipping_region FROM orders LIMIT 3 DO + SET v_order_shipping_region = region.order_shipping_region; + SET v_region_order_count = (SELECT COUNT(*) FROM orders WHERE order_shipping_region = v_order_shipping_region); + IF v_region_order_count < v_max_isolation_level THEN + L1: BEGIN + SET v_region_order_count = (SELECT COUNT(*) FROM customers WHERE customer_country = v_order_shipping_region); + IF v_region_order_count = 0 THEN + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Region ' || v_order_shipping_region, + 'region@regional.com', + '555-0000', + '123 Regional St', + v_order_shipping_region, + v_order_shipping_region, + '00000', + v_order_shipping_region, + 'Wholesale', + CURRENT_TIMESTAMP, + 0.0, + NULL, + NULL, + NULL, + true, + true, + 0.0, + NULL, + NULL + ); + END IF; + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping, + order_shipping_region + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers WHERE customer_country = v_order_shipping_region), + CURRENT_TIMESTAMP, + 'Regional Isolation', + 30.0, + 3.0, + 0.0, + 5.0, + v_order_shipping_region + ); + END L1; + END IF; + END FOR; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, DML, deep-nesting, exception-handler, region-isolation +-- EXPECTED: Regional order and customer inserts, geographical isolation, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 69 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_tax_percent DOUBLE; + DECLARE v_country_tax_rates INT; + DECLARE v_tax_exception BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Tax rate diversity error'); END; + + L0: BEGIN + SET v_country_tax_rates = ( + SELECT COUNT(DISTINCT CONCAT(order_tax, order_shipping_country)) + FROM orders + WHERE order_tax != 0 + ); + IF v_country_tax_rates < 4 AND (SELECT COUNT(DISTINCT order_shipping_country) FROM orders) > 2 THEN + L1: BEGIN + FOR country_tax_pair AS SELECT DISTINCT order_shipping_country FROM orders WHERE order_tax = 0 LIMIT 4 DO + SET v_order_tax_percent = CASE + WHEN country_tax_pair.order_shipping_country = 'USA' THEN 0.08 + WHEN country_tax_pair.order_shipping_country = 'UK' THEN 0.20 + WHEN country_tax_pair.order_shipping_country = 'CA' THEN 0.05 + WHEN country_tax_pair.order_shipping_country = 'AU' THEN 0.10 + ELSE 0.19 + END; + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping, + order_shipping_country + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Tax Diversity', + 50.0, + ROUND(50.0 * v_order_tax_percent, 2), + 0.0, + 2.0, + country_tax_pair.order_shipping_country + ); + END FOR; + SET v_tax_exception = true; + END L1; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOREACH, IF, DML, deep-nesting, exception-handler, tax-diversity +-- EXPECTED: Country tax inserts, tax rate balancing, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 70 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_product_id INT; + DECLARE v_product_reviews INT; + DECLARE v_products_without_reviews INT; + DECLARE v_review_threshold INT DEFAULT 5; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Review coverage error'); END; + + L0: BEGIN + SET v_products_without_reviews = (SELECT COUNT(*) FROM products WHERE product_reviews = 0 OR product_reviews IS NULL); + IF v_products_without_reviews > 0 THEN + FOR product_no_reviews AS SELECT product_id FROM products WHERE product_reviews = 0 OR product_reviews IS NULL LIMIT 3 DO + SET v_product_id = product_no_reviews.product_id; + SET v_product_reviews = (SELECT product_reviews FROM products WHERE product_id = v_product_id); + IF v_product_reviews < v_review_threshold THEN + SET v_product_reviews = v_product_reviews + 5; + UPDATE products + SET product_reviews = v_product_reviews, + product_description = CONCAT(product_description, ' | REVIEWED') + WHERE product_id = v_product_id; + END IF; + END FOR; + ELSE + -- To ensure future variety, inject a product with zero reviews + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Never Reviewed', + 'Misc', + 9.99, + 4.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Noone', + 'NoContact', + '123 No St', + 1, + 'Clear', + 'Small', + 0.1, + 'Waiting for first review', + 0.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, DML, deep-nesting, exception-handler, review-coverage-logic +-- EXPECTED: Review counter updates, unreviewed product insertion, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 71 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_customer_active_missing INT; + DECLARE v_temp_active_set BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Active status error'); END; + + L0: BEGIN + SET v_customer_active_missing = (SELECT COUNT(*) FROM customers WHERE customer_active_status IS NULL); + IF v_customer_active_missing > 0 THEN + FOR cust_missing_active AS SELECT customer_id FROM customers WHERE customer_active_status IS NULL LIMIT 3 DO + UPDATE customers + SET customer_active_status = (DATEDIFF(DAY, customer_membership_date, CURRENT_TIMESTAMP) < 365) + WHERE customer_id = cust_missing_active.customer_id; + SET v_temp_active_set = true; + END FOR; + END IF; + IF v_temp_active_set = false THEN + -- Force at least one unset active status for future handling + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Unset Active', + 'inactive@example.com', + '555-0000', + '123 Unset St', + 'Unknown', + 'CA', + '00000', + 'USA', + 'Retail', + CURRENT_TIMESTAMP, + 0.0, + NULL, + NULL, + NULL, + NULL, + true, + 0.0, + NULL, + NULL + ); + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, DML, deep-nesting, exception-handler, active-status-logic +-- EXPECTED: Customer active status setting, forced unset case, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 72 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_customer_type_count INT; + DECLARE v_low_diversity_type STRING; + DECLARE v_orders_by_type INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Type order diversity error'); END; + + L0: BEGIN + SET v_customer_type_count = (SELECT COUNT(DISTINCT customer_type) FROM customers); + IF v_customer_type_count < 5 THEN + FOR type_boost AS SELECT DISTINCT customer_type FROM customers LIMIT 3 DO + SET v_orders_by_type = (SELECT COUNT(*) FROM orders o JOIN customers c ON o.customer_id = c.customer_id WHERE c.customer_type = type_boost.customer_type); + IF v_orders_by_type < 2 THEN + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers WHERE customer_type = type_boost.customer_type), + CURRENT_TIMESTAMP, + 'Type Filler', + 15.0, + 1.5, + 0.0, + 2.0 + ); + END IF; + END FOR; + ELSE + SET v_low_diversity_type = (SELECT customer_type FROM customers GROUP BY customer_type ORDER BY COUNT(*) LIMIT 1); + IF (SELECT COUNT(*) FROM orders o JOIN customers c ON o.customer_id = c.customer_id WHERE c.customer_type = v_low_diversity_type) < 1 THEN + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers WHERE customer_type = v_low_diversity_type), + CURRENT_TIMESTAMP, + 'Type Revival', + 10.0, + 1.0, + 0.0, + 1.0 + ); + END IF; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, DML, deep-nesting, exception-handler, type-diversity-logic +-- EXPECTED: Order inserts for customer type diversity, type balancing, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 73 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_item_offer_count INT; + DECLARE v_offer_code_required BOOLEAN DEFAULT false; + DECLARE v_order_item_missing_offer INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Offer code error'); END; + + L0: BEGIN + SET v_order_item_offer_count = (SELECT COUNT(*) FROM order_items WHERE item_offer_code IS NOT NULL); + IF v_order_item_offer_count < 2 THEN + FOR order_item_no_offer AS SELECT order_item_id FROM order_items WHERE item_offer_code IS NULL LIMIT 2 DO + UPDATE order_items + SET item_offer_code = CASE + WHEN RANDOM() > 0.7 THEN 'SPRING24' + WHEN RANDOM() > 0.3 THEN 'FALLWINTER' + ELSE 'SUMMER2025' + END + WHERE order_item_id = order_item_no_offer.order_item_id; + SET v_order_item_offer_count = v_order_item_offer_count + 1; + END FOR; + END IF; + SET v_order_item_missing_offer = (SELECT COUNT(*) FROM order_items WHERE item_offer_code IS NULL); + IF v_order_item_missing_offer > 5 THEN + UPDATE order_items + SET item_offer_code = 'NOCODE' + WHERE order_item_id = (SELECT MIN(order_item_id) FROM order_items WHERE item_offer_code IS NULL); + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, DML, deep-nesting, exception-handler, offer-diversity +-- EXPECTED: Offer code insertion, offer logic, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 74 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_employee_dept_stagnant INT; + DECLARE v_dept_stagnant_name STRING; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Dept stagnation error'); END; + + L0: BEGIN + SET v_employee_dept_stagnant = ( + SELECT COUNT(*) + FROM employees + WHERE employee_hire_date < DATEADD(YEAR, -5, CURRENT_TIMESTAMP) + AND employee_department = ( + SELECT employee_department + FROM employees + GROUP BY employee_department + ORDER BY AVG(DATEDIFF(YEAR, employee_hire_date, CURRENT_TIMESTAMP)) DESC + LIMIT 1 + ) + ); + IF v_employee_dept_stagnant > 1 THEN + SET v_dept_stagnant_name = ( + SELECT employee_department + FROM employees + GROUP BY employee_department + ORDER BY AVG(DATEDIFF(YEAR, employee_hire_date, CURRENT_TIMESTAMP)) DESC + LIMIT 1 + ); + INSERT INTO employees VALUES ( + (SELECT MAX(employee_id) + 1 FROM employees), + 'Diverse Dept Member', + 'rotate@company.com', + '555-0000', + 'Associate', + v_dept_stagnant_name, + CURRENT_TIMESTAMP, + NULL, + 45000.0, + 0.0, + NULL, + '123 Diversion St', + NULL, + 'New City', + 'CA', + '00000', + 'USA', + CURRENT_TIMESTAMP, + 'Other', + 'Single', + 0 + ); + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: IF, DML, deep-nesting, exception-handler, department-logic +-- EXPECTED: Employee department balancing insert, department stagnation logic, DML +-- EXECUTES: IF, nested BEGIN...END, exception handler + +-- Script 75 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_supplier_product_min INT DEFAULT 2; + DECLARE v_products_per_supplier INT; + DECLARE v_suppliers_with_stock INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier-product linkage error'); END; + + L0: BEGIN + FOR sup AS SELECT supplier_id FROM suppliers LIMIT 3 DO + SET v_products_per_supplier = (SELECT COUNT(*) FROM products WHERE supplier_id = sup.supplier_id); + IF v_products_per_supplier < v_supplier_product_min THEN + BEGIN + DECLARE v_new_product_id INT; + SET v_new_product_id = (SELECT MAX(product_id) + 1 FROM products); + INSERT INTO products VALUES ( + v_new_product_id, + 'Supplier Stock', + 'Generic', + 24.99, + 19.99, + sup.supplier_id, + 'Stock Contact', + 'Stock Role', + '123 Stock St', + 5, + 'White', + 'Standard', + 0.6, + 'Supplier item', + 3.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_suppliers_with_stock = v_suppliers_with_stock + 1; + END; + END IF; + END FOR; + END L0; + BEGIN + IF v_suppliers_with_stock < 2 AND (SELECT COUNT(*) FROM products WHERE supplier_id IS NULL) > 0 THEN + UPDATE products + SET supplier_id = (SELECT MIN(supplier_id) FROM suppliers) + WHERE product_id = (SELECT MIN(product_id) FROM products WHERE supplier_id IS NULL); + END IF; + END; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, DML, deep-nesting, exception-handler, supplier-stock-logic +-- EXPECTED: Supplier-product linkage, product inserts, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 76 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_product_discount_high INT; + DECLARE v_product_discount_low INT; + DECLARE v_discount_skew_ratio DOUBLE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Discount balancing error'); END; + + L0: BEGIN + SET v_product_discount_high = (SELECT COUNT(*) FROM products WHERE product_discount > 0.2); + SET v_product_discount_low = (SELECT COUNT(*) FROM products WHERE product_discount > 0 AND product_discount <= 0.2); + SET v_discount_skew_ratio = v_product_discount_high / GREATEST(v_product_discount_low, 1.0); + IF v_discount_skew_ratio > 2.0 THEN + BEGIN + DECLARE v_over_discounted_product_id INT; + SET v_over_discounted_product_id = (SELECT MIN(product_id) FROM products WHERE product_discount > 0.2 LIMIT 1); + IF v_over_discounted_product_id IS NOT NULL THEN + REPEAT + UPDATE products + SET product_discount = ROUND(product_discount * 0.9, 2) + WHERE product_id = v_over_discounted_product_id; + SET v_product_discount_high = (SELECT COUNT(*) FROM products WHERE product_discount > 0.2); + SET v_discount_skew_ratio = v_product_discount_high / GREATEST(v_product_discount_low, 1.0); + UNTIL v_product_discount_high <= 2 OR v_discount_skew_ratio <= 2.0 OR v_over_discounted_product_id IS NULL + END REPEAT; + END IF; + END; + ELSEIF v_discount_skew_ratio < 0.5 AND v_product_discount_high < 2 THEN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Discount Blowout', + 'Sale', + 49.99, + 34.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Sale Contact', + 'Sale Role', + '123 Sale St', + 8, + 'Red', + 'Large', + 1.1, + 'Big sale', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.3, + 0.19 + ); + SET v_product_discount_high = (SELECT COUNT(*) FROM products WHERE product_discount > 0.2); + UNTIL v_product_discount_high >= 2 OR v_discount_skew_ratio >= 0.5 + END REPEAT; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: IF, REPEAT, DML, deep-nesting, exception-handler, discount-balancing +-- EXPECTED: Discount rate balancing, high-discount product control, DML +-- EXECUTES: IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 77 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_last_product_update_days INT; + DECLARE v_products_needing_update INT; + DECLARE v_freshness_target INT DEFAULT 7; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product timestamp error'); END; + + L0: BEGIN + SET v_last_product_update_days = (SELECT MAX(DATEDIFF(DAY, product_last_update, CURRENT_TIMESTAMP)) FROM products); + SET v_products_needing_update = (SELECT COUNT(*) FROM products WHERE product_last_update IS NULL OR DATEDIFF(DAY, product_last_update, CURRENT_TIMESTAMP) > v_freshness_target); + IF v_last_product_update_days > v_freshness_target AND v_products_needing_update > 0 THEN + FOR product_stale AS SELECT product_id FROM products WHERE product_last_update IS NULL OR DATEDIFF(DAY, product_last_update, CURRENT_TIMESTAMP) > v_freshness_target LIMIT 3 DO + UPDATE products + SET product_last_update = CURRENT_TIMESTAMP, + product_description = CONCAT(product_description, ' | Fresh') + WHERE product_id = product_stale.product_id; + END FOR; + END IF; + END L0; + + BEGIN + IF (SELECT COUNT(*) FROM products WHERE product_last_update > DATEADD(DAY, -3, CURRENT_TIMESTAMP)) < 2 THEN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Just In', + 'New Arrivals', + 59.99, + 49.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'New Contact', + 'New Role', + '123 Fresh St', + 12, + 'Green', + 'Medium', + 0.8, + 'Fresh item', + 4.5, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + UNTIL (SELECT COUNT(*) FROM products WHERE product_last_update > DATEADD(DAY, -3, CURRENT_TIMESTAMP)) >= 2 + END REPEAT; + END IF; + END; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, REPEAT, DML, deep-nesting, exception-handler, product-freshness +-- EXPECTED: Product freshness updates, fresh item inserts, DML +-- EXECUTES: FOR, REPEAT, nested BEGIN...END, exception handler + +-- Script 78 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_total_min DOUBLE DEFAULT 10.0; + DECLARE v_order_count_low_value INT; + DECLARE v_order_min_value_id INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order value error'); END; + + L0: BEGIN + SET v_order_count_low_value = (SELECT COUNT(*) FROM orders WHERE order_total < v_order_total_min); + IF v_order_count_low_value > 0 THEN + L1: BEGIN + SET v_order_min_value_id = (SELECT MIN(order_id) FROM orders WHERE order_total < v_order_total_min); + REPEAT + UPDATE orders + SET order_total = v_order_total_min, + order_discount = 0.0 + WHERE order_id = v_order_min_value_id; + SET v_order_min_value_id = (SELECT MIN(order_id) FROM orders WHERE order_total < v_order_total_min); + UNTIL v_order_min_value_id IS NULL OR v_order_count_low_value < 2 + END REPEAT; + END L1; + ELSE + L2: BEGIN + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Low Value', + v_order_total_min / 2.0, + 0.0, + 0.0, + 1.0 + ); + END L2; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: IF, REPEAT, DML, deep-nesting, exception-handler, order-value-logic +-- EXPECTED: Order minimum value enforcement, low-value order creation, DML +-- EXECUTES: IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 79 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_employee_transfers_required INT DEFAULT 2; + DECLARE v_longest_department_employees INT; + DECLARE v_shortest_department_employees INT; + DECLARE v_transfer_employee_id INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Department balance error'); END; + + L0: BEGIN + SET v_longest_department_employees = ( + SELECT COUNT(*) + FROM employees + WHERE employee_department = ( + SELECT employee_department + FROM employees + GROUP BY employee_department + ORDER BY AVG(DATEDIFF(YEAR, employee_hire_date, CURRENT_TIMESTAMP)) DESC + LIMIT 1 + ) + ); + SET v_shortest_department_employees = ( + SELECT COUNT(*) + FROM employees + WHERE employee_department = ( + SELECT employee_department + FROM employees + GROUP BY employee_department + ORDER BY AVG(DATEDIFF(YEAR, employee_hire_date, CURRENT_TIMESTAMP)) ASC + LIMIT 1 + ) + ); + IF v_longest_department_employees > v_shortest_department_employees + 2 THEN + L1: BEGIN + SET v_transfer_employee_id = ( + SELECT MIN(employee_id) + FROM employees + WHERE employee_department = ( + SELECT employee_department + FROM employees + GROUP BY employee_department + ORDER BY AVG(DATEDIFF(YEAR, employee_hire_date, CURRENT_TIMESTAMP)) DESC + LIMIT 1 + ) + ); + IF v_transfer_employee_id IS NOT NULL THEN + UPDATE employees + SET employee_department = ( + SELECT employee_department + FROM employees + GROUP BY employee_department + ORDER BY AVG(DATEDIFF(YEAR, employee_hire_date, CURRENT_TIMESTAMP)) ASC + LIMIT 1 + ) + WHERE employee_id = v_transfer_employee_id; + END IF; + END L1; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: IF, DML, deep-nesting, exception-handler, department-balance-logic +-- EXPECTED: Department balancing via transfer, staffing logic, DML +-- EXECUTES: IF, nested BEGIN...END, exception handler + +-- Script 80 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_supplier_region_imbalance INT; + DECLARE v_most_imbalanced_region STRING; + DECLARE v_region_sku_count INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Region sku error'); END; + + L0: BEGIN + SET v_supplier_region_imbalance = ( + SELECT MAX(cnt) - MIN(cnt) + FROM ( + SELECT COUNT(*) AS cnt + FROM products p + JOIN suppliers s ON p.supplier_id = s.supplier_id + GROUP BY s.supplier_region + ) t + ); + IF v_supplier_region_imbalance > 3 THEN + SET v_most_imbalanced_region = ( + SELECT supplier_region + FROM suppliers s + JOIN products p ON s.supplier_id = p.supplier_id + GROUP BY s.supplier_region + HAVING COUNT(*) = ( + SELECT MIN(cnt) + FROM ( + SELECT COUNT(*) AS cnt + FROM products p + JOIN suppliers s ON p.supplier_id = s.supplier_id + GROUP BY s.supplier_region + ) t + ) + ); + IF v_most_imbalanced_region IS NOT NULL THEN + SET v_region_sku_count = ( + SELECT COUNT(*) + FROM products p + JOIN suppliers s ON p.supplier_id = s.supplier_id + WHERE s.supplier_region = v_most_imbalanced_region + ); + WHILE v_region_sku_count < 4 DO + INSERT INTO suppliers VALUES ( + (SELECT MAX(supplier_id) + 1 FROM suppliers), + 'Balancer ' || v_most_imbalanced_region, + 'Balancer Contact', + 'Balancer Role', + 'balancer@regional.com', + '555-0000', + '123 Balance St', + 'Balancer City', + 'CA', + '00000', + 'USA', + v_most_imbalanced_region, + 'Balancer', + 'http://balancer.com', + CURRENT_TIMESTAMP, + NULL, + NULL, + 4.5, + true + ); + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Region SKU', + 'Balancer', + 29.99, + 19.99, + (SELECT MAX(supplier_id) FROM suppliers), + 'Balancer Contact', + 'Balancer Role', + '123 Balance St', + 4, + 'Black', + 'Medium', + 0.6, + 'Region balancer', + 3.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_region_sku_count = v_region_sku_count + 1; + END WHILE; + END IF; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: IF, WHILE, DML, deep-nesting, exception-handler, region-sku-balance-logic +-- EXPECTED: Regional SKU balancing, supplier/product inserts, DML +-- EXECUTES: IF, WHILE, nested BEGIN...END, exception handler + +-- Script 81 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_item_bulk_flag BOOLEAN DEFAULT false; + DECLARE v_large_orders_count INT; + DECLARE v_min_bulk_items INT DEFAULT 2; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Bulk item error'); END; + + L0: BEGIN + SET v_large_orders_count = (SELECT COUNT(*) FROM order_items WHERE item_quantity >= 5); + IF v_large_orders_count < v_min_bulk_items THEN + WHILE v_large_orders_count < v_min_bulk_items DO + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Bulk', + 120.0, + 12.0, + 0.0, + 0.0 + ); + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MAX(order_id) FROM orders), + (SELECT MIN(product_id) FROM products), + 6, + 15.0, + 0.0, + 1.0, + 96.0 + ); + SET v_large_orders_count = v_large_orders_count + 1; + END WHILE; + SET v_order_item_bulk_flag = true; + END IF; + IF v_order_item_bulk_flag = false AND (SELECT COUNT(*) FROM order_items WHERE item_quantity > 1) < 5 THEN + REPEAT + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MIN(order_id) FROM orders), + (SELECT MIN(product_id) FROM products), + 3, + 12.0, + 0.0, + 1.0, + 39.0 + ); + UNTIL (SELECT COUNT(*) FROM order_items WHERE item_quantity > 1) >= 5 + END REPEAT; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: WHILE, REPEAT, IF, DML, deep-nesting, exception-handler, bulk-item-coverage +-- EXPECTED: Order/item inserts for bulk sales, DML +-- EXECUTES: WHILE, REPEAT, IF, nested BEGIN...END, exception handler + +-- Script 82 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_customer_company_flag_count INT; + DECLARE V_COMPANY_FLAG_KEY STRING DEFAULT 'is_company'; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Company customer error'); END; + + L0: BEGIN + SET v_customer_company_flag_count = (SELECT COUNT(*) FROM customers WHERE JSON_EXTRACT(customer_metadata, V_COMPANY_FLAG_KEY) = 'true'); + IF v_customer_company_flag_count < 2 THEN + L1: BEGIN + FOR cust AS SELECT customer_id FROM customers WHERE JSON_EXTRACT(customer_metadata, V_COMPANY_FLAG_KEY) IS NULL OR JSON_EXTRACT(customer_metadata, V_COMPANY_FLAG_KEY) = 'false' LIMIT 2 DO + UPDATE customers + SET customer_metadata = JSON_SET(customer_metadata, '$.' || V_COMPANY_FLAG_KEY, 'true') + WHERE customer_id = cust.customer_id; + SET v_customer_company_flag_count = v_customer_company_flag_count + 1; + END FOR; + IF v_customer_company_flag_count < 1 THEN + INSERT INTO customers (customer_id, customer_name, customer_metadata) + VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'TopLevel Inc.', + JSON_OBJECT(V_COMPANY_FLAG_KEY, 'true') + ); + END IF; + END L1; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, JSON, DML, deep-nesting, exception-handler, company-flag-logic +-- EXPECTED: Customer metadata updates, company flag logic, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 83 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_item_comment_required BOOLEAN DEFAULT false; + DECLARE v_order_item_with_comments INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order item comment error'); END; + + L0: BEGIN + SET v_order_item_with_comments = (SELECT COUNT(*) FROM order_items WHERE item_notes IS NOT NULL AND item_notes != ''); + IF v_order_item_with_comments < 3 THEN + FOR oi AS SELECT order_item_id FROM order_items WHERE item_notes IS NULL OR item_notes = '' LIMIT 3 DO + UPDATE order_items + SET item_notes = CASE + WHEN MOD(oi.order_item_id, 2) = 0 THEN 'Custom request' + WHEN MOD(oi.order_item_id, 3) = 0 THEN 'Special handling' + ELSE 'No comment' + END + WHERE order_item_id = oi.order_item_id; + SET v_order_item_with_comments = v_order_item_with_comments + 1; + SET v_order_item_comment_required = true; + END FOR; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, DML, deep-nesting, exception-handler, item-comment-logic +-- EXPECTED: Order item note filling, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 84 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_product_tags_count INT; + DECLARE V_TAG_VALUE STRING DEFAULT 'featured'; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product tag error'); END; + + L0: BEGIN + SET v_product_tags_count = (SELECT COUNT(*) FROM products WHERE JSON_EXTRACT(product_metadata, '$.tags') IS NOT NULL AND JSON_EXTRACT(product_metadata, '$.tags') != '[]'); + IF v_product_tags_count < 3 THEN + L1: BEGIN + FOR prod AS SELECT product_id, product_metadata FROM products LIMIT 3 DO + IF JSON_EXTRACT(prod.product_metadata, '$.tags') IS NULL OR JSON_EXTRACT(prod.product_metadata, '$.tags') = '[]' THEN + UPDATE products + SET product_metadata = JSON_SET( + IFNULL(product_metadata, '{}'), + '$.tags', + JSON_ARRAY( + V_TAG_VALUE, + CASE WHEN MOD(prod.product_id, 2) = 0 THEN 'eco' ELSE 'limited' END + ) + ) + WHERE product_id = prod.product_id; + SET v_product_tags_count = v_product_tags_count + 1; + END IF; + END FOR; + END L1; + END IF; + IF v_product_tags_count < 1 THEN + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Tagged Example', + 'Special', + 29.99, + 19.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Tag Contact', + 'Tag Role', + '123 Tag St', + 5, + 'Yellow', + 'Small', + 0.5, + 'Tagged', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19, + '{"tags": ["featured", "eco"]}' + ); + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, JSON, DML, deep-nesting, exception-handler, product-tag-logic +-- EXPECTED: Product metadata tag updates, tagged product inserts, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 85 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_multiple_statuses BOOLEAN DEFAULT false; + DECLARE v_different_workflows INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order workflow error'); END; + + L0: BEGIN + SET v_different_workflows = (SELECT COUNT(DISTINCT order_workflow_type) FROM orders WHERE order_workflow_type IS NOT NULL); + IF v_different_workflows < 2 THEN + L1: BEGIN + FOR ord AS SELECT order_id FROM orders WHERE order_workflow_type IS NULL LIMIT 2 DO + UPDATE orders + SET order_workflow_type = CASE + WHEN MOD(ord.order_id, 2) = 0 THEN 'fast_track' + ELSE 'standard' + END + WHERE order_id = ord.order_id; + END FOR; + SET v_order_multiple_statuses = true; + END L1; + END IF; + IF v_order_multiple_statuses = false THEN + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping, + order_workflow_type + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Custom Workflow', + 12.0, + 1.2, + 0.0, + 2.0, + 'bulk_processing' + ); + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, DML, deep-nesting, exception-handler, workflow-diversity +-- EXPECTED: Order workflow type diversity, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 86 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_inactive_supplier_count INT; + DECLARE v_total_products_from_inactive_suppliers INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier inactivity error'); END; + + L0: BEGIN + SET v_inactive_supplier_count = (SELECT COUNT(*) FROM suppliers WHERE supplier_active = false); + SET v_total_products_from_inactive_suppliers = (SELECT COUNT(*) FROM products p JOIN suppliers s ON p.supplier_id = s.supplier_id WHERE s.supplier_active = false); + IF v_inactive_supplier_count > 1 AND v_total_products_from_inactive_suppliers > 1 THEN + L1: BEGIN + DECLARE v_inactive_supplier_id INT; + SET v_inactive_supprier_id = (SELECT MIN(supplier_id) FROM suppliers WHERE supplier_active = false LIMIT 1); + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Clearance', + 'Closeout', + 9.99, + 4.99, + v_inactive_supplier_id, + 'Clearance Contact', + 'Clearance Role', + '123 Clearance St', + 1, + 'Gray', + 'Small', + 0.1, + 'Supplier inactive', + 0.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.5, + 0.19 + ); + SET v_inactive_supplier_count = v_inactive_supplier_count - 1; + SET v_total_products_from_inactive_suppliers = v_total_products_from_inactive_suppliers + 1; + END L1; + ELSE + L2: BEGIN + INSERT INTO suppliers VALUES ( + (SELECT MAX(supplier_id) + 1 FROM suppliers), + 'Inactive Test', + 'Inactive Manager', + 'Inactive Role', + 'inactive@test.com', + '555-0000', + '123 Inactive St', + 'Inactive City', + 'CA', + '00000', + 'USA', + 'Test', + 'General', + NULL, + CURRENT_TIMESTAMP, + NULL, + NULL, + 2.5, + false + ); + SET v_inactive_supplier_count = v_inactive_supplier_count + 1; + END L2; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: IF, DML, deep-nesting, exception-handler, inactive-supplier-logic +-- EXPECTED: Clearance product inserts, inactive supplier coverage, DML +-- EXECUTES: IF, nested BEGIN...END, exception handler + +-- Script 87 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_item_returns BOOLEAN DEFAULT false; + DECLARE v_returns_to_cover INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Return item error'); END; + + L0: BEGIN + SET v_returns_to_cover = (SELECT COUNT(*) FROM order_items WHERE item_status = 'Returned'); + IF v_returns_to_cover < 2 THEN + L1: BEGIN + FOR oi AS SELECT order_item_id FROM order_items WHERE item_status != 'Returned' LIMIT 2 DO + UPDATE order_items + SET item_status = 'Returned', + item_return_date = CURRENT_TIMESTAMP + WHERE order_item_id = oi.order_item_id; + SET v_returns_to_cover = v_returns_to_cover + 1; + END FOR; + SET v_order_item_returns = true; + END L1; + END IF; + IF v_order_item_returns = false AND v_returns_to_cover < 1 THEN + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total, + item_status, + item_return_date + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MIN(order_id) FROM orders), + (SELECT MIN(product_id) FROM products), + 1, + 10.0, + 0.0, + 1.0, + 11.0, + 'Returned', + CURRENT_TIMESTAMP + ); + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, DML, deep-nesting, exception-handler, return-logic +-- EXPECTED: Returned item updates, return state coverage, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 88 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_customer_orders_no_discount INT; + DECLARE v_discount_provided BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Discount logic error'); END; + + L0: BEGIN + SET v_customer_orders_no_discount = ( + SELECT COUNT(*) + FROM customers c + JOIN orders o ON c.customer_id = o.customer_id + WHERE o.order_discount = 0 + ); + IF v_customer_orders_no_discount > 2 THEN + L1: BEGIN + FOR cust AS + SELECT c.customer_id + FROM customers c + JOIN orders o ON c.customer_id = o.customer_id + WHERE o.order_discount = 0 + GROUP BY c.customer_id + LIMIT 2 + DO + UPDATE orders + SET order_discount = 0.1, + order_status = 'Discount Applied' + WHERE customer_id = cust.customer_id + AND order_discount = 0; + SET v_discount_provided = true; + END FOR; + END L1; + END IF; + IF v_discount_provided = false AND v_customer_orders_no_discount > 0 THEN + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers WHERE NOT EXISTS (SELECT 1 FROM orders WHERE customer_id = customers.customer_id)), + CURRENT_TIMESTAMP, + 'Discount Provided', + 25.0, + 2.5, + 0.15, + 2.5 + ); + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, DML, deep-nesting, exception-handler, discount-coverage +-- EXPECTED: Discount application, discount coverage logic, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 89 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_supplier_product_threshold INT DEFAULT 3; + DECLARE v_critical_category_products INT; + DECLARE v_extra_promos_flag BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Critical category error'); END; + + L0: BEGIN + FOR category AS SELECT DISTINCT product_category FROM products WHERE product_category != 'General' LIMIT 2 DO + SET v_critical_category_products = (SELECT COUNT(*) FROM products WHERE product_category = category.product_category); + IF v_critical_category_products < v_supplier_product_threshold THEN + -- Insert additional products to reach threshold + WHILE v_critical_category_products < v_supplier_product_threshold DO + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Critical ' || category.product_category, + category.product_category, + 34.99, + 24.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Critical Contact', + 'Critical Role', + '123 Critical St', + 7, + 'Silver', + 'Medium', + 0.8, + 'Critical', + 4.5, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_critical_category_products = (SELECT COUNT(*) FROM products WHERE product_category = category.product_category); + END WHILE; + SET v_extra_promos_flag = true; + END IF; + END FOR; + IF v_extra_promos_flag = true THEN + -- To ensure orders for these categories + FOR category AS SELECT DISTINCT product_category FROM products LIMIT 1 DO + IF NOT EXISTS (SELECT 1 FROM order_items oi JOIN products p ON oi.product_id = p.product_id WHERE p.product_category = category.product_category) THEN + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MIN(order_id) FROM orders), + (SELECT MIN(product_id) FROM products WHERE product_category = category.product_category), + 2, + 30.0, + 0.0, + 3.0, + 66.0 + ); + END IF; + END FOR; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, WHILE, DML, deep-nesting, exception-handler, critical-category-logic +-- EXPECTED: Critical category product inserts, order item coverage, DML +-- EXECUTES: FOR, IF, WHILE, nested BEGIN...END, exception handler + +-- Script 90 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_item_status_aging BOOLEAN DEFAULT false; + DECLARE v_order_item_status_preprocessing INT; + DECLARE v_required_status_transitions INT DEFAULT 2; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Status workflow error'); END; + + L0: BEGIN + SET v_order_item_status_preprocessing = (SELECT COUNT(*) FROM order_items WHERE item_status = 'Preprocessing' AND item_delivery_date IS NULL); + IF v_order_item_status_preprocessing >= 1 THEN + -- Advance one preprocessing item + UPDATE order_items + SET item_status = 'Processing', + item_delivery_date = CURRENT_TIMESTAMP + WHERE order_item_id = (SELECT MIN(order_item_id) FROM order_items WHERE item_status = 'Preprocessing'); + SET v_order_item_status_aging = true; + END IF; + IF v_order_item_status_aging = false AND (SELECT COUNT(*) FROM customers WHERE customer_last_order_date > DATEADD(DAY, -7, CURRENT_TIMESTAMP)) < 2 THEN + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Item Status Flow', + 15.0, + 1.5, + 0.0, + 2.0 + ); + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total, + item_status, + item_delivery_date + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MAX(order_id) FROM orders), + (SELECT MIN(product_id) FROM products), + 1, + 12.0, + 0.0, + 1.0, + 13.0, + 'Preprocessing', + NULL + ); + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: IF, DML, deep-nesting, exception-handler, status-workflow-logic +-- EXPECTED: Status workflow updates, order and item inserts, DML +-- EXECUTES: IF, nested BEGIN...END, exception handler + +-- Script 91 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_product_missing_weight INT; + DECLARE v_product_weight_coverage BOOLEAN DEFAULT false; + DECLARE v_min_weight_products INT DEFAULT 2; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product weight error'); END; + + L0: BEGIN + SET v_product_missing_weight = (SELECT COUNT(*) FROM products WHERE product_weight IS NULL AND product_category NOT LIKE '%Accessories%'); + IF v_product_missing_weight > 0 THEN + L1: BEGIN + FOR prod AS SELECT product_id FROM products WHERE product_weight IS NULL AND product_category NOT LIKE '%Accessories%' LIMIT v_min_weight_products DO + UPDATE products + SET product_weight = ROUND(RAND() * 2 + 0.2, 2) + WHERE product_id = prod.product_id; + SET v_product_weight_coverage = true; + END FOR; + END L1; + END IF; + IF v_product_weight_coverage = false AND v_product_missing_weight > 0 THEN + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Weighted Product', + 'General', + 29.99, + 19.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Weight Contact', + 'Weight Role', + '123 Weight St', + 6, + 'Black', + 'Medium', + 2.2, + 'Weighted sample', + 3.5, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, DML, deep-nesting, exception-handler, product-weight-logic +-- EXPECTED: Product weight updates, weighted product inserts, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 92 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_customer_opt_in_newsletter_count INT; + DECLARE v_opt_in_diversity BOOLEAN DEFAULT false; + DECLARE v_min_opt_in_variety INT DEFAULT 2; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Newsletter opt-in error'); END; + + L0: BEGIN + SET v_customer_opt_in_newsletter_count = (SELECT COUNT(*) FROM customers WHERE customer_opt_in_newsletter = true); + IF v_customer_opt_in_newsletter_count < v_min_opt_in_variety THEN + L1: BEGIN + FOR cust AS SELECT customer_id FROM customers WHERE customer_opt_in_newsletter IS NULL LIMIT v_min_opt_in_variety DO + UPDATE customers + SET customer_opt_in_newsletter = true + WHERE customer_id = cust.customer_id; + SET v_opt_in_diversity = true; + END FOR; + IF v_opt_in_diversity = false AND v_customer_opt_in_newsletter_count < v_min_opt_in_variety THEN + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Opt-In Customer', + 'optin@example.com', + '555-0000', + '123 OptIn St', + 'OptIn City', + 'CA', + '00000', + 'USA', + 'Retail', + CURRENT_TIMESTAMP, + 0.0, + NULL, + NULL, + NULL, + true, + true, + 0.0, + NULL, + NULL + ); + END IF; + END L1; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, DML, deep-nesting, exception-handler, newsletter-opt-in-logic +-- EXPECTED: Newsletter opt-in diversity, customer updates/inserts, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 93 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_supplier_product_diversity_count INT; + DECLARE v_min_supplier_product_diversity INT DEFAULT 2; + DECLARE v_diversity_enforced BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier-product diversity error'); END; + + L0: BEGIN + SET v_supplier_product_diversity_count = ( + SELECT COUNT(DISTINCT product_category) + FROM products p + JOIN suppliers s ON p.supplier_id = s.supplier_id + WHERE s.supplier_main_products IS NULL + OR p.product_category NOT LIKE CONCAT('%', s.supplier_main_products, '%') + ); + IF v_supplier_product_diversity_count < v_min_supplier_product_diversity THEN + FOR sup AS + SELECT s.supplier_id, s.supplier_main_products + FROM suppliers s + WHERE s.supplier_main_products IS NOT NULL + AND s.supplier_main_products != 'General' + LIMIT 1 + DO + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Diverse Category Product', + (SELECT MIN(product_category) FROM products + WHERE product_category NOT LIKE CONCAT('%', sup.supplier_main_products, '%') + AND product_category IS NOT NULL), + 29.99, + 19.99, + sup.supplier_id, + 'Diverse Contact', + 'Diverse Role', + '123 Diverse St', + 4, + 'White', + 'Medium', + 0.7, + 'Supplier-product diversity', + 3.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + END FOR; + SET v_diversity_enforced = true; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOR, IF, DML, deep-nesting, exception-handler, supplier-product-diversity-logic +-- EXPECTED: Supplier-product category diversity inserts, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +-- Script 94 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_order_item_bundled_flag BOOLEAN DEFAULT false; + DECLARE v_bundled_item_types_count INT; + DECLARE v_min_bundled_items INT DEFAULT 1; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Bundle error'); END; + + L0: BEGIN + SET v_bundled_item_types_count = (SELECT COUNT(*) FROM products WHERE product_category = 'Bundle'); + IF v_bundled_item_types_count < v_min_bundled_items THEN + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Bundle Starter', + 'Bundle', + 49.99, + 39.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Bundle Contact', + 'Bundle Role', + '123 Bundle St', + 5, + 'Multi', + 'Set', + 2.0, + 'Bundle to bundle', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_bundled_item_types_count = v_bundled_item_types_count + 1; + SET v_order_item_bundled_flag = true; + END IF; + IF v_order_item_bundled_flag = false THEN + REPEAT + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total, + item_bundle_notes + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MIN(order_id) FROM orders), + (SELECT MAX(product_id) FROM products WHERE product_category = 'Bundle'), + 1, + 49.99, + 0.0, + 5.0, + 54.99, + 'From bundle logic' + ); + UNTIL (SELECT COUNT(*) FROM order_items WHERE item_bundle_notes IS NOT NULL) >= v_min_bundled_items + END REPEAT; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: IF, REPEAT, DML, deep-nesting, exception-handler, bundled-item-logic +-- EXPECTED: Product bundle inserts, bundle order item inserts, DML +-- EXECUTES: IF, REPEAT, nested BEGIN...END, exception handler + +-- Script 95 +--QUERY-DELIMITER-START +BEGIN + DECLARE v_customer_is_foreign_flag BOOLEAN DEFAULT false; + DECLARE v_foreign_customer_count INT; + DECLARE v_min_foreign_customers INT DEFAULT 2; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Foreign customer error'); END; + + L0: BEGIN + SET v_foreign_customer_count = (SELECT COUNT(*) FROM customers WHERE customer_country != 'USA'); + IF v_foreign_customer_count < v_min_foreign_customers THEN + FOR country AS SELECT DISTINCT supplier_country FROM suppliers WHERE supplier_country != 'USA' LIMIT 2 DO + INSERT INTO customers ( + customer_id, + customer_name, + customer_email, + customer_phone, + customer_address_1, + customer_city, + customer_state, + customer_zip, + customer_country, + customer_type, + customer_total_spent, + customer_active_status, + customer_opt_in_newsletter + ) VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'International ' || country.supplier_country, + 'intl@' || LOWER(country.supplier_country) || '.com', + '555-0000', + '123 Intl St', + 'International City', + country.supplier_country, + '00000', + country.supplier_country, + 'Retail', + 0.0, + true, + true + ); + SET v_customer_is_foreign_flag = true; + END FOR; + END IF; + END L0; +END; +--QUERY-DELIMITER-END +-- TAGS: FOREACH, IF, DML, deep-nesting, exception-handler, foreign-customer-logic +-- EXPECTED: Foreign customer inserts, international customer coverage, DML +-- EXECUTES: FOR, IF, nested BEGIN...END, exception handler + +DROP TABLE products; +DROP TABLE customers; +DROP TABLE orders; +DROP TABLE order_items; +DROP TABLE employees; +DROP TABLE suppliers; \ No newline at end of file diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/session-variable-precedence.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/session-variable-precedence.sql new file mode 100644 index 00000000000..405c3ffdaa4 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/session-variable-precedence.sql @@ -0,0 +1,17 @@ +CREATE TABLE t1(col1 INT, col2 STRING); + +DECLARE all = 1; +DECLARE a = 1; + +-- Precedence with group by ALL +SELECT col1, SUM(col2) FROM t1 GROUP BY ALL; +SELECT col1, SUM(col2) FROM t1 GROUP BY ALL ORDER BY ALL; +SELECT col1, col2 FROM t1 ORDER BY ALL; + +-- Precedence with group by alias +SELECT col1 AS a, SUM(col2) FROM t1 GROUP BY a; + +DROP TEMP VARIABLE a; +DROP TEMP VARIABLE all; + +DROP TABLE t1; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/sql-session-variables.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/sql-session-variables.sql index d876be1bb6b..2e4eaa1f8f6 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/sql-session-variables.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/sql-session-variables.sql @@ -207,6 +207,35 @@ DROP TEMPORARY VARIABLE var1; DROP TEMPORARY VARIABLE var2; DROP TEMPORARY VARIABLE var3; +SET VARIABLE title = 'DECLARE VARIABLE - multiple variables declared at once'; + +DECLARE VARIABLE var1, var2, var3 INT; +DECLARE VARIABLE var4, var5, var6 INT DEFAULT CAST(RAND(0) * 10 AS INT); +DECLARE VARIABLE var7, var8, var9 DEFAULT 5; + +SELECT var4 = var5, var4 = var6, var5 = var6; + +DECLARE OR REPLACE VARIABLE var1, var2, var3 DOUBLE; +DECLARE OR REPLACE VARIABLE var4, var5, var6 DOUBLE DEFAULT RAND(0); +DECLARE OR REPLACE VARIABLE var7, var8, var9 DEFAULT 1.5; + +SELECT var4 = var5, var4 = var6, var5 = var6; + +DROP TEMPORARY VARIABLE var1; +DROP TEMPORARY VARIABLE var2; +DROP TEMPORARY VARIABLE var3; +DROP TEMPORARY VARIABLE var4; +DROP TEMPORARY VARIABLE var5; +DROP TEMPORARY VARIABLE var6; +DROP TEMPORARY VARIABLE var7; +DROP TEMPORARY VARIABLE var8; +DROP TEMPORARY VARIABLE var9; + +SET VARIABLE title = 'DECLARE VARIABLE - duplicate names'; + +DECLARE VARIABLE var1, var2, vAr1 INT; +DECLARE OR REPLACE VARIABLE var1, var2, vAr1 INT; + SET VARIABLE title = 'SET VARIABLE - row assignment'; DECLARE OR REPLACE VARIABLE var1 INT DEFAULT 5; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/sql-udf.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/sql-udf.sql index 63c2a194568..e796b7b192b 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/sql-udf.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/sql-udf.sql @@ -146,6 +146,11 @@ CREATE FUNCTION foo1e3(x INT, y INT) RETURNS TABLE (x INT NOT NULL) RETURN SELEC CREATE FUNCTION foo1f1(x INT, y INT GENERATED ALWAYS AS (x + 10)) RETURNS INT RETURN y + 1; CREATE FUNCTION foo1f2(id BIGINT GENERATED ALWAYS AS IDENTITY) RETURNS BIGINT RETURN id + 1; +-- 1.1.g Constraint +-- Expect failure +CREATE FUNCTION foo1g1(x INT, y INT UNIQUE) RETURNS INT RETURN y + 1; +CREATE FUNCTION foo1g2(id BIGINT CHECK (true)) RETURNS BIGINT RETURN id + 1; + -- 1.2 Returns Columns -- 1.2.a A table function with various numbers of returns columns -- Expect error: Cannot have an empty RETURNS @@ -813,6 +818,36 @@ CREATE FUNCTION foo3_5d(x INT) RETURNS TABLE (a INT) RETURN SELECT foo3_5a(x); CREATE FUNCTION foo3_5d(x INT) RETURNS INT RETURN (SELECT SUM(a) FROM t); CREATE FUNCTION foo3_5d(x INT) RETURNS TABLE (a INT) RETURN SELECT a FROM t; +-- 3.12 SQL data access routine +-- Scalar functions +CREATE FUNCTION foo3_12a(x INT) RETURNS INT CONTAINS SQL RETURN x; +CREATE FUNCTION foo3_12b(x INT) RETURNS INT READS SQL DATA RETURN x; +CREATE FUNCTION foo3_12c(x INT) RETURNS INT CONTAINS SQL RETURN (SELECT x); +CREATE FUNCTION foo3_12d(x INT) RETURNS INT CONTAINS SQL RETURN (SELECT COUNT(*) FROM range(0, 3)); +CREATE FUNCTION foo3_12e(x INT) RETURNS INT CONTAINS SQL RETURN (SELECT COUNT(*) FROM VALUES (0, 1)); +-- Expect error: cannot create a SQL function with CONTAINS SQL that accesses SQL data +CREATE FUNCTION foo3_12f(x INT) RETURNS INT CONTAINS SQL RETURN SELECT SUM(c2) FROM t1; +CREATE FUNCTION foo3_12f(x INT) RETURNS INT CONTAINS SQL RETURN foo3_12b(x) + 1; +CREATE FUNCTION foo3_12f(x INT) RETURNS INT CONTAINS SQL RETURN 1 + (SELECT SUM(c2) FROM t1); + +-- Table functions +CREATE FUNCTION foo3_12g(x INT) RETURNS TABLE (a INT, b INT) CONTAINS SQL RETURN SELECT x, x + 1; +CREATE FUNCTION foo3_12h(x INT) RETURNS TABLE (a INT, b INT) READS SQL DATA RETURN SELECT x, x + 1; +CREATE FUNCTION foo3_12i(x INT) RETURNS TABLE (a INT, b INT) CONTAINS SQL RETURN SELECT * FROM VALUES (0, 1); +CREATE FUNCTION foo3_12j(x INT) RETURNS TABLE (a INT, b INT) CONTAINS SQL RETURN SELECT id, id + 1 FROM RANGE(3); +-- Derived SQL data access: READS SQL DATA. +CREATE FUNCTION foo3_12k(x INT) RETURNS TABLE (a INT, b INT) RETURN SELECT c1, c2 FROM t1; +-- Expect error: cannot create a SQL function with CONTAINS SQL that accesses SQL data +CREATE FUNCTION foo3_12f(x INT) RETURNS TABLE (a INT, b INT) CONTAINS SQL RETURN SELECT c1, c2 FROM t1; +CREATE FUNCTION foo3_12f(x INT) RETURNS TABLE (a INT, b INT) CONTAINS SQL RETURN SELECT foo3_12b(x), x; +CREATE FUNCTION foo3_12f(x INT) RETURNS TABLE (a INT, b INT) CONTAINS SQL RETURN SELECT * FROM foo3_12h(x); +CREATE FUNCTION foo3_12f(x INT) RETURNS TABLE (a INT, b INT) CONTAINS SQL RETURN SELECT * FROM foo3_12k(x); + +CREATE TABLE tbl USING PARQUET AS SELECT c1 FROM t2; +CREATE FUNCTION foo3_12f(x INT) RETURNS INT CONTAINS SQL RETURN SELECT SUM(c1) FROM tbl; +CREATE FUNCTION foo3_12f(x INT) RETURNS TABLE (a INT) CONTAINS SQL RETURN SELECT * FROM tbl; +DROP TABLE tbl; + -- 3.14 Invalid usage of SQL scalar/table functions in query clauses. CREATE FUNCTION foo3_14a() RETURNS INT RETURN 1; CREATE FUNCTION foo3_14b() RETURNS TABLE (a INT) RETURN SELECT 1; @@ -976,6 +1011,17 @@ DROP FUNCTION IF EXISTS foo3_4c; DROP FUNCTION IF EXISTS foo3_4d; DROP FUNCTION IF EXISTS foo3_4e; DROP FUNCTION IF EXISTS foo3_4f; +DROP FUNCTION IF EXISTS foo3_12a; +DROP FUNCTION IF EXISTS foo3_12b; +DROP FUNCTION IF EXISTS foo3_12c; +DROP FUNCTION IF EXISTS foo3_12d; +DROP FUNCTION IF EXISTS foo3_12e; +DROP FUNCTION IF EXISTS foo3_12f; +DROP FUNCTION IF EXISTS foo3_12g; +DROP FUNCTION IF EXISTS foo3_12h; +DROP FUNCTION IF EXISTS foo3_12i; +DROP FUNCTION IF EXISTS foo3_12j; +DROP FUNCTION IF EXISTS foo3_12k; DROP FUNCTION IF EXISTS foo4_0; DROP FUNCTION IF EXISTS foo4_1; DROP FUNCTION IF EXISTS foo4_2; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/st-functions.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/st-functions.sql new file mode 100644 index 00000000000..70fbdef5333 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/st-functions.sql @@ -0,0 +1,100 @@ +-- Create the table of WKB values and insert test values. +DROP TABLE IF EXISTS geodata; +CREATE TABLE geodata(wkb BINARY) USING parquet; +-- See: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary +-- to understand the formatting/layout of the input Well-Known Binary (WKB) values. +INSERT INTO geodata VALUES +(NULL), +(X'0101000000000000000000F03F0000000000000040'); + +--- Casting geospatial data types + +-- GEOGRAPHY and GEOMETRY data types cannot be cast to/from other data types. +SELECT CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040') AS STRING) AS result; +SELECT CAST(X'0101000000000000000000f03f0000000000000040' AS GEOMETRY(4326)) AS result; + +-- Casting GEOGRAPHY() to GEOGRAPHY(ANY) is allowed. +SELECT hex(ST_AsBinary(CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040') AS GEOGRAPHY(ANY)))) AS result; +-- Casting GEOGRAPHY(ANY) to GEOGRAPHY() is not allowed. +SELECT CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040')::GEOGRAPHY(ANY) AS GEOGRAPHY(4326)) AS result; + +-- Casting GEOGRAPHY to GEOMETRY is allowed only if SRIDs match. +SELECT hex(ST_AsBinary(CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040') AS GEOMETRY(4326)))) AS result; +-- Error handling: mismatched SRIDs. +SELECT CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040') AS GEOMETRY(ANY)) AS result; + +-- Casting GEOMETRY() to GEOMETRY(ANY) is allowed. +SELECT hex(ST_AsBinary(CAST(ST_GeomFromWKB(X'0101000000000000000000f03f0000000000000040') AS GEOMETRY(ANY)))) AS result; +-- Casting GEOMETRY(ANY) to GEOMETRY() is not allowed. +SELECT CAST(ST_GeomFromWKB(X'0101000000000000000000f03f0000000000000040')::GEOMETRY(ANY) AS GEOMETRY(4326)) AS result; + +---- Geospatial type coercion + +-- Array +SELECT typeof(array(ST_GeogFromWKB(wkb), ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY))) FROM geodata; +SELECT typeof(array(ST_GeomFromWKB(wkb), ST_GeomFromWKB(wkb)::GEOMETRY(ANY))) FROM geodata; +-- Map +SELECT typeof(map('a', ST_GeogFromWKB(wkb), 'b', ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY))) FROM geodata; +SELECT typeof(map('a', ST_GeomFromWKB(wkb), 'b', ST_GeomFromWKB(wkb)::GEOMETRY(ANY))) FROM geodata; +-- Struct +SELECT typeof(array(named_struct('g1', ST_GeogFromWKB(wkb), 'g2', ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY)), named_struct('g1', ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY), 'g2', ST_GeogFromWKB(wkb)))) FROM geodata; +SELECT typeof(array(named_struct('g1', ST_GeomFromWKB(wkb), 'g2', ST_GeomFromWKB(wkb)::GEOMETRY(ANY)), named_struct('g1', ST_GeomFromWKB(wkb)::GEOMETRY(ANY), 'g2', ST_GeomFromWKB(wkb)))) FROM geodata; +-- Nested +SELECT typeof(named_struct('a', array(ST_GeogFromWKB(wkb), ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY)), 'b', map('g', ST_GeogFromWKB(wkb), 'h', ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY)))) FROM geodata; +SELECT typeof(named_struct('a', array(ST_GeomFromWKB(wkb), ST_GeomFromWKB(wkb)::GEOMETRY(ANY)), 'b', map('g', ST_GeomFromWKB(wkb), 'h', ST_GeomFromWKB(wkb)::GEOMETRY(ANY)))) FROM geodata; + +-- NVL +SELECT typeof(nvl(ST_GeogFromWKB(wkb), ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY))) FROM geodata; +SELECT typeof(nvl(ST_GeomFromWKB(wkb), ST_GeomFromWKB(wkb)::GEOMETRY(ANY))) FROM geodata; +-- NVL2 +SELECT typeof(nvl2(ST_GeogFromWKB(wkb), ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY), ST_GeogFromWKB(wkb))) FROM geodata; +SELECT typeof(nvl2(ST_GeomFromWKB(wkb), ST_GeomFromWKB(wkb)::GEOMETRY(ANY), ST_GeomFromWKB(wkb))) FROM geodata; +-- CASE WHEN +SELECT typeof(CASE WHEN wkb IS NOT NULL THEN ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY) ELSE ST_GeogFromWKB(wkb) END) FROM geodata; +SELECT typeof(CASE WHEN wkb IS NOT NULL THEN ST_GeomFromWKB(wkb)::GEOMETRY(ANY) ELSE ST_GeomFromWKB(wkb) END) FROM geodata; +-- COALESCE +SELECT typeof(coalesce(ST_GeogFromWKB(wkb), ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY))) FROM geodata; +SELECT typeof(coalesce(ST_GeomFromWKB(wkb), ST_GeomFromWKB(wkb)::GEOMETRY(ANY))) FROM geodata; +-- IF +SELECT typeof(IF(wkb IS NOT NULL, ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY), ST_GeogFromWKB(wkb))) FROM geodata; +SELECT typeof(IF(wkb IS NOT NULL, ST_GeomFromWKB(wkb)::GEOMETRY(ANY), ST_GeomFromWKB(wkb))) FROM geodata; + +---- ST reader/writer expressions + +-- WKB (Well-Known Binary) round-trip tests for GEOGRAPHY and GEOMETRY types. +SELECT hex(ST_AsBinary(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040'))) AS result; +SELECT hex(ST_AsBinary(ST_GeomFromWKB(X'0101000000000000000000f03f0000000000000040'))) AS result; + +------ ST accessor expressions + +---- ST_Srid + +-- 1. Driver-level queries. +SELECT ST_Srid(NULL); +SELECT ST_Srid(ST_GeogFromWKB(X'0101000000000000000000F03F0000000000000040')); +SELECT ST_Srid(ST_GeomFromWKB(X'0101000000000000000000F03F0000000000000040')); + +-- 2. Table-level queries. +SELECT COUNT(*) FROM geodata WHERE ST_Srid(ST_GeogFromWKB(wkb)) <> 4326; +SELECT COUNT(*) FROM geodata WHERE ST_Srid(ST_GeomFromWKB(wkb)) <> 0; + +------ ST modifier expressions + +---- ST_SetSrid + +-- 1. Driver-level queries. +SELECT ST_Srid(ST_SetSrid(ST_GeogFromWKB(X'0101000000000000000000F03F0000000000000040'), 4326)); +SELECT ST_Srid(ST_SetSrid(ST_GeomFromWKB(X'0101000000000000000000F03F0000000000000040'), 3857)); +-- Error handling: invalid SRID. +SELECT ST_Srid(ST_SetSrid(ST_GeogFromWKB(X'0101000000000000000000F03F0000000000000040'), 3857)); +SELECT ST_Srid(ST_SetSrid(ST_GeomFromWKB(X'0101000000000000000000F03F0000000000000040'), 9999)); + +-- 2. Table-level queries. +SELECT COUNT(*) FROM geodata WHERE ST_Srid(ST_SetSrid(ST_GeogFromWKB(wkb), 4326)) <> 4326; +SELECT COUNT(*) FROM geodata WHERE ST_Srid(ST_SetSrid(ST_GeomFromWKB(wkb), 3857)) <> 3857; +-- Error handling: invalid SRID. +SELECT COUNT(*) FROM geodata WHERE ST_Srid(ST_SetSrid(ST_GeogFromWKB(wkb), 3857)) IS NOT NULL; +SELECT COUNT(*) FROM geodata WHERE ST_Srid(ST_SetSrid(ST_GeomFromWKB(wkb), 9999)) IS NOT NULL; + +-- Drop the test table. +DROP TABLE geodata; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/string-functions.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/string-functions.sql index c108f7c76f7..7559c45ec10 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/string-functions.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/string-functions.sql @@ -27,7 +27,15 @@ select right("abcd", -2), right("abcd", 0), right("abcd", 'a'); SELECT split('aa1cc2ee3', '[1-9]+'); SELECT split('aa1cc2ee3', '[1-9]+', 2); SELECT split('hello', ''); +SELECT split('hello', '', 0); +SELECT split('hello', '', 1); +SELECT split('hello', '', 3); +SELECT split('hello', '', 5); +SELECT split('hello', '', 100); SELECT split('', ''); +SELECT split('', '', -1); +SELECT split('', '', 0); +SELECT split('', '', 1); SELECT split('abc', null); SELECT split(null, 'b'); @@ -306,3 +314,8 @@ select validate_utf8(x'80'); select try_validate_utf8(''); select try_validate_utf8('abc'); select try_validate_utf8(x'80'); + +-- quote +select quote('Spark'); +select quote("Don't"); +select quote(NULL); \ No newline at end of file diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/struct.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/struct.sql index 93a1238ab18..3d45db5669f 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/struct.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/struct.sql @@ -24,4 +24,11 @@ SELECT ID, STRUCT(ST.*).C NST FROM tbl_x; SELECT ID, STRUCT(ST.C, ST.D).D NST FROM tbl_x; -- Select an alias from a struct -SELECT ID, STRUCT(ST.C as STC, ST.D as STD).STD FROM tbl_x; \ No newline at end of file +SELECT ID, STRUCT(ST.C as STC, ST.D as STD).STD FROM tbl_x; + +-- LCAs with struct columns +SELECT STRUCT(1 AS a) AS b, b AS c; +SELECT STRUCT(col1 AS a) AS b, b AS c FROM VALUES(1); +SELECT STRUCT(1 AS a) AS b, b AS c GROUP BY b; +SELECT STRUCT(col1 AS a) AS b, b AS c FROM VALUES(1) GROUP BY b; +SELECT MAX(STRUCT(1 AS a)), 2 AS b, b AS c GROUP BY b; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/subquery/resolution-edge-cases.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/subquery/resolution-edge-cases.sql new file mode 100644 index 00000000000..0dd37655319 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/subquery/resolution-edge-cases.sql @@ -0,0 +1,70 @@ +--ONLY_IF spark + +CREATE TABLE t1(col1 INT, col2 STRING); +CREATE TABLE t2(col1 INT); +CREATE TABLE t3(col1 INT, col2 STRING); + +-- Subquery expressions validation is done at the end of operator resolution +SELECT * +FROM ( + SELECT ( + SELECT t1.col1 + FROM t1 + WHERE t3.col1 = t1.col2 + LIMIT 1 + ) + FROM t3 + GROUP BY ( + SELECT t1.col1 + FROM t1 + WHERE t3.col1 = t1.col2 + LIMIT 1 + ) +); +SELECT * +FROM ( + SELECT 1 IN ( + SELECT t1.col1 + FROM t1 + WHERE t3.col1 = t1.col2 + LIMIT 1 + ) + FROM t3 + GROUP BY 1 IN ( + SELECT t1.col1 + FROM t1 + WHERE t3.col1 = t1.col2 + LIMIT 1 + ) +); +SELECT * +FROM ( + SELECT EXISTS ( + SELECT t1.col1 + FROM t1 + WHERE t3.col1 = t1.col2 + LIMIT 1 + ) + FROM t3 + GROUP BY EXISTS ( + SELECT t1.col1 + FROM t1 + WHERE t3.col1 = t1.col2 + LIMIT 1 + ) +); + +SELECT col1 IN (SELECT col1 FROM t2) +FROM t2 +GROUP BY col1 IN (SELECT col1 FROM t2), col1 +ORDER BY col1 IN (SELECT col1 FROM t2); + +SELECT col1 FROM t2 GROUP BY col1 IN (SELECT col1 FROM t2), col1 ORDER BY col1 IN (SELECT col1 FROM t2); + +SELECT col1 FROM t2 GROUP BY col1 ORDER BY 1 IN (SELECT 1); + +SELECT col1 AS a, a + 1 FROM t2 GROUP BY col1 ORDER BY 1 IN (SELECT 1); + +DROP TABLE t1; +DROP TABLE t2; +DROP TABLE t3; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/thetasketch.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/thetasketch.sql new file mode 100644 index 00000000000..4782d2017f2 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/thetasketch.sql @@ -0,0 +1,540 @@ +-- Positive test cases +-- Create tables with two columns for each data type + +-- Integer table +DROP TABLE IF EXISTS t_int_1_5_through_7_11; +CREATE TABLE t_int_1_5_through_7_11 AS +VALUES + (1, 5), (2, 6), (3, 7), (4, 8), (5, 9), (6, 10), (7, 11) AS tab(col1, col2); + +-- Long table +DROP TABLE IF EXISTS t_long_1_5_through_7_11; +CREATE TABLE t_long_1_5_through_7_11 AS +VALUES + (1L, 5L), (2L, 6L), (3L, 7L), (4L, 8L), (5L, 9L), (6L, 10L), (7L, 11L) AS tab(col1, col2); + +-- Double table +DROP TABLE IF EXISTS t_double_1_1_1_4_through_1_5_1_8; +CREATE TABLE t_double_1_1_1_4_through_1_5_1_8 AS +SELECT CAST(col1 AS DOUBLE) AS col1, CAST(col2 AS DOUBLE) AS col2 +FROM VALUES + (1.1, 1.4), (1.2, 1.5), (1.3, 1.6), (1.4, 1.7), (1.5, 1.8) AS tab(col1, col2); + +-- Float table (must cast, otherwise Spark will store DOUBLEs) +DROP TABLE IF EXISTS t_float_1_1_1_4_through_1_5_1_8; +CREATE TABLE t_float_1_1_1_4_through_1_5_1_8 AS +SELECT CAST(col1 AS FLOAT) col1, CAST(col2 AS FLOAT) col2 +FROM VALUES + (1.1, 1.4), (1.2, 1.5), (1.3, 1.6), (1.4, 1.7), (1.5, 1.8) AS tab(col1, col2); + +-- String table +DROP TABLE IF EXISTS t_string_a_d_through_e_h; +CREATE TABLE t_string_a_d_through_e_h AS +VALUES + ('a', 'd'), ('b', 'e'), ('c', 'f'), ('d', 'g'), ('e', 'h') AS tab(col1, col2); + +-- Binary table +DROP TABLE IF EXISTS t_binary_a_b_through_e_f; +CREATE TABLE t_binary_a_b_through_e_f AS +VALUES + (X'A', X'B'), (X'B', X'C'), (X'C', X'D'), (X'D', X'E'), (X'E', X'F') AS tab(col1, col2); + +-- Array Integer table +DROP TABLE IF EXISTS t_array_int_1_3_through_4_6; +CREATE TABLE t_array_int_1_3_through_4_6 AS +VALUES + (ARRAY(1), ARRAY(3)), + (ARRAY(2), ARRAY(4)), + (ARRAY(3), ARRAY(5)), + (ARRAY(4), ARRAY(6)) AS tab(col1, col2); + +-- Array Long table +DROP TABLE IF EXISTS t_array_long_1_3_through_4_6; +CREATE TABLE t_array_long_1_3_through_4_6 AS +VALUES + (ARRAY(1L), ARRAY(3L)), + (ARRAY(2L), ARRAY(4L)), + (ARRAY(3L), ARRAY(5L)), + (ARRAY(4L), ARRAY(6L)) AS tab(col1, col2); + +DROP TABLE IF EXISTS t_string_collation; +-- `\u030A` is the "combining ring above" Unicode character: https://www.compart.com/en/unicode/U+030A +-- `\uFFFD is the Unicode replacement character +-- `\xC1` is an invalid Unicode byte. +-- `\x80` is a Unicode continuation byte, that is it cannot be the first byte of a multi-byte UTF8 character. +-- All strings are different based on the UTF8_BINARY collation. +-- The first and second strings are equal for any collation with the RTRIM modifier, and equal to the empty string. +-- The last three strings are respectively equal to the next last three strings for any collation with the RTRIM modifier. +-- The strings "\xC1", "\x80" and "\uFFFD" are equal for all collations except UTF8_BINARY. +-- The (sub)strings `å` and `a\u030A` are equal for the UNICODE family of collations. +-- `å` is the lowercase version of `Å`. +CREATE TABLE t_string_collation AS +VALUES + (''), (' '), (CAST(X'C1' AS STRING)), (CAST(X'80' AS STRING)), + ('\uFFFD'), ('Å'), ('å'), ('a\u030A'), ('Å '), ('å '), + ('a\u030A ') AS tab(col1); + +-- Test basic theta_sketch_agg with IntegerType from table +SELECT theta_sketch_estimate(theta_sketch_agg(col1)) AS result FROM t_int_1_5_through_7_11; + +-- Test theta_sketch_agg with ArrayType(IntegerType) values from table +SELECT theta_sketch_estimate(theta_sketch_agg(col1)) FROM t_array_int_1_3_through_4_6; + +-- Test theta_sketch_agg with ArrayType(LongType) values from table +SELECT theta_sketch_estimate(theta_sketch_agg(col2)) FROM t_array_long_1_3_through_4_6; + +-- Test theta_sketch_agg with BinaryType values from table +SELECT theta_sketch_estimate(theta_sketch_agg(col1)) FROM t_binary_a_b_through_e_f; + +-- Test theta_sketch_agg with DoubleType values from table +SELECT theta_sketch_estimate(theta_sketch_agg(col1)) FROM t_double_1_1_1_4_through_1_5_1_8; + +-- Test theta_sketch_agg with FloatType values from table (promoted to Double internally) +SELECT theta_sketch_estimate(theta_sketch_agg(col2)) FROM t_float_1_1_1_4_through_1_5_1_8; + +-- Test theta_sketch_agg with IntegerType and explicit lgNomEntries parameter +SELECT theta_sketch_estimate(theta_sketch_agg(col1, 22)) FROM t_int_1_5_through_7_11; + +-- Test theta_sketch_agg with LongType values +SELECT theta_sketch_estimate(theta_sketch_agg(col1)) FROM t_long_1_5_through_7_11; + +-- Test theta_sketch_agg with StringType values +SELECT theta_sketch_estimate(theta_sketch_agg(col1)) FROM t_string_a_d_through_e_h; + +-- Test theta_union function with IntegerType sketches +SELECT theta_sketch_estimate( + theta_union( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_int_1_5_through_7_11; + +-- Test theta_union function with LongType sketches and explicit lgNomEntries parameter +SELECT theta_sketch_estimate( + theta_union( + theta_sketch_agg(col1, 15), + theta_sketch_agg(col2))) FROM t_long_1_5_through_7_11; + +-- Test theta_union function with DoubleType sketches +SELECT theta_sketch_estimate( + theta_union( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_double_1_1_1_4_through_1_5_1_8; + +-- Test theta_union function with FloatType sketches and explicit lgNomEntries parameter +SELECT theta_sketch_estimate( + theta_union( + theta_sketch_agg(col1, 6), + theta_sketch_agg(col2, 15), 15)) FROM t_float_1_1_1_4_through_1_5_1_8; + +-- Test theta_union function with StringType sketches +SELECT theta_sketch_estimate( + theta_union( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_string_a_d_through_e_h; + +-- Test theta_union function with BinaryType sketches and explicit lgNomEntries parameter +SELECT theta_sketch_estimate( + theta_union( + theta_sketch_agg(col1), + theta_sketch_agg(col2), 20)) FROM t_binary_a_b_through_e_f; + +-- Test theta_union function with ArrayType(IntegerType) sketches +SELECT theta_sketch_estimate( + theta_union( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_array_int_1_3_through_4_6; + +-- Test theta_union function with ArrayType(LongType) sketches and explicit lgNomEntries parameter +SELECT theta_sketch_estimate( + theta_union( + theta_sketch_agg(col1), + theta_sketch_agg(col2, 13))) FROM t_array_long_1_3_through_4_6; + +-- Test theta_intersection function with IntegerType sketches +SELECT theta_sketch_estimate( + theta_intersection( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_int_1_5_through_7_11; + +-- Test theta_intersection function with LongType sketches and explicit lgNomEntries parameter +SELECT theta_sketch_estimate( + theta_intersection( + theta_sketch_agg(col1, 5), + theta_sketch_agg(col2, 12))) FROM t_long_1_5_through_7_11; + +-- Test theta_intersection function with DoubleType sketches +SELECT theta_sketch_estimate( + theta_intersection( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_double_1_1_1_4_through_1_5_1_8; + +-- Test theta_intersection function with FloatType sketches and explicit lgNomEntries parameter +SELECT theta_sketch_estimate( + theta_intersection( + theta_sketch_agg(col1, 5), + theta_sketch_agg(col2))) FROM t_float_1_1_1_4_through_1_5_1_8; + +-- Test theta_intersection function with StringType sketches +SELECT theta_sketch_estimate( + theta_intersection( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_string_a_d_through_e_h; + +-- Test theta_intersection function with BinaryType sketches and explicit lgNomEntries parameter +SELECT theta_sketch_estimate( + theta_intersection( + theta_sketch_agg(col1), + theta_sketch_agg(col2, 22))) FROM t_binary_a_b_through_e_f; + +-- Test theta_intersection function with ArrayType(IntegerType) sketches +SELECT theta_sketch_estimate( + theta_intersection( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_array_int_1_3_through_4_6; + +-- Test theta_intersection function with ArrayType(LongType) sketches and explicit lgNomEntries parameter +SELECT theta_sketch_estimate( + theta_intersection( + theta_sketch_agg(col1), + theta_sketch_agg(col2, 10))) FROM t_array_long_1_3_through_4_6; + +-- Test theta_difference function with IntegerType sketches +SELECT theta_sketch_estimate( + theta_difference( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_int_1_5_through_7_11; + +-- Test theta_difference function with LongType sketches and explicit lgNomEntries parameter +SELECT theta_sketch_estimate( + theta_difference( + theta_sketch_agg(col1), + theta_sketch_agg(col2, 5))) FROM t_long_1_5_through_7_11; + +-- Test theta_difference function with DoubleType sketches +SELECT theta_sketch_estimate( + theta_difference( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_double_1_1_1_4_through_1_5_1_8; + +-- Test theta_difference function with FloatType sketches and explicit lgNomEntries parameter +SELECT theta_sketch_estimate( + theta_difference( + theta_sketch_agg(col1, 12), + theta_sketch_agg(col2))) FROM t_float_1_1_1_4_through_1_5_1_8; + +-- Test theta_difference function with StringType sketches +SELECT theta_sketch_estimate( + theta_difference( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_string_a_d_through_e_h; + +-- Test theta_difference function with BinaryType sketches and explicit lgNomEntries parameter +SELECT theta_sketch_estimate( + theta_difference( + theta_sketch_agg(col1, 6), + theta_sketch_agg(col2, 8))) FROM t_binary_a_b_through_e_f; + +-- Test theta_difference function with ArrayType(IntegerType) sketches +SELECT theta_sketch_estimate( + theta_difference( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_array_int_1_3_through_4_6; + +-- Test theta_difference function with ArrayType(LongType) sketches and explicit lgNomEntries parameter +SELECT theta_sketch_estimate( + theta_difference( + theta_sketch_agg(col1), + theta_sketch_agg(col2, 4))) FROM t_array_long_1_3_through_4_6; + +-- Test theta_union_agg with IntegerType and explicit lgNomEntries parameter +SELECT theta_sketch_estimate(theta_union_agg(sketch, 15)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_int_1_5_through_7_11 + UNION ALL + SELECT theta_sketch_agg(col2, 20) as sketch FROM t_int_1_5_through_7_11); + +-- Test theta_union_agg with DoubleType sketches and explicit lgNomEntries parameter +SELECT theta_sketch_estimate(theta_union_agg(sketch, 12)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_double_1_1_1_4_through_1_5_1_8 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_double_1_1_1_4_through_1_5_1_8); + +-- Test theta_union_agg with StringType sketches and explicit lgNomEntries parameter +SELECT theta_sketch_estimate(theta_union_agg(sketch, 14)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_string_a_d_through_e_h + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_string_a_d_through_e_h); + +-- Test theta_union_agg with LongType sketches and explicit lgNomEntries parameter +SELECT theta_sketch_estimate(theta_union_agg(sketch, 10)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_long_1_5_through_7_11 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_long_1_5_through_7_11); + +-- Test theta_union_agg with FloatType sketches and explicit lgNomEntries parameter +SELECT theta_sketch_estimate(theta_union_agg(sketch, 6)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_float_1_1_1_4_through_1_5_1_8 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_float_1_1_1_4_through_1_5_1_8); + +-- Test theta_union_agg with BinaryType sketches +SELECT theta_sketch_estimate(theta_union_agg(sketch)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_binary_a_b_through_e_f + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_binary_a_b_through_e_f); + +-- Test theta_union_agg with ArrayType(IntegerType) sketches and explicit lgNomEntries parameter +SELECT theta_sketch_estimate(theta_union_agg(sketch, 12)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_array_int_1_3_through_4_6 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_array_int_1_3_through_4_6); + +-- Test theta_union_agg with ArrayType(LongType) sketches and explicit lgNomEntries parameter +SELECT theta_sketch_estimate(theta_union_agg(sketch, 16)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_array_long_1_3_through_4_6 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_array_long_1_3_through_4_6); + +-- Test theta_intersection_agg with IntegerType sketches +SELECT theta_sketch_estimate(theta_intersection_agg(sketch)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_int_1_5_through_7_11 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_int_1_5_through_7_11); + +-- Test theta_intersection_agg with LongType sketches +SELECT theta_sketch_estimate(theta_intersection_agg(sketch)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_long_1_5_through_7_11 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_long_1_5_through_7_11); + +-- Test theta_intersection_agg with FloatType sketches +SELECT theta_sketch_estimate(theta_intersection_agg(sketch)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_float_1_1_1_4_through_1_5_1_8 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_float_1_1_1_4_through_1_5_1_8); + +-- Test theta_intersection_agg with DoubleType sketches +SELECT theta_sketch_estimate(theta_intersection_agg(sketch)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_double_1_1_1_4_through_1_5_1_8 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_double_1_1_1_4_through_1_5_1_8); + +-- Test theta_intersection_agg with StringType sketches +SELECT theta_sketch_estimate(theta_intersection_agg(sketch)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_string_a_d_through_e_h + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_string_a_d_through_e_h); + +-- Test theta_intersection_agg with BinaryType sketches +SELECT theta_sketch_estimate(theta_intersection_agg(sketch)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_binary_a_b_through_e_f + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_binary_a_b_through_e_f); + +-- Test theta_intersection_agg with ArrayType(IntegerType) sketches +SELECT theta_sketch_estimate(theta_intersection_agg(sketch)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_array_int_1_3_through_4_6 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_array_int_1_3_through_4_6); + +-- Test theta_intersection_agg with ArrayType(LongType) sketches +SELECT theta_sketch_estimate(theta_intersection_agg(sketch)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_array_long_1_3_through_4_6 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_array_long_1_3_through_4_6); + +-- Test theta_sketch_agg with IntegerType and null values (nulls should be ignored) +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES (1), (null), (2), (null), (3) tab(col); + +-- Test theta_sketch_agg with StringType and null values (nulls should be ignored) +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES ('test'), (null), ('null'), (null) tab(col); + +-- Test theta_sketch_agg with LongType and null values (nulls should be ignored) +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES (100L), (null), (200L), (null), (300L) tab(col); + +-- Test theta_sketch_agg with DoubleType and null values (nulls should be ignored) +SELECT theta_sketch_estimate(theta_sketch_agg(CAST(col AS DOUBLE))) +FROM VALUES (1.1), (null), (2.2), (null), (3.3) tab(col); + +-- Test theta_sketch_agg with FloatType and null values (nulls should be ignored) +SELECT theta_sketch_estimate(theta_sketch_agg(CAST(col AS FLOAT))) +FROM VALUES (1.5), (null), (2.5), (null), (3.5) tab(col); + +-- Test theta_sketch_agg with BinaryType and null values (nulls should be ignored) +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES (X'AA'), (null), (X'BB'), (null), (X'CC') tab(col); + +-- Test theta_sketch_agg with ArrayType(IntegerType) and null values (nulls should be ignored) +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES (ARRAY(1, 2)), (null), (ARRAY(3, 4)), (null), (ARRAY(5, 6)) tab(col); + +-- Test theta_sketch_agg with ArrayType(LongType) and null values (nulls should be ignored) +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES (ARRAY(10L, 20L)), (null), (ARRAY(30L, 40L)), (null), (ARRAY(50L, 60L)) tab(col); + +-- Test theta_sketch_agg with arrays containing null elements +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES (ARRAY(1, null)), (ARRAY(1)), (ARRAY(2, null, 3)), (ARRAY(4)) tab(col); + +-- Test theta_sketch_agg with arrays containing null elements (LongType) +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES (ARRAY(10L, null)), (ARRAY(10L)), (ARRAY(20L, null, 30L)), (ARRAY(40L)) tab(col); + +-- Test theta_sketch_agg with empty arrays +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES (ARRAY()), (ARRAY(1, 2)), (ARRAY()), (ARRAY(3, 4)) tab(col); + +-- Test theta_sketch_agg with empty strings +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES (''), ('a'), (''), ('b'), ('c') tab(col); + +-- Test theta_sketch_agg with empty binary data +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES (X''), (X'01'), (X'02'), (X'03'), (CAST(' ' AS BINARY)), (X'e280'), (X'c1'), (X'c120') tab(col); + +-- Test theta_sketch_agg with collated string data +SELECT theta_sketch_estimate(theta_sketch_agg(col1)) utf8_b FROM t_string_collation; +SELECT theta_sketch_estimate(theta_sketch_agg(col1 COLLATE UTF8_LCASE)) utf8_lc FROM t_string_collation; +SELECT theta_sketch_estimate(theta_sketch_agg(col1 COLLATE UNICODE)) unicode FROM t_string_collation; +SELECT theta_sketch_estimate(theta_sketch_agg(col1 COLLATE UNICODE_CI)) unicode_ci FROM t_string_collation; +SELECT theta_sketch_estimate(theta_sketch_agg(col1 COLLATE UTF8_BINARY_RTRIM)) utf8_b_rt FROM t_string_collation; +SELECT theta_sketch_estimate(theta_sketch_agg(col1 COLLATE UTF8_LCASE_RTRIM)) utf8_lc_rt FROM t_string_collation; +SELECT theta_sketch_estimate(theta_sketch_agg(col1 COLLATE UNICODE_RTRIM)) unicode_rt FROM t_string_collation; +SELECT theta_sketch_estimate(theta_sketch_agg(col1 COLLATE UNICODE_CI_RTRIM)) unicode_ci_rt FROM t_string_collation; + +-- Comprehensive test using all ThetaSketch functions in a single query +-- This query demonstrates the full workflow: aggregation -> union -> intersection -> difference -> estimate +WITH sketches AS ( + SELECT 'int_sketch' as sketch_type, theta_sketch_agg(col1, 12) as sketch FROM t_int_1_5_through_7_11 + UNION ALL + SELECT 'long_sketch' as sketch_type, theta_sketch_agg(col1, 15) as sketch FROM t_long_1_5_through_7_11 + UNION ALL + SELECT 'double_sketch' as sketch_type, theta_sketch_agg(col1, 10) as sketch FROM t_double_1_1_1_4_through_1_5_1_8 + UNION ALL + SELECT 'string_sketch' as sketch_type, theta_sketch_agg(col1, 14) as sketch FROM t_string_a_d_through_e_h +), +union_result AS ( + SELECT theta_union_agg(sketch, 16) as union_sketch FROM sketches +), +individual_sketches AS ( + SELECT theta_sketch_agg(col1, 12) as sketch1, theta_sketch_agg(col2, 12) as sketch2 FROM t_int_1_5_through_7_11 +) +SELECT + -- Basic estimate from union of all sketches + theta_sketch_estimate((SELECT union_sketch FROM union_result)) as union_estimate, + -- Union of two individual sketches + theta_sketch_estimate(theta_union(sketch1, sketch2, 15)) as binary_union_estimate, + -- Intersection of two individual sketches + theta_sketch_estimate(theta_intersection(sketch1, sketch2)) as intersection_estimate, + -- Difference of two individual sketches + theta_sketch_estimate(theta_difference(sketch1, sketch2)) as difference_estimate +FROM individual_sketches; + +-- Negative test cases + +-- Test theta_sketch_agg with lgNomEntries value of 2 (too low, minimum is 4) - should fail +SELECT theta_sketch_agg(col, 2) +FROM VALUES (50), (60), (60) tab(col); + +-- Test theta_sketch_agg with lgNomEntries value of 40 (too high, maximum is 26) - should fail +SELECT theta_sketch_agg(col, 40) +FROM VALUES (50), (60), (60) tab(col); + +-- Test theta_union_agg with lgNomEntries value of 3 (too low, minimum is 4) - should fail +SELECT theta_union_agg(sketch, 3) +FROM (SELECT theta_sketch_agg(col, 12) as sketch + FROM VALUES (1) AS tab(col) + UNION ALL + SELECT theta_sketch_agg(col, 20) as sketch + FROM VALUES (1) AS tab(col)); + +-- Test theta_union_agg with lgNomEntries value of 27 (too high, maximum is 26) - should fail +SELECT theta_union_agg(sketch, 27) +FROM (SELECT theta_sketch_agg(col, 12) as sketch + FROM VALUES (1) AS tab(col) + UNION ALL + 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 + (1, 4), + (2, 5), + (3, 6) AS tab(col1, col2); + +-- Test theta_intersection with integers (1, 2) instead of binary sketch data - should fail +SELECT theta_intersection(1, 2) + FROM VALUES + (1, 4), + (2, 5), + (3, 6) AS tab(col1, col2); + +-- Test theta_difference with integers (1, 2) instead of binary sketch data - should fail +SELECT theta_difference(1, 2) + FROM VALUES + (1, 4), + (2, 5), + (3, 6) AS tab(col1, col2); + +-- Test theta_union with string 'invalid' instead of integer for lgNomEntries parameter - should fail +SELECT theta_union( + theta_sketch_agg(col1), + theta_sketch_agg(col2), 'invalid') + FROM VALUES + (1, 4), + (2, 5), + (3, 6) AS tab(col1, col2); + +-- Test theta_intersection with string 'invalid_sketch' instead of binary sketch data - should fail +SELECT theta_intersection( + theta_sketch_agg(col1), + 'invalid_sketch') + FROM VALUES + (1, 4), + (2, 5), + (3, 6) AS tab(col1, col2); + +-- Test theta_sketch_estimate with invalid binary data ('abc') that is not a valid theta sketch - should fail +SELECT theta_sketch_estimate(CAST('abc' AS BINARY)); + +-- Test theta_union with invalid binary data ('abc', 'def') that are not valid theta sketches - should fail +SELECT theta_union(CAST('abc' AS BINARY), CAST('def' AS BINARY)); + +-- Test theta_intersection with invalid binary data ('abc', 'def') that are not valid theta sketches - should fail +SELECT theta_intersection(CAST('abc' AS BINARY), CAST('def' AS BINARY)); + +-- Test theta_difference with invalid binary data ('abc', 'def') that are not valid theta sketches - should fail +SELECT theta_difference(CAST('abc' AS BINARY), CAST('def' AS BINARY)); + +-- Test theta_union_agg with invalid binary data ('abc') that is not a valid theta sketch - should fail +SELECT theta_union_agg(buffer, 15) +FROM (SELECT CAST('abc' AS BINARY) AS buffer); + +-- Test theta_intersection_agg with invalid binary data ('abc') that is not a valid theta sketch - should fail +SELECT theta_intersection_agg(buffer) +FROM (SELECT CAST('abc' AS BINARY) AS buffer); + +-- Clean up +DROP TABLE IF EXISTS t_int_1_5_through_7_11; +DROP TABLE IF EXISTS t_long_1_5_through_7_11; +DROP TABLE IF EXISTS t_double_1_1_1_4_through_1_5_1_8; +DROP TABLE IF EXISTS t_float_1_1_1_4_through_1_5_1_8; +DROP TABLE IF EXISTS t_string_a_d_through_e_h; +DROP TABLE IF EXISTS t_binary_a_b_through_e_f; +DROP TABLE IF EXISTS t_array_int_1_3_through_4_6; +DROP TABLE IF EXISTS t_array_long_1_3_through_4_6; +DROP TABLE IF EXISTS t_string_collation \ No newline at end of file diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/time.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/time.sql new file mode 100644 index 00000000000..b46f74c6576 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/time.sql @@ -0,0 +1,303 @@ +-- time literals, functions and operations + +create temporary view timediff_view as select time'01:02:03' time_start, time'04:05:06' time_end, 'SECOND' unit; + +create temporary view time_view as select '11:53:26.038344' time_str, 'HH:mm:ss.SSSSSS' fmt_str; + +create temporary view trunc_time_view as select time'11:53:26.038344' time_val, 'MINUTE' unit; + +select time '16:39:45\t'; + +select to_time(null), to_time('01:02:03'), to_time('23-59-59.999999', 'HH-mm-ss.SSSSSS'); +select to_time(time_str, fmt_str) from time_view; + +-- missing fields in `to_time` +select to_time("11", "HH"); +-- invalid: there is no 13 hours +select to_time("13-60", "HH-mm"); + +select try_to_time(null), try_to_time('00:12:00'), try_to_time('01:02:03', 'HH:mm:ss'); +select try_to_time(1); +select try_to_time('12:48:31 abc'); +select try_to_time('10:11:12.', 'HH:mm:ss.SSSSSS'); +select try_to_time("02-69", "HH-mm"); +select try_to_time('11:12:13', 'HH:mm:ss', 'SSSSSS'); + +select make_time(1, 18, 19.87); +-- invalid cases +select make_time(null, 18, 19.87); +select make_time(1, null, 19.87); +select make_time(1, 18, null); +select make_time(-1, 18, 19.87); +select make_time(1, 60, 19.87); +select make_time(1, 18, 60.0); +select make_time(1, 18, 9999999999.999999); +select make_time(1, 18, -999999999.999999); +-- Full seconds overflows to a valid seconds integer when converted from long to int +select make_time(1, 18, 4294967297.999999); + +select second(to_time('23-59-58.987654', 'HH-mm-ss.SSSSSS')); +select minute(to_time('23-59-58.987654', 'HH-mm-ss.SSSSSS')); +select hour(to_time('23-59-58.987654', 'HH-mm-ss.SSSSSS')); + +select extract(HOUR from time'00:59:00.987654'); +select extract(H from time'23:59:00.987654'); +select extract(HOURS from time'00:00:00'); +select extract(HR from time'23:59:59.999999'); +select extract(HRS from time'23:59:58.987654'); + +select extract(MINUTE from time'00:59:00.987654'); +select extract(M from time'23:59:00.987654'); +select extract(M from time'23:00:59.987654'); +select extract(MIN from time'00:00:00'); +select extract(MINS from time'23:59:59.999999'); +select extract(MINUTES from time'23:59:58.987654'); + +select extract(SECOND from time'00:59:00.987654'); +select extract(SECOND from time'00:0:00.000001'); +select extract(SECOND from time'00:0:00.100000'); +select extract(SECOND from time'00:0:00.100001'); +select extract(S from time'23:59:00.987654'); +select extract(SEC from time'00:00:00'); +select extract(SEC from time'00:00:00.000000'); +select extract(SECONDS from time'23:59:59.999999'); +select extract(SECS from time'23:59:58.987654'); + +-- test with precisions +select extract(SECOND FROM cast('09:08:01.987654' as time(0))); +select extract(SECOND FROM cast('09:08:01.987654' as time(1))); +select extract(SECOND FROM cast('09:08:01.987654' as time(2))); +select extract(SECOND FROM cast('09:08:01.987654' as time(3))); +select extract(SECOND FROM cast('09:08:01.987654' as time(4))); +select extract(SECOND FROM cast('09:08:01.987654' as time(5))); +select extract(SECOND FROM cast('09:08:01.987654' as time(6))); + +-- valid time literals +SELECT TIME'0:0:0'; +SELECT TIME'01:02:03'; +SELECT TIME'12:34:56'; +SELECT TIME'23:59:59'; +SELECT TIME'23:59:59.9'; +SELECT TIME'23:59:59.99'; +SELECT TIME'23:59:59.999'; +SELECT TIME'23:59:59.9999'; +SELECT TIME'23:59:59.99999'; +SELECT TIME'23:59:59.999999'; +SELECT TIME'01:02:03 AM'; +SELECT TIME'01:02:03 am'; +SELECT TIME'01:02:03 Am'; +SELECT TIME'01:02:03 PM'; +SELECT TIME'01:02:03 pm'; +SELECT TIME'01:02:03 pM'; + +-- invalid time literals +SELECT TIME'00:00:60'; +SELECT TIME'00:60:00'; +SELECT TIME'24:00:00'; +SELECT TIME'00:00:00 AM'; +SELECT TIME'00:00:00 PM'; +SELECT TIME'12:00:60 AM'; +SELECT TIME'12:00:60 PM'; +SELECT TIME'12:60:00 AM'; +SELECT TIME'12:60:00 PM'; +SELECT TIME'13:00:00 AM'; +SELECT TIME'13:00:00 PM'; +SELECT TIME'24:00:00 AM'; +SELECT TIME'24:00:00 PM'; + +-- cast string to time +SELECT cast("12:34:56" as time); +SELECT cast("12:34:56.789" as time(3)); +SELECT cast("12:34:56.789" as time(6)); +SELECT cast("12:34:56.789012" as time without time zone); + +-- cast time to time +SELECT cast(cast('12:00' as time(0)) as time(2)); +SELECT cast(('23:59:59.001001' :: time(6)) as time(4)); +SELECT cast(time'11:59:59.999999' as time without time zone); + +-- SPARK-51554: time truncation. +SELECT time_trunc('HOUR', time'12:34:56'); +SELECT time_trunc('MINUTE', time'12:34:56'); +SELECT time_trunc('SECOND', time'12:34:56'); +SELECT time_trunc('MILLISECOND', time'12:34:56'); +SELECT time_trunc('MICROSECOND', time'12:34:56'); + +-- SPARK-51554: time truncation with various time precisions. +SELECT time_trunc('HOUR', time'12:34:56.1'); +SELECT time_trunc('MINUTE', time'12:34:56.1'); +SELECT time_trunc('SECOND', time'12:34:56.1'); +SELECT time_trunc('MILLISECOND', time'12:34:56.1'); +SELECT time_trunc('MICROSECOND', time'12:34:56.1'); +SELECT time_trunc('HOUR', time'12:34:56.123456'); +SELECT time_trunc('MINUTE', time'12:34:56.123456'); +SELECT time_trunc('SECOND', time'12:34:56.123456'); +SELECT time_trunc('MILLISECOND', time'12:34:56.123456'); +SELECT time_trunc('MICROSECOND', time'12:34:56.123456'); +SELECT time_trunc('HOUR', time'12:34:56.123456789'); +SELECT time_trunc('MINUTE', time'12:34:56.123456789'); +SELECT time_trunc('SECOND', time'12:34:56.123456789'); +SELECT time_trunc('MILLISECOND', time'12:34:56.123456789'); +SELECT time_trunc('MICROSECOND', time'12:34:56.123456789'); + +-- SPARK-51554: time truncation with various unit cases. +SELECT time_trunc('hour', time'12:34:56'); +SELECT time_trunc('MiNuTe', time'12:34:56'); +SELECT time_trunc('sEcOnD', time'12:34:56'); +SELECT time_trunc('Millisecond', time'12:34:56'); +SELECT time_trunc('microseconD', time'12:34:56'); + +-- SPARK-51554: time truncation with zero time. +SELECT time_trunc('HOUR', time'00:00:00'); +SELECT time_trunc('MINUTE', time'00:00:00'); +SELECT time_trunc('SECOND', time'00:00:00'); +SELECT time_trunc('MILLISECOND', time'00:00:00'); +SELECT time_trunc('MICROSECOND', time'00:00:00'); +-- SPARK-51554: time truncation with small time. +SELECT time_trunc('HOUR', time'00:00:00.000000001'); +SELECT time_trunc('MINUTE', time'00:00:00.000000001'); +SELECT time_trunc('SECOND', time'00:00:00.000000001'); +SELECT time_trunc('MILLISECOND', time'00:00:00.000000001'); +SELECT time_trunc('MICROSECOND', time'00:00:00.000000001'); +-- SPARK-51554: time truncation with max time. +SELECT time_trunc('HOUR', time'23:59:59.999999999'); +SELECT time_trunc('MINUTE', time'23:59:59.999999999'); +SELECT time_trunc('SECOND', time'23:59:59.999999999'); +SELECT time_trunc('MILLISECOND', time'23:59:59.999999999'); +SELECT time_trunc('MICROSECOND', time'23:59:59.999999999'); + +-- SPARK-51554: time truncation with invalid unit. +SELECT time_trunc('', time'12:34:56'); +SELECT time_trunc(' ', time'12:34:56'); +SELECT time_trunc('MS', time'12:34:56'); +SELECT time_trunc('DAY', time'12:34:56'); +SELECT time_trunc('WEEK', time'12:34:56'); +SELECT time_trunc('ABCD', time'12:34:56'); +SELECT time_trunc('QUARTER', time'12:34:56'); +SELECT time_trunc('INVALID', time'12:34:56'); +SELECT time_trunc('INVALID_UNIT', time'12:34:56'); + +-- SPARK-51554: time truncation with null inputs. +SELECT time_trunc('HOUR', NULL); +SELECT time_trunc(NULL, time'12:34:56'); +SELECT time_trunc(NULL, NULL); + +-- SPARK-51554: time truncation with table columns. +SELECT time_trunc('HOUR', time_val) FROM trunc_time_view; +SELECT time_trunc(unit, time'12:34:56') FROM trunc_time_view; +SELECT time_trunc(unit, time_val) FROM trunc_time_view; + +-- SPARK-51562: test time function (i.e. alias for casting to time type). +SELECT time("12:34:56"); +SELECT time("12:34:56.789"); +SELECT time("12:34:56.789012"); +SELECT time(cast('12:00' as time(0))); +SELECT time(('23:59:59.001001' :: time(6))); +SELECT time(time'11:59:59.999999'); + +-- +/- ANSI day-time intervals +SELECT '12:43:33.1234' :: TIME(4) + INTERVAL '01:04:05.56' HOUR TO SECOND; +SELECT TIME'08:30' + NULL; +SELECT NULL + TIME'08:30'; +SELECT TIME'00:00:00.0101' + 1; +SELECT TIME'12:30' - INTERVAL '12:29:59.000001' HOUR TO SECOND; +SELECT '23:59:59.999999' :: TIME - INTERVAL '23:59:59.999999' HOUR TO SECOND; +SELECT '00:00:00.0001' :: TIME(4) - INTERVAL '0 00:00:00.0001' DAY TO SECOND; +SELECT '08:30' :: TIME(0) - INTERVAL '6' HOUR; +SELECT '10:00:01' :: TIME(1) - INTERVAL '1' MONTH; + +-- SPARK-51555: time difference. +SELECT time_diff('HOUR', time'00:00:00', time'12:34:56'); +SELECT time_diff('MINUTE', time'00:00:00', time'12:34:56'); +SELECT time_diff('SECOND', time'00:00:00', time'12:34:56'); +SELECT time_diff('MILLISECOND', time'00:00:00', time'12:34:56'); +SELECT time_diff('MICROSECOND', time'00:00:00', time'12:34:56'); + +-- SPARK-51555: positive and negative time difference. +SELECT time_diff('HOUR', time'01:02:03', time'12:34:56'); +SELECT time_diff('MINUTE', time'01:02:03', time'12:34:56'); +SELECT time_diff('SECOND', time'01:02:03', time'12:34:56'); +SELECT time_diff('HOUR', time'12:34:56', time'01:02:03'); +SELECT time_diff('MINUTE', time'12:34:56', time'01:02:03'); +SELECT time_diff('SECOND', time'12:34:56', time'01:02:03'); + +-- SPARK-51555: time difference with various time precisions. +SELECT time_diff('HOUR', time'00:00:00', time'12:34:56.1'); +SELECT time_diff('MINUTE', time'00:00:00', time'12:34:56.1'); +SELECT time_diff('SECOND', time'00:00:00', time'12:34:56.1'); +SELECT time_diff('MILLISECOND', time'00:00:00', time'12:34:56.1'); +SELECT time_diff('MICROSECOND', time'00:00:00', time'12:34:56.1'); +SELECT time_diff('HOUR', time'00:00:00', time'12:34:56.123456'); +SELECT time_diff('MINUTE', time'00:00:00', time'12:34:56.123456'); +SELECT time_diff('SECOND', time'00:00:00', time'12:34:56.123456'); +SELECT time_diff('MILLISECOND', time'00:00:00', time'12:34:56.123456'); +SELECT time_diff('MICROSECOND', time'00:00:00', time'12:34:56.123456'); +SELECT time_diff('HOUR', time'00:00:00', time'12:34:56.123456789'); +SELECT time_diff('MINUTE', time'00:00:00', time'12:34:56.123456789'); +SELECT time_diff('SECOND', time'00:00:00', time'12:34:56.123456789'); +SELECT time_diff('MILLISECOND', time'00:00:00', time'12:34:56.123456789'); +SELECT time_diff('MICROSECOND', time'00:00:00', time'12:34:56.123456789'); + +-- SPARK-51555: time difference with various unit cases. +SELECT time_diff('hour', time'00:00:00', time'12:34:56'); +SELECT time_diff('MiNuTe', time'00:00:00', time'12:34:56'); +SELECT time_diff('sEcOnD', time'00:00:00', time'12:34:56'); +SELECT time_diff('Millisecond', time'00:00:00', time'12:34:56'); +SELECT time_diff('microseconD', time'00:00:00', time'12:34:56'); + +-- SPARK-51555: time difference with zero time. +SELECT time_diff('HOUR', time'00:00:00', time'00:00:00'); +SELECT time_diff('MINUTE', time'00:00:00', time'00:00:00'); +SELECT time_diff('SECOND', time'00:00:00', time'00:00:00'); +SELECT time_diff('MILLISECOND', time'00:00:00', time'00:00:00'); +SELECT time_diff('MICROSECOND', time'00:00:00', time'00:00:00'); +-- SPARK-51555: time difference with small time. +SELECT time_diff('HOUR', time'00:00:00', time'00:00:00.000000001'); +SELECT time_diff('MINUTE', time'00:00:00', time'00:00:00.000000001'); +SELECT time_diff('SECOND', time'00:00:00', time'00:00:00.000000001'); +SELECT time_diff('MILLISECOND', time'00:00:00', time'00:00:00.000000001'); +SELECT time_diff('MICROSECOND', time'00:00:00', time'00:00:00.000000001'); +-- SPARK-51555: time difference with max time. +SELECT time_diff('HOUR', time'00:00:00', time'23:59:59.999999999'); +SELECT time_diff('MINUTE', time'00:00:00', time'23:59:59.999999999'); +SELECT time_diff('SECOND', time'00:00:00', time'23:59:59.999999999'); +SELECT time_diff('MILLISECOND', time'00:00:00', time'23:59:59.999999999'); +SELECT time_diff('MICROSECOND', time'00:00:00', time'23:59:59.999999999'); + +-- SPARK-51555: time difference with invalid unit. +SELECT time_diff('', time'00:00:00', time'12:34:56'); +SELECT time_diff(' ', time'00:00:00', time'12:34:56'); +SELECT time_diff('MS', time'00:00:00', time'12:34:56'); +SELECT time_diff('DAY', time'00:00:00', time'12:34:56'); +SELECT time_diff('WEEK', time'00:00:00', time'12:34:56'); +SELECT time_diff('ABCD', time'00:00:00', time'12:34:56'); +SELECT time_diff('QUARTER', time'00:00:00', time'12:34:56'); +SELECT time_diff('INVALID', time'00:00:00', time'12:34:56'); +SELECT time_diff('INVALID_UNIT', time'00:00:00', time'12:34:56'); + +-- SPARK-51555: time difference with null inputs. +SELECT time_diff(NULL, time'00:00:00', time'12:34:56'); +SELECT time_diff('MICROSECOND', NULL, time'12:34:56'); +SELECT time_diff('MICROSECOND', time'00:00:00', NULL); +SELECT time_diff(NULL, NULL, time'12:34:56'); +SELECT time_diff(NULL, time'00:00:00', NULL); +SELECT time_diff('MICROSECOND', NULL, NULL); +SELECT time_diff(NULL, NULL, NULL); + +-- SPARK-51555: time difference with table columns. +SELECT time_diff('SECOND', time_start, time_end) FROM timediff_view; +SELECT time_diff(unit, time'01:02:03', time_end) FROM timediff_view; +SELECT time_diff(unit, time_start, time'04:05:06') FROM timediff_view; +SELECT time_diff('SECOND', time'01:02:03', time_end) FROM timediff_view; +SELECT time_diff('SECOND', time_start, time'04:05:06') FROM timediff_view; +SELECT time_diff(unit, time'01:02:03', time'04:05:06') FROM timediff_view; +SELECT time_diff(unit, time_start, time_end) FROM timediff_view; + +-- Subtract times +SELECT TIME'12:30:41' - TIME'10:00'; +SELECT TIME'08:30' - NULL; +SELECT NULL - TIME'10:32'; +SELECT TIME'12:30:41.123' - TIMESTAMP'2025-07-11 10:00:01'; +SELECT '12:30:41.123' - TIME'10:00:01'; +SELECT '23:59:59.999999' :: TIME(6) - '00:00' :: TIME(0); +SELECT '00:00:00.1234' :: TIME(4) - TIME'23:59:59'; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/timestamp-ltz.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/timestamp-ltz.sql index 28fe4539855..6484383eabc 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/timestamp-ltz.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/timestamp-ltz.sql @@ -15,4 +15,28 @@ SELECT make_timestamp_ltz(2021, 07, 11, 6, 30, 45.678); SELECT make_timestamp_ltz(2021, 07, 11, 6, 30, 45.678, 'CET'); SELECT make_timestamp_ltz(2021, 07, 11, 6, 30, 60.007); +-- TimestampLTZ date/time fields constructor +SELECT make_timestamp_ltz(make_date(2021, 07, 11), make_time(6, 30, 45.678)); +-- Handling NULL input. +SELECT make_timestamp_ltz(NULL, TIME'00:00:00'); +SELECT make_timestamp_ltz(DATE'1970-01-01', NULL); +-- Handling invalid input. +SELECT make_timestamp_ltz(timestamp_ntz'2018-11-17 13:33:33', TIME'0:0:0'); +SELECT make_timestamp_ltz(DATE'2025-06-20', timestamp_ntz'2018-11-17 13:33:33'); +-- Optional timezone is ignored. +SELECT make_timestamp_ltz(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'PST'); +SELECT make_timestamp_ltz(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'CET'); + SELECT convert_timezone('Europe/Brussels', timestamp_ltz'2022-03-23 00:00:00 America/Los_Angeles'); + +-- Try TimestampLTZ date/time fields constructor +SELECT try_make_timestamp_ltz(make_date(2021, 07, 11), make_time(6, 30, 45.678)); +-- Handling NULL input. +SELECT try_make_timestamp_ltz(NULL, TIME'00:00:00'); +SELECT try_make_timestamp_ltz(DATE'1970-01-01', NULL); +-- Handling invalid input. +SELECT try_make_timestamp_ltz(timestamp_ntz'2018-11-17 13:33:33', TIME'0:0:0'); +SELECT try_make_timestamp_ltz(DATE'2025-06-20', timestamp_ntz'2018-11-17 13:33:33'); +-- Optional timezone is ignored. +SELECT try_make_timestamp_ltz(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'PST'); +SELECT try_make_timestamp_ltz(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'CET'); diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/timestamp.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/timestamp.sql index 8e005c995d4..d7db610ac0e 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/timestamp.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/timestamp.sql @@ -26,6 +26,51 @@ SELECT make_timestamp(1, 1, 1, 1, 1, 59.999999); SELECT make_timestamp(1, 1, 1, 1, 1, 99.999999); SELECT make_timestamp(1, 1, 1, 1, 1, 999.999999); +-- SPARK-51415: timestamp date constructor. +SELECT make_timestamp(make_date(2021, 07, 11)); +SELECT make_timestamp(DATE'1970-01-01'); +SELECT make_timestamp(NULL); + +-- SPARK-51415: timestamp date + time constructor. +SELECT make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678)); +SELECT make_timestamp(DATE'1970-01-01', TIME'00:00:00'); +SELECT make_timestamp(NULL, TIME'00:00:00'); +SELECT make_timestamp(DATE'1970-01-01', NULL); +SELECT make_timestamp(NULL, NULL); + +-- SPARK-51415: timestamp date + time + timezone constructor. +SELECT make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'MIT'); +SELECT make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'PST'); +SELECT make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'UTC'); +SELECT make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'CET'); +SELECT make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'JST'); +SELECT make_timestamp(DATE'1970-01-01', TIME'00:00:00', 'UTC'); +SELECT make_timestamp(NULL, TIME'00:00:00', 'UTC'); +SELECT make_timestamp(DATE'1970-01-01', NULL, 'UTC'); +SELECT make_timestamp(DATE'1970-01-01', TIME'00:00:00', NULL); +SELECT make_timestamp(NULL, NULL, 'UTC'); +SELECT make_timestamp(NULL, TIME'00:00:00', NULL); +SELECT make_timestamp(DATE'1970-01-01', NULL, NULL); +SELECT make_timestamp(NULL, NULL, NULL); + +-- SPARK-51415: unsupported input types. +SELECT make_timestamp(timestamp '2018-11-17 13:33:33', TIME'0:0:0', 'CET'); +SELECT make_timestamp(timestamp_ntz '2018-11-17 13:33:33', TIME'0:0:0', 'CET'); +SELECT make_timestamp(DATE'1970-01-01', timestamp '2018-11-17 13:33:33', 'CET'); +SELECT make_timestamp(DATE'1970-01-01', timestamp_ntz '2018-11-17 13:33:33', 'CET'); + +-- SPARK-53113: try_make_timestamp; supported inputs. +SELECT try_make_timestamp(make_date(2021, 07, 11)); +SELECT try_make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678)); +SELECT try_make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'CET'); +-- SPARK-53113: try_make_timestamp; NULL inputs. +SELECT try_make_timestamp(NULL); +SELECT try_make_timestamp(NULL, NULL); +SELECT try_make_timestamp(NULL, NULL, NULL); +-- SPARK-53113: try_make_timestamp; unsupported input types. +SELECT try_make_timestamp(timestamp '2018-11-17 13:33:33', TIME'0:0:0', 'CET'); +SELECT try_make_timestamp(DATE'1970-01-01', timestamp_ntz '2018-11-17 13:33:33', 'CET'); + -- [SPARK-31710] TIMESTAMP_SECONDS, TIMESTAMP_MILLISECONDS and TIMESTAMP_MICROSECONDS that always create timestamp_ltz select TIMESTAMP_SECONDS(1230219000),TIMESTAMP_SECONDS(-1230219000),TIMESTAMP_SECONDS(null); select TIMESTAMP_SECONDS(1.23), TIMESTAMP_SECONDS(1.23d), TIMESTAMP_SECONDS(FLOAT(1.23)); diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/timezone.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/timezone.sql index 105f2816fb5..49153d1d85d 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/timezone.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/timezone.sql @@ -1,3 +1,5 @@ +CREATE TABLE t1(col1 STRING); + -- valid time zones SET TIME ZONE 'Asia/Hong_Kong'; SET TIME ZONE 'GMT+1'; @@ -13,3 +15,8 @@ SET TIME ZONE INTERVAL 24 HOURS; SET TIME ZONE INTERVAL '19:40:32' HOUR TO SECOND; SET TIME ZONE INTERVAL 10 HOURS 'GMT+1'; SET TIME ZONE INTERVAL 10 HOURS 1 MILLISECOND; + +-- Timezone should be applied recursively +SELECT NANVL(col1, NULL) FROM t1; + +DROP TABLE t1; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/try_arithmetic.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/try_arithmetic.sql index c7957e0f392..96cca99e184 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/try_arithmetic.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/try_arithmetic.sql @@ -7,6 +7,7 @@ SELECT try_add(-2147483648, -1); SELECT try_add(9223372036854775807L, 1); SELECT try_add(-9223372036854775808L, -1); SELECT try_add(1, 1.0 / 0.0); +SELECT try_add(sum(1), 1) GROUP BY ALL; -- Date + Integer SELECT try_add(date'2021-01-01', 1); @@ -40,6 +41,7 @@ SELECT try_divide(1L, (9223372036854775807L + 1L)); SELECT try_divide(1, 1.0 / 0.0); SELECT try_divide(1, decimal(0)); SELECT try_divide(1, "0"); +SELECT try_divide(sum(1), 1) GROUP BY ALL; -- Interval / Numeric SELECT try_divide(interval 2 year, 2); @@ -60,6 +62,7 @@ SELECT try_subtract(-9223372036854775808L, 1); SELECT try_subtract(1, (2147483647 + 1)); SELECT try_subtract(1L, (9223372036854775807L + 1L)); SELECT try_subtract(1, 1.0 / 0.0); +SELECT try_subtract(sum(1), 1) GROUP BY ALL; -- Interval - Interval SELECT try_subtract(interval 2 year, interval 3 year); @@ -78,6 +81,7 @@ SELECT try_multiply(-9223372036854775808L, -2); SELECT try_multiply(1, (2147483647 + 1)); SELECT try_multiply(1L, (9223372036854775807L + 1L)); SELECT try_multiply(1, 1.0 / 0.0); +SELECT try_multiply(sum(1), 1) GROUP BY ALL; -- Interval * Numeric SELECT try_multiply(interval 2 year, 2); diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/type-coercion-edge-cases.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/type-coercion-edge-cases.sql new file mode 100644 index 00000000000..7003411385f --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/type-coercion-edge-cases.sql @@ -0,0 +1,12 @@ +CREATE TABLE t1(col1 TIMESTAMP, col2 MAP); + +-- Preserve tags after type coercing aggregate expression children +SELECT MEAN(col1) FROM t1; + +-- Type coercion is applied to recursive data types +SELECT col2.field FROM t1; + +-- Apply type coercion to semi_structured_extract +SELECT NULL:a AS b; + +DROP TABLE t1; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/typeCoercion/native/mapZipWith.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/typeCoercion/native/mapZipWith.sql index 1727ee725db..8195572ad77 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/typeCoercion/native/mapZipWith.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/typeCoercion/native/mapZipWith.sql @@ -15,7 +15,13 @@ CREATE TEMPORARY VIEW various_maps AS SELECT * FROM VALUES ( map('2016-11-15 20:54:00.000', '2016-11-12 20:54:00.000'), map('922337203685477897945456575809789456', 'text'), map(array(1L, 2L), array(1L, 2L)), map(array(1, 2), array(1, 2)), - map(struct(1S, 2L), struct(1S, 2L)), map(struct(1, 2), struct(1, 2)) + map(struct(1S, 2L), struct(1S, 2L)), map(struct(1, 2), struct(1, 2)), + map(float('NaN'), 1), + map(float('NaN'), 2), + map(float('Infinity'), 1), + map(float('Infinity'), 2), + map(float(0.0), 1), + map(float(-0.0), 1) ) AS various_maps( boolean_map, tinyint_map, @@ -29,7 +35,10 @@ CREATE TEMPORARY VIEW various_maps AS SELECT * FROM VALUES ( timestamp_map, string_map1, string_map2, string_map3, string_map4, array_map1, array_map2, - struct_map1, struct_map2 + struct_map1, struct_map2, + float_nan_map1, float_nan_map2, + float_infinity_map1, float_infinity_map2, + float_zero_map, float_neg_zero_map ); SELECT map_zip_with(tinyint_map, smallint_map, (k, v1, v2) -> struct(k, v1, v2)) m @@ -76,3 +85,12 @@ FROM various_maps; SELECT map_zip_with(struct_map1, struct_map2, (k, v1, v2) -> struct(k, v1, v2)) m FROM various_maps; + +SELECT map_zip_with(float_nan_map1, float_nan_map2, (k, v1, v2) -> (v1, v2)) m +FROM various_maps; + +SELECT map_zip_with(float_infinity_map1, float_infinity_map2, (k, v1, v2) -> (v1, v2)) m +FROM various_maps; + +SELECT map_zip_with(float_zero_map, float_neg_zero_map, (k, v1, v2) -> (v1, v2)) m +FROM various_maps; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/union-per-child-output-deduplication.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/union-per-child-output-deduplication.sql new file mode 100644 index 00000000000..f07b7c0b4a5 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/union-per-child-output-deduplication.sql @@ -0,0 +1,81 @@ +DROP TABLE IF EXISTS t1; +DROP VIEW IF EXISTS v1; + +CREATE TABLE t1 (col1 STRING, col2 STRING, col3 STRING); + +CREATE VIEW v1 as SELECT * FROM t1; + +SELECT * +FROM ( + SELECT col1, col2 FROM t1 + UNION + SELECT col3, col2 FROM t1 + UNION + SELECT col2, col2 FROM t1 + ); + +SELECT * +FROM ( + SELECT col1, col2 FROM v1 + UNION + SELECT col3, col2 FROM v1 + UNION + SELECT col2, col2 FROM v1 + ); + +SELECT * +FROM ( + SELECT col1, col2 FROM t1 + UNION + SELECT col3, col2 FROM t1 + UNION + SELECT col2, col2 FROM v1 + ); + +SELECT * +FROM ( + SELECT col1, col2 FROM t1 + UNION + SELECT col3, col2 FROM v1 + UNION + SELECT col2, col2 FROM t1 + ); + +SELECT * +FROM ( + SELECT col1, col2 FROM v1 + UNION + SELECT col3, col2 FROM t1 + UNION + SELECT col2, col2 FROM t1 + ); + +SELECT * +FROM ( + SELECT col1, col2 FROM v1 + UNION + SELECT col3, col2 FROM v1 + UNION + SELECT col2, col2 FROM t1 + ); + +SELECT * +FROM ( + SELECT col1, col2 FROM v1 + UNION + SELECT col3, col2 FROM t1 + UNION + SELECT col2, col2 FROM v1 + ); + +SELECT * +FROM ( + SELECT col1, col2 FROM t1 + UNION + SELECT col3, col2 FROM v1 + UNION + SELECT col2, col2 FROM v1 + ); + +DROP VIEW v1; +DROP TABLE t1; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/union-resolution-edge-cases.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/union-resolution-edge-cases.sql new file mode 100644 index 00000000000..43214fba05c --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/union-resolution-edge-cases.sql @@ -0,0 +1,30 @@ +CREATE TABLE t1(col1 TIMESTAMP, col2 STRING); +CREATE TABLE t2(col1 INT, col2 STRING); + +-- Duplicates in UNION under CTE +WITH cte AS ( + SELECT col1, col1 FROM t1 + UNION + SELECT col1, col1 FROM t1 +) +SELECT col1 FROM cte; + +WITH cte AS ( + SELECT col2, from_utc_timestamp(col1, 'unknown'), col2 FROM t1 + UNION ALL + SELECT col2, from_utc_timestamp(col1, 'unknown'), col2 FROM t1 +) +SELECT * FROM cte; + +-- UNION with outer references in a subquery +SELECT col1 FROM t3 WHERE (col1, col1) IN (SELECT col1, col1 UNION SELECT col1, col1); + +-- SetOperationLike output deduplication across different branches should be done only in context of UNION +SELECT col1, TRIM(col2), col1 FROM t2 UNION SELECT col1, col2, col1 FROM t2; +SELECT col1, TRIM(col2), col1 FROM t2 MINUS SELECT col1, col2, col1 FROM t2; +SELECT col1, LTRIM(col2), col1 FROM t2 MINUS SELECT col1, col2, col1 FROM t2; +SELECT col1, RTRIM(col2), col1 FROM t2 EXCEPT SELECT col1, col2, col1 FROM t2; +SELECT col1, LOWER(col2), col1 FROM t2 INTERSECT SELECT col1, col2, col1 FROM t2; + +DROP TABLE t1; +DROP TABLE t2; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/union.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/union.sql index ab81cc7bbab..01b53c61327 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/union.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/union.sql @@ -1,5 +1,6 @@ CREATE OR REPLACE TEMPORARY VIEW t1 AS VALUES (1, 'a'), (2, 'b') tbl(c1, c2); CREATE OR REPLACE TEMPORARY VIEW t2 AS VALUES (1.0, 1), (2.0, 4) tbl(c1, c2); +CREATE TABLE jsonTable (col1 INT, col2 INT, col3 INT, col4 INT) USING json; -- Simple Union SELECT * @@ -59,6 +60,13 @@ SELECT SUM(t.v) FROM ( SELECT v + v AS v FROM t3 ) t; +-- SPARK-52462: UNION should produce consistent results with different underlying table providers. +SELECT col1, col2, col3, NULLIF('','') AS col4 +FROM jsonTable +UNION ALL +SELECT col2, col2, null AS col3, col4 +FROM jsonTable; + -- Clean-up DROP VIEW IF EXISTS t1; DROP VIEW IF EXISTS t2; @@ -66,3 +74,4 @@ DROP VIEW IF EXISTS t3; DROP VIEW IF EXISTS p1; DROP VIEW IF EXISTS p2; DROP VIEW IF EXISTS p3; +DROP TABLE IF EXISTS jsonTable; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/using-join.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/using-join.sql index f2657a91910..600a6597511 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/using-join.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/using-join.sql @@ -93,3 +93,9 @@ WITH SELECT t1.key FROM t1 FULL OUTER JOIN t2 USING (key) WHERE t1.key NOT LIKE 'bb.%'; + +-- ResolvesNameByHiddenOutput.retainOriginalOutput shouldn't change NameScope output +SELECT * +FROM + ( SELECT col1 FROM VALUES(false) ) LEFT JOIN ( SELECT col1 FROM VALUES(false) ) b USING(col1) +WHERE b.col1; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/variant-field-extractions.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/variant-field-extractions.sql new file mode 100644 index 00000000000..3a5a3c454db --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/variant-field-extractions.sql @@ -0,0 +1,74 @@ +-- Create temp view with Variant columns for testing field extraction and type casting. +CREATE TEMP VIEW variant_test_data AS +SELECT + parse_json('{ "price": 30 }') as int_price_variant, + parse_json('{ "price": 12345.678 }') as double_price_variant, + parse_json('{ "name": "John", "age": 30, "city": "New York", "active": true, "scores": [85, 92, 78] }') as multi_field_variant, + parse_json('{ "item": [ { "model" : "basic", "price" : 6.12 }, { "model" : "medium", "price" : 9.24 } ] }') as array_value_variant, + parse_json('[{ "id": 1, "name": "Alice" }, { "id": 2, "name": "Bob" }, { "id": 3, "name": "Charlie" }]') as array_variant, + parse_json('{ "metadata": { "version": "1.0", "tags": ["important", "urgent"], "nested": { "level": 2, "value": "deep" } } }') as nested_variant, + parse_json('{ "field-name": "value1", "field.name": "value2", "field_name": "value3" }') as special_chars_variant; + +-- Single field extraction and type casting. +select int_price_variant:price from variant_test_data; +select int_price_variant:price::decimal(5, 2) from variant_test_data; +select int_price_variant:price::string from variant_test_data; + +-- Applying an invalid function -- will throw an error. +select double_price_variant:price::decimal(3, 2) from variant_test_data; + +-- Multi-field access. +select multi_field_variant:name, multi_field_variant:age, multi_field_variant:city from variant_test_data; +select multi_field_variant:name::string, multi_field_variant:age::int, multi_field_variant:active::boolean from variant_test_data; +select multi_field_variant:['name'] from variant_test_data; +select multi_field_variant:['age'] from variant_test_data; + +-- Array value access. +select array_value_variant:item[0].model from variant_test_data; +select array_value_variant:item[0].price from variant_test_data; +select array_value_variant:item[1].model from variant_test_data; +select array_value_variant:item[1].price from variant_test_data; + +-- Array access. +select array_variant:[0].id from variant_test_data; +select array_variant:[0].name from variant_test_data; +select array_variant:[1].id from variant_test_data; +select array_variant:[1].name from variant_test_data; + +-- Nested field access. +select nested_variant:metadata.version from variant_test_data; +select nested_variant:metadata.tags[0] from variant_test_data; +select nested_variant:metadata.nested.level from variant_test_data; +select nested_variant:metadata.nested.value from variant_test_data; +select nested_variant:metadata['version'] from variant_test_data; +select nested_variant:metadata['tags'] from variant_test_data; + +-- Special characters. +select special_chars_variant:`field-name`::string from variant_test_data; +select special_chars_variant:['field-name']::string from variant_test_data; +select special_chars_variant:field_name::string from variant_test_data; +select special_chars_variant:['field_name']::string from variant_test_data; +-- Not supported; will return NULL. +select special_chars_variant:`field.name`::string from variant_test_data; +-- Using [] is okay. +select special_chars_variant:['field.name']::string from variant_test_data; + +-- Array operations on Variant arrays. +select multi_field_variant:scores[0]::int + multi_field_variant:scores[1]::int from variant_test_data; +select count(*) from (select explode(cast(multi_field_variant:scores as array)) as score from variant_test_data); + +-- ASTERISK syntax. +select * from variant_test_data; +-- Not supported; will throw an error. +select multi_field_variant:* from variant_test_data; + +-- Type checking: The result of the following would all be 'variant'. +select typeof(multi_field_variant:name) from variant_test_data; +select typeof(multi_field_variant:age) from variant_test_data; +select typeof(multi_field_variant:active) from variant_test_data; +select typeof(multi_field_variant:scores) from variant_test_data; + +-- Variant field access with NULL handling. +select isnull(multi_field_variant:missing_field) from variant_test_data; +select isnotnull(multi_field_variant:name) from variant_test_data; +select coalesce(multi_field_variant:missing_field, 'default_value') from variant_test_data; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/view-conf.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/view-conf.sql new file mode 100644 index 00000000000..5db43e93cc7 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/view-conf.sql @@ -0,0 +1,25 @@ +CREATE OR REPLACE TEMPORARY VIEW testData AS SELECT * FROM VALUES +('a', 1), ('a', 2), ('b', 1), ('b', 2), ('c', 1), ('c', 2), (null, 1), ('c', null), (null, null) +AS testData(ColumnA, ColumnB); + +-- ANSI +SET spark.sql.ansi.enabled = false; + +CREATE TEMPORARY VIEW view_ansi AS SELECT ColumnA + 1 FROM testData; + +SET spark.sql.ansi.enabled = true; + +SELECT * FROM view_ansi; + +-- Case sensitivity +SET spark.sql.caseSensitive = false; + +CREATE TEMPORARY VIEW view_case_sensitivity AS SELECT CoLuMNa FROM testData; + +SET spark.sql.caseSensitive = true; + +SELECT * FROM view_case_sensitivity; + +-- Clean up +DROP VIEW IF EXISTS view_ansi; +DROP VIEW IF EXISTS view_case_sensitivity; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/window-with-aggregates.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/window-with-aggregates.sql new file mode 100644 index 00000000000..7d68d141ed0 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/window-with-aggregates.sql @@ -0,0 +1,186 @@ +SELECT + SUM(col1) OVER () as window_sum +FROM VALUES (1, 2), (3, 4), (5, 6) AS t(col1, col2) +GROUP BY col1, col2 + 1 +ORDER BY SUM(col1), col2 + 1; + +SELECT + col1, + col2 + 1 as computed_col, + SUM(col1) OVER () as total_sum, + AVG(col1) OVER () as avg_col1, + COUNT(*) OVER () as row_count +FROM VALUES (10, 20), (30, 40), (50, 60), (70, 80) AS t(col1, col2) +GROUP BY col1, col2 + 1 +ORDER BY SUM(col1) DESC, col2 + 1 ASC; + +SELECT + col1 % 2 as parity, + SUM(col1) as group_sum, + SUM(SUM(col1)) OVER (PARTITION BY col1 % 2) as partition_sum +FROM VALUES (1, 10), (2, 20), (3, 30), (4, 40), (5, 50) AS t(col1, col2) +GROUP BY col1, col2, col1 % 2 +ORDER BY SUM(col1), col1 % 2; + +SELECT + col1, + MAX(col2) as max_col2, + ROW_NUMBER() OVER (ORDER BY MAX(col2)) as rn, + RANK() OVER (ORDER BY MAX(col2)) as rnk +FROM VALUES (1, 100), (2, 200), (1, 150), (2, 250) AS t(col1, col2) +GROUP BY col1 +ORDER BY MAX(col2), col1; + +SELECT + col1 * 2 as doubled_col1, + col2 + col1 as sum_cols, + COUNT(*) as cnt, + SUM(COUNT(*)) OVER () as total_count +FROM VALUES (1, 10), (2, 20), (3, 30), (4, 40) AS t(col1, col2) +GROUP BY col1 * 2, col2 + col1, col1, col2 +ORDER BY COUNT(*) DESC, col1 * 2; + +SELECT + col1, + SUM(col2) as sum_col2, + SUM(SUM(col2)) OVER (ORDER BY col1 ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as rolling_sum +FROM VALUES (1, 5), (2, 10), (3, 15), (4, 20), (5, 25) AS t(col1, col2) +GROUP BY col1, col2 +ORDER BY SUM(col2), col1; + +SELECT + col1 / 10 as bucket, + SUM(col1) as sum_col1, + AVG(col2) as avg_col2, + MIN(col1) OVER () as global_min, + MAX(SUM(col1)) OVER (PARTITION BY col1 / 10) as bucket_max +FROM VALUES (15, 100), (25, 200), (35, 300), (45, 400), (55, 500) AS t(col1, col2) +GROUP BY col1 / 10, col1, col2 +ORDER BY SUM(col1), AVG(col2); + +SELECT + col1, + COUNT(*) as cnt, + SUM(COUNT(*)) OVER (ORDER BY col1 RANGE BETWEEN 1 PRECEDING AND 1 FOLLOWING) as range_sum +FROM VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd') AS t(col1, col2) +GROUP BY col1, col2 +ORDER BY COUNT(*), col1; + +SELECT + col1, + col2 + 100 as adjusted_col2, + COUNT(*) as cnt, + AVG(COUNT(*)) OVER () as avg_count +FROM VALUES (1, 5), (1, 15), (2, 25), (2, 35), (3, 45) AS t(col1, col2) +GROUP BY col1, col2 + 100, col2 +HAVING COUNT(*) >= 1 +ORDER BY COUNT(*) DESC, col2 + 100; + +SELECT + col1, + MAX(col2) as max_col2, + LAG(MAX(col2)) OVER (ORDER BY col1) as prev_max, + LEAD(MAX(col2)) OVER (ORDER BY col1) as next_max +FROM VALUES (10, 100), (20, 200), (30, 300), (40, 400) AS t(col1, col2) +GROUP BY col1 +ORDER BY MAX(col2), col1; + +SELECT + col1 + col2 as sum_expr, + COUNT(*) as cnt, + PERCENT_RANK() OVER (ORDER BY COUNT(*)) as pct_rank, + CUME_DIST() OVER (ORDER BY COUNT(*)) as cum_dist +FROM VALUES (1, 2), (3, 4), (5, 6), (7, 8) AS t(col1, col2) +GROUP BY col1 + col2, col1, col2 +ORDER BY COUNT(*), col1 + col2; + +SELECT + COALESCE(col1, 0) as safe_col1, + COUNT(col2) as non_null_count, + SUM(COUNT(col2)) OVER () as total_non_null +FROM VALUES (1, 10), (NULL, 20), (3, NULL), (4, 40) AS t(col1, col2) +GROUP BY COALESCE(col1, 0), col1, col2 +ORDER BY COUNT(col2) DESC, COALESCE(col1, 0); + +SELECT + col1, + col2, + SUM(col1) as sum_col1, + AVG(col2) as avg_col2, + MAX(SUM(col1)) OVER () as max_sum_col1, + MIN(AVG(col2)) OVER () as min_avg_col2 +FROM VALUES (1, 100), (2, 200), (3, 300), (4, 400) AS t(col1, col2) +GROUP BY col1, col2 +ORDER BY SUM(col1) + AVG(col2), col1, col2; + + +SELECT + col1, + SUM(col2) as sum_col2, + SUM(SUM(col2)) OVER () as total_sum +FROM VALUES (1, 10), (2, 20), (3, 30) AS t(col1, col2) +GROUP BY col1; + +SELECT + col1 % 2 as parity, + COUNT(*) as cnt, + AVG(col2) as avg_col2, + SUM(COUNT(*)) OVER () as total_count, + MAX(AVG(col2)) OVER () as max_avg +FROM VALUES (1, 100), (2, 200), (3, 300), (4, 400) AS t(col1, col2) +GROUP BY col1 % 2, col1, col2; + +SELECT + col1, + col2, + SUM(col1) as sum_col1, + AVG(SUM(col1)) OVER (PARTITION BY col2) as avg_by_col2 +FROM VALUES (1, 'A'), (2, 'A'), (3, 'B'), (4, 'B') AS t(col1, col2) +GROUP BY col1, col2; + +SELECT + col1 / 10 as bucket, + COUNT(*) as cnt, + MIN(COUNT(*)) OVER () as min_count, + MAX(COUNT(*)) OVER () as max_count +FROM VALUES (15, 'x'), (25, 'y'), (35, 'z') AS t(col1, col2) +GROUP BY col1 / 10, col1, col2; + +SELECT + col1 % 3 as mod_group, + col2, + COUNT(*) as cnt, + SUM(COUNT(*)) OVER (PARTITION BY col1 % 3) as sum_by_mod, + AVG(COUNT(*)) OVER (PARTITION BY col2) as avg_by_col2 +FROM VALUES (1, 'A'), (2, 'B'), (3, 'A'), (4, 'B'), (5, 'A') AS t(col1, col2) +GROUP BY col1 % 3, col2, col1; + +SELECT + col1, + MAX(col2) as max_col2, + FIRST_VALUE(MAX(col2)) OVER (PARTITION BY col1) as first_max +FROM VALUES (1, 100), (1, 150), (2, 200), (2, 250) AS t(col1, col2) +GROUP BY col1; + +SELECT + col1 + col2 as sum_cols, + COUNT(*) as cnt, + SUM(COUNT(*)) OVER () as total_rows, + COUNT(COUNT(*)) OVER () as count_of_groups +FROM VALUES (1, 2), (3, 4), (5, 6) AS t(col1, col2) +GROUP BY col1 + col2, col1, col2; + +SELECT + col1, + SUM(col2) as sum_col2, + SUM(SUM(col2)) OVER (ORDER BY col1 ROWS UNBOUNDED PRECEDING) as running_sum +FROM VALUES (1, 10), (2, 20), (3, 30) AS t(col1, col2) +GROUP BY col1, col2; + +SELECT + col1 / 5 as bucket, + col2 % 2 as parity, + AVG(col1) as avg_col1, + RANK() OVER (PARTITION BY col1 / 5, col2 % 2 ORDER BY AVG(col1)) as rank_in_bucket +FROM VALUES (5, 1), (7, 3), (10, 2), (12, 4), (15, 1) AS t(col1, col2) +GROUP BY col1 / 5, col2 % 2, col1, col2; \ No newline at end of file diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/xml-functions.sql b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/xml-functions.sql index 7e3d21ef753..c2bd2f6d4d4 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/xml-functions.sql +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/inputs/xml-functions.sql @@ -53,6 +53,7 @@ select from_xml( -- infer schema of xml literal with options select schema_of_xml(null); +select schema_of_xml(42); CREATE TEMPORARY VIEW xmlTable(xmlField, a) AS SELECT * FROM VALUES ('

1"2"

', 'a'); SELECT schema_of_xml(xmlField) FROM xmlTable; diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/alias-resolution-edge-cases.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/alias-resolution-edge-cases.sql.out new file mode 100644 index 00000000000..28840992e6f --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/alias-resolution-edge-cases.sql.out @@ -0,0 +1,90 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +CREATE TABLE t1(col1 INT, col2 STRING) +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE t2(col1 STRUCT, a STRING) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT LEN(LOWER('X')) AS a, 1 AS b, b AS c GROUP BY LOWER('X') ORDER BY LOWER('X') +-- !query schema +struct +-- !query output +1 1 1 + + +-- !query +SELECT LEN(LOWER('X')) AS a, 1 AS b, b AS c GROUP BY LOWER('X') HAVING LOWER('X') = 'x' +-- !query schema +struct +-- !query output +1 1 1 + + +-- !query +SELECT col1.field, field FROM VALUES(named_struct('field', 1)) +-- !query schema +struct +-- !query output +1 1 + + +-- !query +SELECT col1.field, field FROM VALUES(map('field', 1)) +-- !query schema +struct +-- !query output +1 1 + + +-- !query +SELECT COUNT(col1) as alias, SUM(col1) + alias FROM t1 GROUP BY ALL +-- !query schema +struct +-- !query output +0 NULL + + +-- !query +SELECT COUNT(col1) as alias, SUM(col1) + alias, SUM(col1) + col1 FROM t1 GROUP BY ALL +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_ALL_IN_GROUP_BY", + "sqlState" : "42803", + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 74, + "stopIndex" : 85, + "fragment" : "GROUP BY ALL" + } ] +} + + +-- !query +DROP TABLE t1 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE t2 +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/array.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/array.sql.out index b5dabfb47f4..90a605734c1 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/array.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/array.sql.out @@ -525,6 +525,214 @@ struct NULL +-- !query +select get(1, 0) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"1\"", + "inputType" : "\"INT\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"get(1, 0)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 16, + "fragment" : "get(1, 0)" + } ] +} + + +-- !query +select get(1, -1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"1\"", + "inputType" : "\"INT\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"get(1, -1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 17, + "fragment" : "get(1, -1)" + } ] +} + + +-- !query +select get('1', 0) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"1\"", + "inputType" : "\"STRING\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"get(1, 0)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 18, + "fragment" : "get('1', 0)" + } ] +} + + +-- !query +select get('1', -1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"1\"", + "inputType" : "\"STRING\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"get(1, -1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 19, + "fragment" : "get('1', -1)" + } ] +} + + +-- !query +select get(null, 0) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"NULL\"", + "inputType" : "\"VOID\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"get(NULL, 0)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 19, + "fragment" : "get(null, 0)" + } ] +} + + +-- !query +select get(null, -1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"NULL\"", + "inputType" : "\"VOID\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"get(NULL, -1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 20, + "fragment" : "get(null, -1)" + } ] +} + + +-- !query +select get(null, null) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"NULL\"", + "inputType" : "\"VOID\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"get(NULL, NULL)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 22, + "fragment" : "get(null, null)" + } ] +} + + +-- !query +select get(CAST (null AS string), 0) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"CAST(NULL AS STRING)\"", + "inputType" : "\"STRING\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"get(CAST(NULL AS STRING), 0)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 36, + "fragment" : "get(CAST (null AS string), 0)" + } ] +} + + -- !query select array_insert(array(1, 2, 3), 3, 4) -- !query schema diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/binary.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/binary.sql.out index 9571d9130f7..bdbf4e538f6 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/binary.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/binary.sql.out @@ -49,3 +49,23 @@ struct2018 Kindergarten Cop + + +-- !query +SELECT from_xml( + to_xml(named_struct('name', binary('Eason'), 'birth', 2018, 'org', binary('Kindergarten Cop'))), + 'name STRING, birth INT, org STRING') +-- !query schema +struct> +-- !query output +{"name":"Eason","birth":2018,"org":"Kindergarten Cop"} + + +-- !query +SELECT from_xml( + to_xml(named_struct('name', binary('Eason'), 'birth', 2018, 'org', binary('Kindergarten Cop'))), + 'name binary, birth INT, org binary') +-- !query schema +struct> +-- !query output +{"name":Eason,"birth":2018,"org":Kindergarten Cop} diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/binary_base64.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/binary_base64.sql.out index ef45d059bc8..0806f175550 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/binary_base64.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/binary_base64.sql.out @@ -49,3 +49,23 @@ struct2018 S2luZGVyZ2FydGVuIENvcA + + +-- !query +SELECT from_xml( + to_xml(named_struct('name', binary('Eason'), 'birth', 2018, 'org', binary('Kindergarten Cop'))), + 'name STRING, birth INT, org STRING') +-- !query schema +struct> +-- !query output +{"name":"RWFzb24","birth":2018,"org":"S2luZGVyZ2FydGVuIENvcA"} + + +-- !query +SELECT from_xml( + to_xml(named_struct('name', binary('Eason'), 'birth', 2018, 'org', binary('Kindergarten Cop'))), + 'name binary, birth INT, org binary') +-- !query schema +struct> +-- !query output +{"name":RWFzb24,"birth":2018,"org":S2luZGVyZ2FydGVuIENvcA} diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/binary_basic.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/binary_basic.sql.out index 0118df765df..ce0d7d5d7f9 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/binary_basic.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/binary_basic.sql.out @@ -49,3 +49,23 @@ struct2018 [75, 105, 110, 100, 101, 114, 103, 97, 114, 116, 101, 110, 32, 67, 111, 112] + + +-- !query +SELECT from_xml( + to_xml(named_struct('name', binary('Eason'), 'birth', 2018, 'org', binary('Kindergarten Cop'))), + 'name STRING, birth INT, org STRING') +-- !query schema +struct> +-- !query output +{"name":"[69, 97, 115, 111, 110]","birth":2018,"org":"[75, 105, 110, 100, 101, 114, 103, 97, 114, 116, 101, 110, 32, 67, 111, 112]"} + + +-- !query +SELECT from_xml( + to_xml(named_struct('name', binary('Eason'), 'birth', 2018, 'org', binary('Kindergarten Cop'))), + 'name binary, birth INT, org binary') +-- !query schema +struct> +-- !query output +{"name":[69, 97, 115, 111, 110],"birth":2018,"org":[75, 105, 110, 100, 101, 114, 103, 97, 114, 116, 101, 110, 32, 67, 111, 112]} diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/binary_hex.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/binary_hex.sql.out index d97f6efae29..b1b23e02ea4 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/binary_hex.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/binary_hex.sql.out @@ -49,3 +49,23 @@ struct2018 4B696E64657267617274656E20436F70 + + +-- !query +SELECT from_xml( + to_xml(named_struct('name', binary('Eason'), 'birth', 2018, 'org', binary('Kindergarten Cop'))), + 'name STRING, birth INT, org STRING') +-- !query schema +struct> +-- !query output +{"name":"4561736F6E","birth":2018,"org":"4B696E64657267617274656E20436F70"} + + +-- !query +SELECT from_xml( + to_xml(named_struct('name', binary('Eason'), 'birth', 2018, 'org', binary('Kindergarten Cop'))), + 'name binary, birth INT, org binary') +-- !query schema +struct> +-- !query output +{"name":4561736F6E,"birth":2018,"org":4B696E64657267617274656E20436F70} diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/binary_hex_discrete.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/binary_hex_discrete.sql.out index e0dc049db83..a07cfd8cacf 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/binary_hex_discrete.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/binary_hex_discrete.sql.out @@ -49,3 +49,23 @@ struct2018 [4B 69 6E 64 65 72 67 61 72 74 65 6E 20 43 6F 70] + + +-- !query +SELECT from_xml( + to_xml(named_struct('name', binary('Eason'), 'birth', 2018, 'org', binary('Kindergarten Cop'))), + 'name STRING, birth INT, org STRING') +-- !query schema +struct> +-- !query output +{"name":"[45 61 73 6F 6E]","birth":2018,"org":"[4B 69 6E 64 65 72 67 61 72 74 65 6E 20 43 6F 70]"} + + +-- !query +SELECT from_xml( + to_xml(named_struct('name', binary('Eason'), 'birth', 2018, 'org', binary('Kindergarten Cop'))), + 'name binary, birth INT, org binary') +-- !query schema +struct> +-- !query output +{"name":[45 61 73 6F 6E],"birth":2018,"org":[4B 69 6E 64 65 72 67 61 72 74 65 6E 20 43 6F 70]} diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/cast.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/cast.sql.out index 7dd7180165f..2ebdcb6cbc9 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/cast.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/cast.sql.out @@ -1092,7 +1092,8 @@ org.apache.spark.SparkNumberFormatException select cast('\t\t true \n\r ' as boolean) -- !query schema struct + + AS BOOLEAN):boolean> -- !query output true @@ -1101,7 +1102,8 @@ true select cast('\t\n false \t\r' as boolean) -- !query schema struct + false + AS BOOLEAN):boolean> -- !query output false @@ -1661,6 +1663,130 @@ struct 0-11 +-- !query +SELECT CAST(TIME '00:01:52' AS tinyint) +-- !query schema +struct +-- !query output +112 + + +-- !query +SELECT CAST(TIME '00:01:52' AS smallint) +-- !query schema +struct +-- !query output +112 + + +-- !query +SELECT CAST(TIME '00:01:52' AS int) +-- !query schema +struct +-- !query output +112 + + +-- !query +SELECT CAST(TIME '00:01:52' AS bigint) +-- !query schema +struct +-- !query output +112 + + +-- !query +SELECT CAST(TIME '23:59:59' AS tinyint) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkArithmeticException +{ + "errorClass" : "CAST_OVERFLOW", + "sqlState" : "22003", + "messageParameters" : { + "ansiConfig" : "\"spark.sql.ansi.enabled\"", + "sourceType" : "\"TIME(6)\"", + "targetType" : "\"TINYINT\"", + "value" : "TIME '23:59:59'" + } +} + + +-- !query +SELECT CAST(TIME '23:59:59' AS smallint) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkArithmeticException +{ + "errorClass" : "CAST_OVERFLOW", + "sqlState" : "22003", + "messageParameters" : { + "ansiConfig" : "\"spark.sql.ansi.enabled\"", + "sourceType" : "\"TIME(6)\"", + "targetType" : "\"SMALLINT\"", + "value" : "TIME '23:59:59'" + } +} + + +-- !query +SELECT CAST(TIME '23:59:59' AS int) +-- !query schema +struct +-- !query output +86399 + + +-- !query +SELECT CAST(TIME '23:59:59' AS bigint) +-- !query schema +struct +-- !query output +86399 + + +-- !query +SELECT CAST(TIME '00:00:17.5' AS tinyint) +-- !query schema +struct +-- !query output +17 + + +-- !query +SELECT CAST(TIME '00:00:17.5' AS int) +-- !query schema +struct +-- !query output +17 + + +-- !query +SELECT CAST(TIME '00:00:17.9' AS int) +-- !query schema +struct +-- !query output +17 + + +-- !query +SELECT CAST(TIME '00:00:00' AS tinyint) +-- !query schema +struct +-- !query output +0 + + +-- !query +SELECT CAST(TIME '00:00:00' AS int) +-- !query schema +struct +-- !query output +0 + + -- !query SELECT '1.23' :: int -- !query schema @@ -1872,7 +1998,8 @@ struct select '\t\t true \n\r ' :: boolean -- !query schema struct + + AS BOOLEAN):boolean> -- !query output true @@ -1917,6 +2044,48 @@ struct 0 00:00:10.123456000 +-- !query +SELECT TIME '00:01:52' :: tinyint +-- !query schema +struct +-- !query output +112 + + +-- !query +SELECT TIME '00:01:52' :: int +-- !query schema +struct +-- !query output +112 + + +-- !query +SELECT TIME '23:59:59' :: tinyint +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkArithmeticException +{ + "errorClass" : "CAST_OVERFLOW", + "sqlState" : "22003", + "messageParameters" : { + "ansiConfig" : "\"spark.sql.ansi.enabled\"", + "sourceType" : "\"TIME(6)\"", + "targetType" : "\"TINYINT\"", + "value" : "TIME '23:59:59'" + } +} + + +-- !query +SELECT TIME '23:59:59' :: int +-- !query schema +struct +-- !query output +86399 + + -- !query SELECT '1.23' :: int :: long -- !query schema @@ -2044,3 +2213,190 @@ org.apache.spark.sql.catalyst.parser.ParseException "hint" : "" } } + + +-- !query +SELECT CAST(time '00:00:00' AS decimal(1, 0)) +-- !query schema +struct +-- !query output +0 + + +-- !query +SELECT CAST(time '12:00:00' AS decimal(7, 2)) +-- !query schema +struct +-- !query output +43200.00 + + +-- !query +SELECT CAST(time '01:30:45' AS decimal(8, 3)) +-- !query schema +struct +-- !query output +5445.000 + + +-- !query +SELECT CAST(time '23:59:59' AS decimal(9, 4)) +-- !query schema +struct +-- !query output +86399.0000 + + +-- !query +SELECT CAST(time '01:02:03' AS decimal(15, 9)) +-- !query schema +struct +-- !query output +3723.000000000 + + +-- !query +SELECT CAST(time '10:20:30' AS decimal(20, 10)) +-- !query schema +struct +-- !query output +37230.0000000000 + + +-- !query +SELECT CAST(time '23:59:59.001' AS decimal(8, 3)) +-- !query schema +struct +-- !query output +86399.001 + + +-- !query +SELECT CAST(time '23:59:59.999999' AS decimal(11, 6)) +-- !query schema +struct +-- !query output +86399.999999 + + +-- !query +SELECT CAST(time '23:59:59.999999999' AS decimal(14, 9)) +-- !query schema +struct +-- !query output +86399.999999000 + + +-- !query +SELECT CAST(time '23:59:59.999999999' AS decimal(20, 10)) +-- !query schema +struct +-- !query output +86399.9999990000 + + +-- !query +SELECT CAST(time '00:01:00' AS decimal(1, 0)) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkArithmeticException +{ + "errorClass" : "NUMERIC_VALUE_OUT_OF_RANGE.WITH_SUGGESTION", + "sqlState" : "22003", + "messageParameters" : { + "config" : "\"spark.sql.ansi.enabled\"", + "precision" : "1", + "scale" : "0", + "value" : "60.000000000" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 45, + "fragment" : "CAST(time '00:01:00' AS decimal(1, 0))" + } ] +} + + +-- !query +SELECT CAST(time '01:00:00' AS decimal(3, 0)) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkArithmeticException +{ + "errorClass" : "NUMERIC_VALUE_OUT_OF_RANGE.WITH_SUGGESTION", + "sqlState" : "22003", + "messageParameters" : { + "config" : "\"spark.sql.ansi.enabled\"", + "precision" : "3", + "scale" : "0", + "value" : "3600.000000000" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 45, + "fragment" : "CAST(time '01:00:00' AS decimal(3, 0))" + } ] +} + + +-- !query +SELECT CAST(time '10:00:00' AS decimal(5, 2)) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkArithmeticException +{ + "errorClass" : "NUMERIC_VALUE_OUT_OF_RANGE.WITH_SUGGESTION", + "sqlState" : "22003", + "messageParameters" : { + "config" : "\"spark.sql.ansi.enabled\"", + "precision" : "5", + "scale" : "2", + "value" : "36000.000000000" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 45, + "fragment" : "CAST(time '10:00:00' AS decimal(5, 2))" + } ] +} + + +-- !query +SELECT CAST(time '23:59:59.9' AS decimal(6, 0)) +-- !query schema +struct +-- !query output +86400 + + +-- !query +SELECT CAST(time '23:59:59.999' AS decimal(8, 2)) +-- !query schema +struct +-- !query output +86400.00 + + +-- !query +SELECT CAST(time '23:59:59.999999' AS decimal(11, 5)) +-- !query schema +struct +-- !query output +86400.00000 + + +-- !query +SELECT CAST(time '23:59:59.999999999' AS decimal(14, 8)) +-- !query schema +struct +-- !query output +86399.99999900 diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/collations-aliases.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/collations-aliases.sql.out new file mode 100644 index 00000000000..efc0dd9f10f --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/collations-aliases.sql.out @@ -0,0 +1,408 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +create table t1(s string, utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('Spark', 'Spark', 'SQL') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaAAaA') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaaAaA') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaaAaAaaAaaAaAaaAaaAaA') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('bbAbaAbA', 'bbAbAAbA', 'a') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('İo', 'İo', 'İo') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('İo', 'İo', 'İo ') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('İo', 'İo ', 'İo') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('İo', 'İo', 'i̇o') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('efd2', 'efd2', 'efd2') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('Hello, world! Nice day.', 'Hello, world! Nice day.', 'Hello, world! Nice day.') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('Something else. Nothing here.', 'Something else. Nothing here.', 'Something else. Nothing here.') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('kitten', 'kitten', 'sitTing') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('abc', 'abc', 'abc') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('abcdcba', 'abcdcba', 'aBcDCbA') +-- !query schema +struct<> +-- !query output + + + +-- !query +select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +SQL SQL +Something else. Nothing here. Something else. Nothing here. +a a +aBcDCbA aBcDCbA +aaAaAAaA aaAaAAaA +aaAaaAaA aaAaaAaA +aaAaaAaAaaAaaAaAaaAaaAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +efd2 efd2 +i̇o i̇o +sitTing sitTing +İo İo +İo İo +İo İo + + +-- !query +select `concat_ws(' ' collate UTF8_LCASE, utf8_lcase, utf8_lcase)` from ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 +) +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +SQL SQL +Something else. Nothing here. Something else. Nothing here. +a a +aBcDCbA aBcDCbA +aaAaAAaA aaAaAAaA +aaAaaAaA aaAaaAaA +aaAaaAaAaaAaaAaAaaAaaAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +efd2 efd2 +i̇o i̇o +sitTing sitTing +İo İo +İo İo +İo İo + + +-- !query +select * from ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 +) +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +SQL SQL +Something else. Nothing here. Something else. Nothing here. +a a +aBcDCbA aBcDCbA +aaAaAAaA aaAaAAaA +aaAaaAaA aaAaaAaA +aaAaaAaAaaAaaAaAaaAaaAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +efd2 efd2 +i̇o i̇o +sitTing sitTing +İo İo +İo İo +İo İo + + +-- !query +select subq1.* from ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 +) AS subq1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +SQL SQL +Something else. Nothing here. Something else. Nothing here. +a a +aBcDCbA aBcDCbA +aaAaAAaA aaAaAAaA +aaAaaAaA aaAaaAaA +aaAaaAaAaaAaaAaAaaAaaAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +efd2 efd2 +i̇o i̇o +sitTing sitTing +İo İo +İo İo +İo İo + + +-- !query +with cte as ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 +) +select * from cte +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +SQL SQL +Something else. Nothing here. Something else. Nothing here. +a a +aBcDCbA aBcDCbA +aaAaAAaA aaAaAAaA +aaAaaAaA aaAaaAaA +aaAaaAaAaaAaaAaAaaAaaAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +efd2 efd2 +i̇o i̇o +sitTing sitTing +İo İo +İo İo +İo İo + + +-- !query +select * from values (1) where exists ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 +) +-- !query schema +struct +-- !query output +1 + + +-- !query +select ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 limit 1 +) +-- !query schema +struct +-- !query output +Something else. Nothing here. Something else. Nothing here. + + +-- !query +select ( + with cte as ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 + ) + select * from cte limit 1 +) +-- !query schema +struct +-- !query output +Something else. Nothing here. Something else. Nothing here. + + +-- !query +select * from ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 limit 1 +) +where ( + `concat_ws(' ' collate UTF8_LCASE, utf8_lcase, utf8_lcase)` == 'aaa' +) +-- !query schema +struct +-- !query output + + + +-- !query +select lower(`concat_ws(' ' collate UTF8_LCASE, utf8_lcase, utf8_lcase)`) from ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 + group by 1 + order by 1 +) +-- !query schema +struct +-- !query output +a a +aaaaaaaa aaaaaaaa +aaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaa +abc abc +abcdcba abcdcba +efd2 efd2 +hello, world! nice day. hello, world! nice day. +i̇o i̇o +i̇o i̇o +sitting sitting +something else. nothing here. something else. nothing here. +sql sql + + +-- !query +select lower(`concat_ws(' ' collate UTF8_LCASE, utf8_lcase, utf8_lcase)`) from ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 + group by 1 + order by max(concat_ws(' ', utf8_lcase, utf8_lcase)) +) +-- !query schema +struct +-- !query output +a a +aaaaaaaa aaaaaaaa +aaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaa +abc abc +abcdcba abcdcba +efd2 efd2 +hello, world! nice day. hello, world! nice day. +i̇o i̇o +i̇o i̇o +sitting sitting +something else. nothing here. something else. nothing here. +sql sql + + +-- !query +create temporary view v1 as ( + select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 +) +-- !query schema +struct<> +-- !query output + + + +-- !query +select * from v1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +SQL SQL +Something else. Nothing here. Something else. Nothing here. +a a +aBcDCbA aBcDCbA +aaAaAAaA aaAaAAaA +aaAaaAaA aaAaaAaA +aaAaaAaAaaAaaAaAaaAaaAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +efd2 efd2 +i̇o i̇o +sitTing sitTing +İo İo +İo İo +İo İo + + +-- !query +select `concat_ws(' ' collate UTF8_LCASE, utf8_lcase, utf8_lcase)` from v1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +SQL SQL +Something else. Nothing here. Something else. Nothing here. +a a +aBcDCbA aBcDCbA +aaAaAAaA aaAaAAaA +aaAaaAaA aaAaaAaA +aaAaaAaAaaAaaAaAaaAaaAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +efd2 efd2 +i̇o i̇o +sitTing sitTing +İo İo +İo İo +İo İo + + +-- !query +drop view v1 +-- !query schema +struct<> +-- !query output + + + +-- !query +drop table t1 +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/collations-basic.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/collations-basic.sql.out new file mode 100644 index 00000000000..4be0c01df3a --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/collations-basic.sql.out @@ -0,0 +1,1770 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +create table t1(utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values('aaa', 'aaa') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values('AAA', 'AAA') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values('bbb', 'bbb') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values('BBB', 'BBB') +-- !query schema +struct<> +-- !query output + + + +-- !query +describe table t1 +-- !query schema +struct +-- !query output +utf8_binary string +utf8_lcase string collate UTF8_LCASE + + +-- !query +select count(*) from t1 group by utf8_binary +-- !query schema +struct +-- !query output +1 +1 +1 +1 + + +-- !query +select count(*) from t1 group by utf8_lcase +-- !query schema +struct +-- !query output +2 +2 + + +-- !query +select * from t1 where utf8_binary = 'aaa' +-- !query schema +struct +-- !query output +aaa aaa + + +-- !query +select * from t1 where utf8_lcase = 'aaa' collate utf8_lcase +-- !query schema +struct +-- !query output +AAA AAA +aaa aaa + + +-- !query +select * from t1 where utf8_binary < 'bbb' +-- !query schema +struct +-- !query output +AAA AAA +BBB BBB +aaa aaa + + +-- !query +select * from t1 where utf8_lcase < 'bbb' collate utf8_lcase +-- !query schema +struct +-- !query output +AAA AAA +aaa aaa + + +-- !query +select l.utf8_binary, r.utf8_lcase from t1 l join t1 r on l.utf8_lcase = r.utf8_lcase +-- !query schema +struct +-- !query output +AAA AAA +AAA aaa +BBB BBB +BBB bbb +aaa AAA +aaa aaa +bbb BBB +bbb bbb + + +-- !query +create table t2(utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t2 values('aaa', 'aaa') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t2 values('bbb', 'bbb') +-- !query schema +struct<> +-- !query output + + + +-- !query +select * from t1 anti join t2 on t1.utf8_lcase = t2.utf8_lcase +-- !query schema +struct +-- !query output + + + +-- !query +drop table t2 +-- !query schema +struct<> +-- !query output + + + +-- !query +drop table t1 +-- !query schema +struct<> +-- !query output + + + +-- !query +select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') except select col1 collate utf8_lcase from values ('aaa'), ('bbb') +-- !query schema +struct +-- !query output +zzz + + +-- !query +select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') except all select col1 collate utf8_lcase from values ('aaa'), ('bbb') +-- !query schema +struct +-- !query output +aaa +bbb +zzz +zzz + + +-- !query +select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') union select col1 collate utf8_lcase from values ('aaa'), ('bbb') +-- !query schema +struct +-- !query output +aaa +bbb +zzz + + +-- !query +select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') union all select col1 collate utf8_lcase from values ('aaa'), ('bbb') +-- !query schema +struct +-- !query output +AAA +BBB +ZZZ +aaa +aaa +bbb +bbb +zzz + + +-- !query +select col1 collate utf8_lcase from values ('aaa'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') intersect select col1 collate utf8_lcase from values ('aaa'), ('bbb') +-- !query schema +struct +-- !query output +aaa +bbb + + +-- !query +select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') except select col1 collate unicode_ci from values ('aaa'), ('bbb') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INCOMPATIBLE_COLUMN_TYPE", + "sqlState" : "42825", + "messageParameters" : { + "columnOrdinalNumber" : "first", + "dataType1" : "\"STRING COLLATE UNICODE_CI\"", + "dataType2" : "\"STRING COLLATE UTF8_LCASE\"", + "hint" : "", + "operator" : "EXCEPT", + "tableOrdinalNumber" : "second" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 162, + "fragment" : "select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') except select col1 collate unicode_ci from values ('aaa'), ('bbb')" + } ] +} + + +-- !query +select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') except all select col1 collate unicode_ci from values ('aaa'), ('bbb') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INCOMPATIBLE_COLUMN_TYPE", + "sqlState" : "42825", + "messageParameters" : { + "columnOrdinalNumber" : "first", + "dataType1" : "\"STRING COLLATE UNICODE_CI\"", + "dataType2" : "\"STRING COLLATE UTF8_LCASE\"", + "hint" : "", + "operator" : "EXCEPT ALL", + "tableOrdinalNumber" : "second" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 166, + "fragment" : "select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') except all select col1 collate unicode_ci from values ('aaa'), ('bbb')" + } ] +} + + +-- !query +select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') union select col1 collate unicode_ci from values ('aaa'), ('bbb') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INCOMPATIBLE_COLUMN_TYPE", + "sqlState" : "42825", + "messageParameters" : { + "columnOrdinalNumber" : "first", + "dataType1" : "\"STRING COLLATE UNICODE_CI\"", + "dataType2" : "\"STRING COLLATE UTF8_LCASE\"", + "hint" : "", + "operator" : "UNION", + "tableOrdinalNumber" : "second" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 161, + "fragment" : "select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') union select col1 collate unicode_ci from values ('aaa'), ('bbb')" + } ] +} + + +-- !query +select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') union all select col1 collate unicode_ci from values ('aaa'), ('bbb') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INCOMPATIBLE_COLUMN_TYPE", + "sqlState" : "42825", + "messageParameters" : { + "columnOrdinalNumber" : "first", + "dataType1" : "\"STRING COLLATE UNICODE_CI\"", + "dataType2" : "\"STRING COLLATE UTF8_LCASE\"", + "hint" : "", + "operator" : "UNION", + "tableOrdinalNumber" : "second" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 165, + "fragment" : "select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') union all select col1 collate unicode_ci from values ('aaa'), ('bbb')" + } ] +} + + +-- !query +select col1 collate utf8_lcase from values ('aaa'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') intersect select col1 collate unicode_ci from values ('aaa'), ('bbb') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INCOMPATIBLE_COLUMN_TYPE", + "sqlState" : "42825", + "messageParameters" : { + "columnOrdinalNumber" : "first", + "dataType1" : "\"STRING COLLATE UNICODE_CI\"", + "dataType2" : "\"STRING COLLATE UTF8_LCASE\"", + "hint" : "", + "operator" : "INTERSECT", + "tableOrdinalNumber" : "second" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 156, + "fragment" : "select col1 collate utf8_lcase from values ('aaa'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') intersect select col1 collate unicode_ci from values ('aaa'), ('bbb')" + } ] +} + + +-- !query +create table t1 (c1 struct) USING PARQUET +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values (named_struct('utf8_binary', 'aaa', 'utf8_lcase', 'aaa')) +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values (named_struct('utf8_binary', 'AAA', 'utf8_lcase', 'AAA')) +-- !query schema +struct<> +-- !query output + + + +-- !query +select count(*) from t1 group by c1.utf8_binary +-- !query schema +struct +-- !query output +1 +1 + + +-- !query +select count(*) from t1 group by c1.utf8_lcase +-- !query schema +struct +-- !query output +2 + + +-- !query +drop table t1 +-- !query schema +struct<> +-- !query output + + + +-- !query +select array_contains(ARRAY('aaa' collate utf8_lcase),'AAA' collate utf8_lcase) +-- !query schema +struct +-- !query output +true + + +-- !query +select array_position(ARRAY('aaa' collate utf8_lcase, 'bbb' collate utf8_lcase),'BBB' collate utf8_lcase) +-- !query schema +struct +-- !query output +2 + + +-- !query +select nullif('aaa' COLLATE utf8_lcase, 'AAA' COLLATE utf8_lcase) +-- !query schema +struct +-- !query output +NULL + + +-- !query +select least('aaa' COLLATE utf8_lcase, 'AAA' collate utf8_lcase, 'a' collate utf8_lcase) +-- !query schema +struct +-- !query output +a + + +-- !query +select arrays_overlap(array('aaa' collate utf8_lcase), array('AAA' collate utf8_lcase)) +-- !query schema +struct +-- !query output +true + + +-- !query +select array_distinct(array('aaa' collate utf8_lcase, 'AAA' collate utf8_lcase)) +-- !query schema +struct> +-- !query output +["aaa"] + + +-- !query +select array_union(array('aaa' collate utf8_lcase), array('AAA' collate utf8_lcase)) +-- !query schema +struct> +-- !query output +["aaa"] + + +-- !query +select array_intersect(array('aaa' collate utf8_lcase), array('AAA' collate utf8_lcase)) +-- !query schema +struct> +-- !query output +["aaa"] + + +-- !query +select array_except(array('aaa' collate utf8_lcase), array('AAA' collate utf8_lcase)) +-- !query schema +struct> +-- !query output +[] + + +-- !query +select 'a' collate unicode < 'A' +-- !query schema +struct<(collate(a, unicode) < 'A' collate UNICODE):boolean> +-- !query output +true + + +-- !query +select 'a' collate unicode_ci = 'A' +-- !query schema +struct<(collate(a, unicode_ci) = 'A' collate UNICODE_CI):boolean> +-- !query output +true + + +-- !query +select 'a' collate unicode_ai = 'Ã¥' +-- !query schema +struct<(collate(a, unicode_ai) = 'Ã¥' collate UNICODE_AI):boolean> +-- !query output +true + + +-- !query +select 'a' collate unicode_ci_ai = 'Ã…' +-- !query schema +struct<(collate(a, unicode_ci_ai) = 'Ã…' collate UNICODE_CI_AI):boolean> +-- !query output +true + + +-- !query +select 'a' collate en < 'A' +-- !query schema +struct<(collate(a, en) < 'A' collate en):boolean> +-- !query output +true + + +-- !query +select 'a' collate en_ci = 'A' +-- !query schema +struct<(collate(a, en_ci) = 'A' collate en_CI):boolean> +-- !query output +true + + +-- !query +select 'a' collate en_ai = 'Ã¥' +-- !query schema +struct<(collate(a, en_ai) = 'Ã¥' collate en_AI):boolean> +-- !query output +true + + +-- !query +select 'a' collate en_ci_ai = 'Ã…' +-- !query schema +struct<(collate(a, en_ci_ai) = 'Ã…' collate en_CI_AI):boolean> +-- !query output +true + + +-- !query +select 'Kypper' collate sv < 'Köpfe' +-- !query schema +struct<(collate(Kypper, sv) < 'Köpfe' collate sv):boolean> +-- !query output +true + + +-- !query +select 'Kypper' collate de > 'Köpfe' +-- !query schema +struct<(collate(Kypper, de) > 'Köpfe' collate de):boolean> +-- !query output +true + + +-- !query +select 'I' collate tr_ci = 'ı' +-- !query schema +struct<(collate(I, tr_ci) = 'ı' collate tr_CI):boolean> +-- !query output +true + + +-- !query +create table t3 (text string collate utf8_binary, pairDelim string collate utf8_lcase, keyValueDelim string collate utf8_binary) using parquet +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t3 values('a:1,b:2,c:3', ',', ':') +-- !query schema +struct<> +-- !query output + + + +-- !query +select str_to_map(text, pairDelim, keyValueDelim) from t3 +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "INDETERMINATE_COLLATION", + "sqlState" : "42P22" +} + + +-- !query +select str_to_map(text collate utf8_binary, pairDelim collate utf8_lcase, keyValueDelim collate utf8_binary) from t3 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" + } +} + + +-- !query +select str_to_map(text collate utf8_binary, pairDelim collate utf8_binary, keyValueDelim collate utf8_binary) from t3 +-- !query schema +struct> +-- !query output +{"a":"1","b":"2","c":"3"} + + +-- !query +select str_to_map(text collate unicode_ai, pairDelim collate unicode_ai, keyValueDelim collate unicode_ai) from t3 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"collate(text, unicode_ai)\"", + "inputType" : "\"STRING COLLATE UNICODE_AI\"", + "paramIndex" : "first", + "requiredType" : "\"STRING\"", + "sqlExpr" : "\"str_to_map(collate(text, unicode_ai), collate(pairDelim, unicode_ai), collate(keyValueDelim, unicode_ai))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 106, + "fragment" : "str_to_map(text collate unicode_ai, pairDelim collate unicode_ai, keyValueDelim collate unicode_ai)" + } ] +} + + +-- !query +drop table t3 +-- !query schema +struct<> +-- !query output + + + +-- !query +create table t1(s string, utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('Spark', 'Spark', 'SQL') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaAAaA') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaaAaA') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaaAaAaaAaaAaAaaAaaAaA') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('bbAbaAbA', 'bbAbAAbA', 'a') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('İo', 'İo', 'İo') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('İo', 'İo', 'İo ') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('İo', 'İo ', 'İo') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('İo', 'İo', 'i̇o') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('efd2', 'efd2', 'efd2') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('Hello, world! Nice day.', 'Hello, world! Nice day.', 'Hello, world! Nice day.') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('Something else. Nothing here.', 'Something else. Nothing here.', 'Something else. Nothing here.') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('kitten', 'kitten', 'sitTing') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('abc', 'abc', 'abc') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('abcdcba', 'abcdcba', 'aBcDCbA') +-- !query schema +struct<> +-- !query output + + + +-- !query +create table t2(ascii double) using parquet +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t2 values (97.52143) +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t2 values (66.421) +-- !query schema +struct<> +-- !query output + + + +-- !query +create table t3(utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t3 values ('aaAaAAaA', 'aaAaaAaA') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t3 values ('efd2', 'efd2') +-- !query schema +struct<> +-- !query output + + + +-- !query +create table t4(num long) using parquet +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t4 values (97) +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t4 values (66) +-- !query schema +struct<> +-- !query output + + + +-- !query +select elt(2, s, utf8_binary) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. +Something else. Nothing here. +Spark +aaAaAAaA +aaAaAAaA +aaAaAAaA +abc +abcdcba +bbAbAAbA +efd2 +kitten +İo +İo +İo +İo + + +-- !query +select elt(2, utf8_binary, utf8_lcase, s) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. +SQL +Something else. Nothing here. +a +aBcDCbA +aaAaAAaA +aaAaaAaA +aaAaaAaAaaAaaAaAaaAaaAaA +abc +efd2 +i̇o +sitTing +İo +İo +İo + + +-- !query +select elt(1, utf8_binary collate utf8_binary, utf8_lcase collate utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" + } +} + + +-- !query +select elt(1, utf8_binary collate utf8_binary, utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. +Something else. Nothing here. +Spark +aaAaAAaA +aaAaAAaA +aaAaAAaA +abc +abcdcba +bbAbAAbA +efd2 +kitten +İo +İo +İo +İo + + +-- !query +select elt(1, utf8_binary collate utf8_binary, utf8_lcase) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. +Something else. Nothing here. +Spark +aaAaAAaA +aaAaAAaA +aaAaAAaA +abc +abcdcba +bbAbAAbA +efd2 +kitten +İo +İo +İo +İo + + +-- !query +select elt(1, utf8_binary, 'word'), elt(1, utf8_lcase, 'word') from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select elt(1, utf8_binary, 'word' collate utf8_lcase), elt(1, utf8_lcase, 'word' collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select ascii(utf8_binary), ascii(utf8_lcase) from t1 +-- !query schema +struct +-- !query output +101 101 +107 115 +304 105 +304 304 +304 304 +304 304 +72 72 +83 83 +83 83 +97 97 +97 97 +97 97 +97 97 +97 97 +98 97 + + +-- !query +select ascii(utf8_binary collate utf8_lcase), ascii(utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +101 101 +107 115 +304 105 +304 304 +304 304 +304 304 +72 72 +83 83 +83 83 +97 97 +97 97 +97 97 +97 97 +97 97 +98 97 + + +-- !query +select unbase64(utf8_binary), unbase64(utf8_lcase) from t3 +-- !query schema +struct +-- !query output +i�� i�h� +y�v y�v + + +-- !query +select unbase64(utf8_binary collate utf8_lcase), unbase64(utf8_lcase collate utf8_binary) from t3 +-- !query schema +struct +-- !query output +i�� i�h� +y�v y�v + + +-- !query +select base64(utf8_binary), base64(utf8_lcase) from t1 +-- !query schema +struct +-- !query output +SGVsbG8sIHdvcmxkISBOaWNlIGRheS4= SGVsbG8sIHdvcmxkISBOaWNlIGRheS4= +U29tZXRoaW5nIGVsc2UuIE5vdGhpbmcgaGVyZS4= U29tZXRoaW5nIGVsc2UuIE5vdGhpbmcgaGVyZS4= +U3Bhcms= U1FM +YWFBYUFBYUE= YWFBYUFBYUE= +YWFBYUFBYUE= YWFBYWFBYUE= +YWFBYUFBYUE= YWFBYWFBYUFhYUFhYUFhQWFhQWFhQWFB +YWJj YWJj +YWJjZGNiYQ== YUJjRENiQQ== +YmJBYkFBYkE= YQ== +ZWZkMg== ZWZkMg== +a2l0dGVu c2l0VGluZw== +xLBv acyHbw== +xLBv xLBv +xLBv xLBvIA== +xLBvIA== xLBv + + +-- !query +select base64(utf8_binary collate utf8_lcase), base64(utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +SGVsbG8sIHdvcmxkISBOaWNlIGRheS4= SGVsbG8sIHdvcmxkISBOaWNlIGRheS4= +U29tZXRoaW5nIGVsc2UuIE5vdGhpbmcgaGVyZS4= U29tZXRoaW5nIGVsc2UuIE5vdGhpbmcgaGVyZS4= +U3Bhcms= U1FM +YWFBYUFBYUE= YWFBYUFBYUE= +YWFBYUFBYUE= YWFBYWFBYUE= +YWFBYUFBYUE= YWFBYWFBYUFhYUFhYUFhQWFhQWFhQWFB +YWJj YWJj +YWJjZGNiYQ== YUJjRENiQQ== +YmJBYkFBYkE= YQ== +ZWZkMg== ZWZkMg== +a2l0dGVu c2l0VGluZw== +xLBv acyHbw== +xLBv xLBv +xLBv xLBvIA== +xLBvIA== xLBv + + +-- !query +select decode(encode(utf8_binary, 'utf-8'), 'utf-8'), decode(encode(utf8_lcase, 'utf-8'), 'utf-8') from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select decode(encode(utf8_binary collate utf8_lcase, 'utf-8'), 'utf-8'), decode(encode(utf8_lcase collate utf8_binary, 'utf-8'), 'utf-8') from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select format_number(ascii, '###.###') from t2 +-- !query schema +struct +-- !query output +66.421 +97.521 + + +-- !query +select format_number(ascii, '###.###' collate utf8_lcase) from t2 +-- !query schema +struct +-- !query output +66.421 +97.521 + + +-- !query +select encode(utf8_binary, 'utf-8'), encode(utf8_lcase, 'utf-8') from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select encode(utf8_binary collate utf8_lcase, 'utf-8'), encode(utf8_lcase collate utf8_binary, 'utf-8') from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select to_binary(utf8_binary, 'utf-8'), to_binary(utf8_lcase, 'utf-8') from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select to_binary(utf8_binary collate utf8_lcase, 'utf-8'), to_binary(utf8_lcase collate utf8_binary, 'utf-8') from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select soundex(utf8_binary), soundex(utf8_lcase) from t1 +-- !query schema +struct +-- !query output +A000 A000 +A000 A000 +A000 A000 +A120 A120 +A123 A123 +B110 A000 +E130 E130 +H464 H464 +K350 S352 +S162 S400 +S535 S535 +İo I000 +İo İo +İo İo +İo İo + + +-- !query +select soundex(utf8_binary collate utf8_lcase), soundex(utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +A000 A000 +A000 A000 +A000 A000 +A120 A120 +A123 A123 +B110 A000 +E130 E130 +H464 H464 +K350 S352 +S162 S400 +S535 S535 +İo I000 +İo İo +İo İo +İo İo + + +-- !query +select luhn_check(num) from t4 +-- !query schema +struct +-- !query output +false +false + + +-- !query +select levenshtein(utf8_binary, utf8_lcase) from t1 +-- !query schema +struct +-- !query output +0 +0 +0 +0 +0 +0 +1 +1 +1 +16 +2 +4 +4 +4 +8 + + +-- !query +select levenshtein(s, utf8_binary) from t1 +-- !query schema +struct +-- !query output +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +1 +1 + + +-- !query +select levenshtein(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" + } +} + + +-- !query +select levenshtein(utf8_binary, utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +0 +0 +0 +0 +0 +0 +1 +1 +1 +16 +2 +4 +4 +4 +8 + + +-- !query +select levenshtein(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t1 +-- !query schema +struct +-- !query output +0 +0 +0 +0 +0 +0 +1 +1 +1 +16 +2 +4 +4 +4 +8 + + +-- !query +select levenshtein(utf8_binary, 'a'), levenshtein(utf8_lcase, 'a') from t1 +-- !query schema +struct +-- !query output +2 2 +2 2 +2 3 +2 3 +22 22 +29 29 +3 2 +4 3 +4 4 +6 6 +6 7 +7 23 +7 7 +7 7 +8 0 + + +-- !query +select levenshtein(utf8_binary, 'AaAA' collate utf8_lcase, 3), levenshtein(utf8_lcase, 'AAa' collate utf8_binary, 4) from t1 +-- !query schema +struct +-- !query output +-1 -1 +-1 -1 +-1 -1 +-1 -1 +-1 -1 +-1 -1 +-1 -1 +-1 2 +-1 3 +-1 3 +-1 3 +-1 3 +-1 3 +-1 4 +3 3 + + +-- !query +select is_valid_utf8(utf8_binary), is_valid_utf8(utf8_lcase) from t1 +-- !query schema +struct +-- !query output +true true +true true +true true +true true +true true +true true +true true +true true +true true +true true +true true +true true +true true +true true +true true + + +-- !query +select is_valid_utf8(utf8_binary collate utf8_lcase), is_valid_utf8(utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +true true +true true +true true +true true +true true +true true +true true +true true +true true +true true +true true +true true +true true +true true +true true + + +-- !query +select is_valid_utf8(utf8_binary collate utf8_lcase_rtrim), is_valid_utf8(utf8_lcase collate utf8_binary_rtrim) from t1 +-- !query schema +struct +-- !query output +true true +true true +true true +true true +true true +true true +true true +true true +true true +true true +true true +true true +true true +true true +true true + + +-- !query +select make_valid_utf8(utf8_binary), make_valid_utf8(utf8_lcase) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select make_valid_utf8(utf8_binary collate utf8_lcase), make_valid_utf8(utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select make_valid_utf8(utf8_binary collate utf8_lcase_rtrim), make_valid_utf8(utf8_lcase collate utf8_binary_rtrim) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select validate_utf8(utf8_binary), validate_utf8(utf8_lcase) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select validate_utf8(utf8_binary collate utf8_lcase), validate_utf8(utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select validate_utf8(utf8_binary collate utf8_lcase_rtrim), validate_utf8(utf8_lcase collate utf8_binary_rtrim) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select try_validate_utf8(utf8_binary), try_validate_utf8(utf8_lcase) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select try_validate_utf8(utf8_binary collate utf8_lcase), try_validate_utf8(utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select try_validate_utf8(utf8_binary collate utf8_lcase_rtrim), try_validate_utf8(utf8_lcase collate utf8_binary_rtrim) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +SELECT CASE WHEN utf8_lcase = 'XX' THEN 'XX' ELSE utf8_lcase END FROM t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. +SQL +Something else. Nothing here. +a +aBcDCbA +aaAaAAaA +aaAaaAaA +aaAaaAaAaaAaaAaAaaAaaAaA +abc +efd2 +i̇o +sitTing +İo +İo +İo + + +-- !query +drop table t1 +-- !query schema +struct<> +-- !query output + + + +-- !query +drop table t2 +-- !query schema +struct<> +-- !query output + + + +-- !query +drop table t3 +-- !query schema +struct<> +-- !query output + + + +-- !query +drop table t4 +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/collations-padding-trim.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/collations-padding-trim.sql.out new file mode 100644 index 00000000000..d18a011292c --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/collations-padding-trim.sql.out @@ -0,0 +1,1225 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +create table t1(s string, utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('Spark', 'Spark', 'SQL') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaAAaA') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaaAaA') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaaAaAaaAaaAaAaaAaaAaA') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('bbAbaAbA', 'bbAbAAbA', 'a') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('İo', 'İo', 'İo') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('İo', 'İo', 'İo ') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('İo', 'İo ', 'İo') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('İo', 'İo', 'i̇o') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('efd2', 'efd2', 'efd2') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('Hello, world! Nice day.', 'Hello, world! Nice day.', 'Hello, world! Nice day.') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('Something else. Nothing here.', 'Something else. Nothing here.', 'Something else. Nothing here.') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('kitten', 'kitten', 'sitTing') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('abc', 'abc', 'abc') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('abcdcba', 'abcdcba', 'aBcDCbA') +-- !query schema +struct<> +-- !query output + + + +-- !query +select rpad(utf8_binary, 8, utf8_lcase) from t1 +-- !query schema +struct +-- !query output +Hello, w +Somethin +SparkSQL +aaAaAAaA +aaAaAAaA +aaAaAAaA +abcabcab +abcdcbaa +bbAbAAbA +efd2efd2 +kittensi +İo İoİoİ +İoi̇oi̇o +İoİo İo +İoİoİoİo + + +-- !query +select rpad(s, 8, utf8_binary) from t1 +-- !query schema +struct +-- !query output +Hello, w +Somethin +SparkSpa +aaAaAAaA +aaAaAAaA +aaAaAAaA +abcabcab +abcdcbaa +bbAbaAbA +efd2efd2 +kittenki +İoİo İo +İoİoİoİo +İoİoİoİo +İoİoİoİo + + +-- !query +select rpad(utf8_binary collate utf8_binary, 8, s collate utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" + } +} + + +-- !query +select rpad(utf8_binary, 8, utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +Hello, w +Somethin +SparkSQL +aaAaAAaA +aaAaAAaA +aaAaAAaA +abcabcab +abcdcbaa +bbAbAAbA +efd2efd2 +kittensi +İo İoİoİ +İoi̇oi̇o +İoİo İo +İoİoİoİo + + +-- !query +select rpad(utf8_binary collate utf8_lcase, 8, utf8_lcase collate utf8_lcase) from t1 +-- !query schema +struct +-- !query output +Hello, w +Somethin +SparkSQL +aaAaAAaA +aaAaAAaA +aaAaAAaA +abcabcab +abcdcbaa +bbAbAAbA +efd2efd2 +kittensi +İo İoİoİ +İoi̇oi̇o +İoİo İo +İoİoİoİo + + +-- !query +select lpad(utf8_binary collate utf8_binary_rtrim, 8, utf8_lcase collate utf8_binary_rtrim) from t1 +-- !query schema +struct +-- !query output +Hello, w +SQLSpark +Somethin +aaAaAAaA +aaAaAAaA +aaAaAAaA +aabcdcba +abcababc +bbAbAAbA +efd2efd2 +i̇oi̇oİo +sikitten +İo İo İo +İoİoİoİo +İoİoİİo + + +-- !query +select rpad(utf8_binary, 8, 'a'), rpad(utf8_lcase, 8, 'a') from t1 +-- !query schema +struct +-- !query output +Hello, w Hello, w +Somethin Somethin +Sparkaaa SQLaaaaa +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaA +abcaaaaa abcaaaaa +abcdcbaa aBcDCbAa +bbAbAAbA aaaaaaaa +efd2aaaa efd2aaaa +kittenaa sitTinga +İo aaaaa İoaaaaaa +İoaaaaaa i̇oaaaaa +İoaaaaaa İo aaaaa +İoaaaaaa İoaaaaaa + + +-- !query +select rpad(utf8_binary, 8, 'AaAA' collate utf8_lcase), rpad(utf8_lcase, 8, 'AAa' collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +Hello, w Hello, w +Somethin Somethin +SparkAaA SQLAAaAA +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaA +abcAaAAA abcAAaAA +abcdcbaA aBcDCbAA +bbAbAAbA aAAaAAaA +efd2AaAA efd2AAaA +kittenAa sitTingA +İo AaAAA İoAAaAAa +İoAaAAAa i̇oAAaAA +İoAaAAAa İo AAaAA +İoAaAAAa İoAAaAAa + + +-- !query +select lpad(utf8_binary, 8, utf8_lcase) from t1 +-- !query schema +struct +-- !query output +Hello, w +SQLSpark +Somethin +aaAaAAaA +aaAaAAaA +aaAaAAaA +aabcdcba +abcababc +bbAbAAbA +efd2efd2 +i̇oi̇oİo +sikitten +İo İo İo +İoİoİoİo +İoİoİİo + + +-- !query +select lpad(s, 8, utf8_binary) from t1 +-- !query schema +struct +-- !query output +Hello, w +Somethin +SpaSpark +aaAaAAaA +aaAaAAaA +aaAaAAaA +aabcdcba +abcababc +bbAbaAbA +efd2efd2 +kikitten +İo İo İo +İoİoİoİo +İoİoİoİo +İoİoİoİo + + +-- !query +select lpad(utf8_binary collate utf8_binary, 8, s collate utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" + } +} + + +-- !query +select lpad(utf8_binary, 8, utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +Hello, w +SQLSpark +Somethin +aaAaAAaA +aaAaAAaA +aaAaAAaA +aabcdcba +abcababc +bbAbAAbA +efd2efd2 +i̇oi̇oİo +sikitten +İo İo İo +İoİoİoİo +İoİoİİo + + +-- !query +select lpad(utf8_binary collate utf8_lcase, 8, utf8_lcase collate utf8_lcase) from t1 +-- !query schema +struct +-- !query output +Hello, w +SQLSpark +Somethin +aaAaAAaA +aaAaAAaA +aaAaAAaA +aabcdcba +abcababc +bbAbAAbA +efd2efd2 +i̇oi̇oİo +sikitten +İo İo İo +İoİoİoİo +İoİoİİo + + +-- !query +select lpad(utf8_binary collate utf8_binary_rtrim, 8, utf8_lcase collate utf8_binary_rtrim) from t1 +-- !query schema +struct +-- !query output +Hello, w +SQLSpark +Somethin +aaAaAAaA +aaAaAAaA +aaAaAAaA +aabcdcba +abcababc +bbAbAAbA +efd2efd2 +i̇oi̇oİo +sikitten +İo İo İo +İoİoİoİo +İoİoİİo + + +-- !query +select lpad(utf8_binary, 8, 'a'), lpad(utf8_lcase, 8, 'a') from t1 +-- !query schema +struct +-- !query output +Hello, w Hello, w +Somethin Somethin +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaA +aaaSpark aaaaaSQL +aaaaaabc aaaaaabc +aaaaaaİo aaaaaaİo +aaaaaaİo aaaaai̇o +aaaaaaİo aaaaaİo +aaaaaİo aaaaaaİo +aaaaefd2 aaaaefd2 +aabcdcba aaBcDCbA +aakitten asitTing +bbAbAAbA aaaaaaaa + + +-- !query +select lpad(utf8_binary, 8, 'AaAA' collate utf8_lcase), lpad(utf8_lcase, 8, 'AAa' collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +AaAAAabc AAaAAabc +AaAAAaİo AAaAAaİo +AaAAAaİo AAaAAi̇o +AaAAAaİo AAaAAİo +AaAAAİo AAaAAaİo +AaAAefd2 AAaAefd2 +AaASpark AAaAASQL +Aabcdcba AaBcDCbA +Aakitten AsitTing +Hello, w Hello, w +Somethin Somethin +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaA +bbAbAAbA AAaAAaAa + + +-- !query +select TRIM(utf8_binary, utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", + "sqlState" : "42P22", + "messageParameters" : { + "expr" : "\"TRIM(BOTH utf8_binary FROM utf8_lcase)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 36, + "fragment" : "TRIM(utf8_binary, utf8_lcase)" + } ] +} + + +-- !query +select TRIM(s, utf8_binary) from t1 +-- !query schema +struct +-- !query output + + + +-- !query +select TRIM(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING COLLATE UTF8_LCASE\", \"STRING\"" + } +} + + +-- !query +select TRIM(utf8_binary, utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output + + + + + + + + + + +BcDCbA +QL +a +i̇ +sitTing + + +-- !query +select TRIM(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t1 +-- !query schema +struct +-- !query output + + + + + + + + + + + + + +QL +sitTing + + +-- !query +select TRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"collate(utf8_lcase, unicode_ai)\"", + "inputType" : "\"STRING COLLATE UNICODE_AI\"", + "paramIndex" : "first", + "requiredType" : "\"STRING\"", + "sqlExpr" : "\"TRIM(BOTH collate(utf8_binary, unicode_ai) FROM collate(utf8_lcase, unicode_ai))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 74, + "fragment" : "TRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai)" + } ] +} + + +-- !query +select TRIM(utf8_binary collate utf8_binary_rtrim, utf8_lcase collate utf8_binary_rtrim) from t1 +-- !query schema +struct +-- !query output + + + + + + + + + + +BcDCbA +QL +a +i̇ +sitTing + + +-- !query +select TRIM('ABc', utf8_binary), TRIM('ABc', utf8_lcase) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAa +aaAaAAa +aaAaAAa +ab +abcdcba D +bbAbAAb +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select TRIM('ABc' collate utf8_lcase, utf8_binary), TRIM('AAa' collate utf8_binary, utf8_lcase) from t1 +-- !query schema +struct +-- !query output + + + + + bc +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +d BcDCb +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select BTRIM(utf8_binary, utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", + "sqlState" : "42P22", + "messageParameters" : { + "expr" : "\"TRIM(BOTH utf8_lcase FROM utf8_binary)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 37, + "fragment" : "BTRIM(utf8_binary, utf8_lcase)" + } ] +} + + +-- !query +select BTRIM(s, utf8_binary) from t1 +-- !query schema +struct +-- !query output + + + + + + + + + + + + + + +a + + +-- !query +select BTRIM(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" + } +} + + +-- !query +select BTRIM(utf8_binary, utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output + + + + + + + + + + +bbAbAAbA +d +kitte +park +İ + + +-- !query +select BTRIM(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t1 +-- !query schema +struct +-- !query output + + + + + + + + + + + +bbAbAAb +kitte +park +İ + + +-- !query +select BTRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"collate(utf8_binary, unicode_ai)\"", + "inputType" : "\"STRING COLLATE UNICODE_AI\"", + "paramIndex" : "first", + "requiredType" : "\"STRING\"", + "sqlExpr" : "\"TRIM(BOTH collate(utf8_lcase, unicode_ai) FROM collate(utf8_binary, unicode_ai))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 75, + "fragment" : "BTRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai)" + } ] +} + + +-- !query +select BTRIM(utf8_binary collate utf8_binary_rtrim, utf8_lcase collate utf8_binary_rtrim) from t1 +-- !query schema +struct +-- !query output + + + + + + + + + + +bbAbAAbA +d +kitte +park +İ + + +-- !query +select BTRIM('ABc', utf8_binary), BTRIM('ABc', utf8_lcase) from t1 +-- !query schema +struct +-- !query output +AB +AB +AB B +ABc ABc +ABc ABc +ABc ABc +ABc ABc +ABc ABc +ABc ABc +ABc ABc +ABc ABc +Bc Bc +Bc Bc +Bc Bc +Bc Bc + + +-- !query +select BTRIM('ABc' collate utf8_lcase, utf8_binary), BTRIM('AAa' collate utf8_binary, utf8_lcase) from t1 +-- !query schema +struct +-- !query output + + AA +ABc AAa +ABc AAa +ABc AAa +ABc AAa +ABc AAa +ABc AAa +ABc AAa +B AA +Bc +Bc +Bc +Bc AAa +c AA + + +-- !query +select LTRIM(utf8_binary, utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", + "sqlState" : "42P22", + "messageParameters" : { + "expr" : "\"TRIM(LEADING utf8_binary FROM utf8_lcase)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 37, + "fragment" : "LTRIM(utf8_binary, utf8_lcase)" + } ] +} + + +-- !query +select LTRIM(s, utf8_binary) from t1 +-- !query schema +struct +-- !query output + + + +-- !query +select LTRIM(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING COLLATE UTF8_LCASE\", \"STRING\"" + } +} + + +-- !query +select LTRIM(utf8_binary, utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output + + + + + + + + + + +BcDCbA +QL +a +i̇o +sitTing + + +-- !query +select LTRIM(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t1 +-- !query schema +struct +-- !query output + + + + + + + + + + + + + +QL +sitTing + + +-- !query +select LTRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"collate(utf8_lcase, unicode_ai)\"", + "inputType" : "\"STRING COLLATE UNICODE_AI\"", + "paramIndex" : "first", + "requiredType" : "\"STRING\"", + "sqlExpr" : "\"TRIM(LEADING collate(utf8_binary, unicode_ai) FROM collate(utf8_lcase, unicode_ai))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 75, + "fragment" : "LTRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai)" + } ] +} + + +-- !query +select LTRIM(utf8_binary collate utf8_binary_rtrim, utf8_lcase collate utf8_binary_rtrim) from t1 +-- !query schema +struct +-- !query output + + + + + + + + + + +BcDCbA +QL +a +i̇o +sitTing + + +-- !query +select LTRIM('ABc', utf8_binary), LTRIM('ABc', utf8_lcase) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA +aaAaAAaA +aaAaAAaA +abc +abcdcba DCbA +bbAbAAbA +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select LTRIM('ABc' collate utf8_lcase, utf8_binary), LTRIM('AAa' collate utf8_binary, utf8_lcase) from t1 +-- !query schema +struct +-- !query output + + + + + bc +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +dcba BcDCbA +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select RTRIM(utf8_binary, utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", + "sqlState" : "42P22", + "messageParameters" : { + "expr" : "\"TRIM(TRAILING utf8_binary FROM utf8_lcase)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 37, + "fragment" : "RTRIM(utf8_binary, utf8_lcase)" + } ] +} + + +-- !query +select RTRIM(s, utf8_binary) from t1 +-- !query schema +struct +-- !query output + + + + + + + + + + + + + + +İo + + +-- !query +select RTRIM(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING COLLATE UTF8_LCASE\", \"STRING\"" + } +} + + +-- !query +select RTRIM(utf8_binary, utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output + + + + + + + + + +SQL +a +aBcDCbA +i̇ +sitTing +İo + + +-- !query +select RTRIM(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t1 +-- !query schema +struct +-- !query output + + + + + + + + + + + + +SQL +sitTing +İo + + +-- !query +select RTRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"collate(utf8_lcase, unicode_ai)\"", + "inputType" : "\"STRING COLLATE UNICODE_AI\"", + "paramIndex" : "first", + "requiredType" : "\"STRING\"", + "sqlExpr" : "\"TRIM(TRAILING collate(utf8_binary, unicode_ai) FROM collate(utf8_lcase, unicode_ai))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 75, + "fragment" : "RTRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai)" + } ] +} + + +-- !query +select RTRIM(utf8_binary collate utf8_binary_rtrim, utf8_lcase collate utf8_binary_rtrim) from t1 +-- !query schema +struct +-- !query output + + + + + + + + + + +SQL +a +aBcDCbA +i̇ +sitTing + + +-- !query +select RTRIM('ABc', utf8_binary), RTRIM('ABc', utf8_lcase) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAa +aaAaAAa +aaAaAAa +ab +abcdcba aBcD +bbAbAAb +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select RTRIM('ABc' collate utf8_lcase, utf8_binary), RTRIM('AAa' collate utf8_binary, utf8_lcase) from t1 +-- !query schema +struct +-- !query output + + + + + abc +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +abcd aBcDCb +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +drop table t1 +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/collations-string-functions.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/collations-string-functions.sql.out new file mode 100644 index 00000000000..ed4f6b500ae --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/collations-string-functions.sql.out @@ -0,0 +1,2858 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +create table t1(s string, utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('Spark', 'Spark', 'SQL') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaAAaA') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaaAaA') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaaAaAaaAaaAaAaaAaaAaA') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('bbAbaAbA', 'bbAbAAbA', 'a') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('İo', 'İo', 'İo') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('İo', 'İo', 'İo ') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('İo', 'İo ', 'İo') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('İo', 'İo', 'i̇o') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('efd2', 'efd2', 'efd2') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('Hello, world! Nice day.', 'Hello, world! Nice day.', 'Hello, world! Nice day.') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('Something else. Nothing here.', 'Something else. Nothing here.', 'Something else. Nothing here.') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('kitten', 'kitten', 'sitTing') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('abc', 'abc', 'abc') +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t1 values ('abcdcba', 'abcdcba', 'aBcDCbA') +-- !query schema +struct<> +-- !query output + + + +-- !query +create table t2(ascii long) using parquet +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t2 values (97) +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t2 values (66) +-- !query schema +struct<> +-- !query output + + + +-- !query +create table t3(format string collate utf8_binary, utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into t3 values ('%s%s', 'abCdE', 'abCdE') +-- !query schema +struct<> +-- !query output + + + +-- !query +select concat_ws(' ', utf8_lcase, utf8_lcase) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +SQL SQL +Something else. Nothing here. Something else. Nothing here. +a a +aBcDCbA aBcDCbA +aaAaAAaA aaAaAAaA +aaAaaAaA aaAaaAaA +aaAaaAaAaaAaaAaAaaAaaAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +efd2 efd2 +i̇o i̇o +sitTing sitTing +İo İo +İo İo +İo İo + + +-- !query +select concat_ws(' ', utf8_binary, utf8_lcase) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo İo +İo i̇o +İo İo +İo İo + + +-- !query +select concat_ws(' ' collate utf8_binary, utf8_binary, 'SQL' collate utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" + } +} + + +-- !query +select concat_ws(' ' collate utf8_lcase, utf8_binary, 'SQL' collate utf8_lcase) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. SQL +Something else. Nothing here. SQL +Spark SQL +aaAaAAaA SQL +aaAaAAaA SQL +aaAaAAaA SQL +abc SQL +abcdcba SQL +bbAbAAbA SQL +efd2 SQL +kitten SQL +İo SQL +İo SQL +İo SQL +İo SQL + + +-- !query +select concat_ws(',', utf8_lcase, 'word'), concat_ws(',', utf8_binary, 'word') from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day.,word Hello, world! Nice day.,word +SQL,word Spark,word +Something else. Nothing here.,word Something else. Nothing here.,word +a,word bbAbAAbA,word +aBcDCbA,word abcdcba,word +aaAaAAaA,word aaAaAAaA,word +aaAaaAaA,word aaAaAAaA,word +aaAaaAaAaaAaaAaAaaAaaAaA,word aaAaAAaA,word +abc,word abc,word +efd2,word efd2,word +i̇o,word İo,word +sitTing,word kitten,word +İo ,word İo,word +İo,word İo ,word +İo,word İo,word + + +-- !query +select concat_ws(',', utf8_lcase, 'word' collate utf8_binary), concat_ws(',', utf8_binary, 'word' collate utf8_lcase) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day.,word Hello, world! Nice day.,word +SQL,word Spark,word +Something else. Nothing here.,word Something else. Nothing here.,word +a,word bbAbAAbA,word +aBcDCbA,word abcdcba,word +aaAaAAaA,word aaAaAAaA,word +aaAaaAaA,word aaAaAAaA,word +aaAaaAaAaaAaaAaAaaAaaAaA,word aaAaAAaA,word +abc,word abc,word +efd2,word efd2,word +i̇o,word İo,word +sitTing,word kitten,word +İo ,word İo,word +İo,word İo ,word +İo,word İo,word + + +-- !query +select split_part(utf8_binary, utf8_lcase, 3) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "INDETERMINATE_COLLATION", + "sqlState" : "42P22" +} + + +-- !query +select split_part(s, utf8_binary, 1) from t1 +-- !query schema +struct +-- !query output + + + + + + + + + + + + + +bbAbaAbA +İo + + +-- !query +select split_part(utf8_binary collate utf8_binary, s collate utf8_lcase, 1) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" + } +} + + +-- !query +select split_part(utf8_binary, utf8_lcase collate utf8_binary, 2) from t1 +-- !query schema +struct +-- !query output + + + +-- !query +select split_part(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase, 2) from t1 +-- !query schema +struct +-- !query output + + + + + + + + + + + + + + +b + + +-- !query +select split_part(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 2) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"collate(utf8_binary, unicode_ai)\"", + "inputType" : "\"STRING COLLATE UNICODE_AI\"", + "paramIndex" : "first", + "requiredType" : "\"STRING\"", + "sqlExpr" : "\"split_part(collate(utf8_binary, unicode_ai), collate(utf8_lcase, unicode_ai), 2)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 83, + "fragment" : "split_part(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 2)" + } ] +} + + +-- !query +select split_part(utf8_binary, 'a', 3), split_part(utf8_lcase, 'a', 3) from t1 +-- !query schema +struct +-- !query output + + + + + + + + + + + + +A +A +A + + +-- !query +select split_part(utf8_binary, 'a' collate utf8_lcase, 3), split_part(utf8_lcase, 'a' collate utf8_binary, 3) from t1 +-- !query schema +struct +-- !query output + + + + + + + + + + + + + A + A + A + + +-- !query +select split_part(utf8_binary, 'a ' collate utf8_lcase_rtrim, 3), split_part(utf8_lcase, 'a' collate utf8_binary, 3) from t1 +-- !query schema +struct +-- !query output + + + + + + + + + + + + + A + A + A + + +-- !query +select contains(utf8_binary, utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", + "sqlState" : "42P22", + "messageParameters" : { + "expr" : "\"contains(utf8_binary, utf8_lcase)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 40, + "fragment" : "contains(utf8_binary, utf8_lcase)" + } ] +} + + +-- !query +select contains(s, utf8_binary) from t1 +-- !query schema +struct +-- !query output +false +false +true +true +true +true +true +true +true +true +true +true +true +true +true + + +-- !query +select contains(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" + } +} + + +-- !query +select contains(utf8_binary, utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +false +false +false +false +false +false +false +false +true +true +true +true +true +true +true + + +-- !query +select contains(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t1 +-- !query schema +struct +-- !query output +false +false +false +false +true +true +true +true +true +true +true +true +true +true +true + + +-- !query +select contains(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"collate(utf8_binary, unicode_ai)\"", + "inputType" : "\"STRING COLLATE UNICODE_AI\"", + "paramIndex" : "first", + "requiredType" : "\"STRING\"", + "sqlExpr" : "\"contains(collate(utf8_binary, unicode_ai), collate(utf8_lcase, unicode_ai))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 78, + "fragment" : "contains(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai)" + } ] +} + + +-- !query +select contains(utf8_binary, 'a'), contains(utf8_lcase, 'a') from t1 +-- !query schema +struct +-- !query output +false false +false false +false false +false false +false false +false false +false false +false true +true false +true true +true true +true true +true true +true true +true true + + +-- !query +select contains(utf8_binary, 'AaAA' collate utf8_lcase), contains(utf8_lcase, 'AAa' collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +true false +true false +true true + + +-- !query +select contains(utf8_binary, 'AaAA ' collate utf8_lcase_rtrim), contains(utf8_lcase, 'AAa ' collate utf8_binary_rtrim) from t1 +-- !query schema +struct +-- !query output +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +true false +true false +true true + + +-- !query +select substring_index(utf8_binary, utf8_lcase, 2) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", + "sqlState" : "42P22", + "messageParameters" : { + "expr" : "\"substring_index(utf8_binary, utf8_lcase, 2)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 50, + "fragment" : "substring_index(utf8_binary, utf8_lcase, 2)" + } ] +} + + +-- !query +select substring_index(s, utf8_binary,1) from t1 +-- !query schema +struct +-- !query output + + + + + + + + + + + + + +bbAbaAbA +İo + + +-- !query +select substring_index(utf8_binary collate utf8_binary, s collate utf8_lcase, 3) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" + } +} + + +-- !query +select substring_index(utf8_binary, utf8_lcase collate utf8_binary, 2) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. +Something else. Nothing here. +Spark +aaAaAAaA +aaAaAAaA +aaAaAAaA +abc +abcdcba +bbAbAAbA +efd2 +kitten +İo +İo +İo +İo + + +-- !query +select substring_index(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase, 2) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. +Something else. Nothing here. +Spark +aaAaAAaA +aaAaAAaA +aaAaAAaA +abc +abcdcba +bbAb +efd2 +kitten +İo +İo +İo +İo + + +-- !query +select substring_index(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 2) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"collate(utf8_binary, unicode_ai)\"", + "inputType" : "\"STRING COLLATE UNICODE_AI\"", + "paramIndex" : "first", + "requiredType" : "\"STRING\"", + "sqlExpr" : "\"substring_index(collate(utf8_binary, unicode_ai), collate(utf8_lcase, unicode_ai), 2)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 88, + "fragment" : "substring_index(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 2)" + } ] +} + + +-- !query +select substring_index(utf8_binary, 'a', 2), substring_index(utf8_lcase, 'a', 2) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +a a +a a +a a +abc abc +abcdcb aBcDCb +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select substring_index(utf8_binary, 'AaAA' collate utf8_lcase, 2), substring_index(utf8_lcase, 'AAa' collate utf8_binary, 2) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +a aaAaAAaA +a aaAaaAaA +a aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select substring_index(utf8_binary, 'AaAA ' collate utf8_lcase_rtrim, 2), substring_index(utf8_lcase, 'AAa' collate utf8_binary, 2) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +a aaAaAAaA +a aaAaaAaA +a aaAaaAaAaaAaaAaAaaAaaAaA +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select instr(utf8_binary, utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", + "sqlState" : "42P22", + "messageParameters" : { + "expr" : "\"instr(utf8_binary, utf8_lcase)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 37, + "fragment" : "instr(utf8_binary, utf8_lcase)" + } ] +} + + +-- !query +select instr(s, utf8_binary) from t1 +-- !query schema +struct +-- !query output +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + + +-- !query +select instr(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" + } +} + + +-- !query +select instr(utf8_binary, utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +0 +0 +0 +0 +0 +0 +0 +0 +1 +1 +1 +1 +1 +1 +1 + + +-- !query +select instr(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t1 +-- !query schema +struct +-- !query output +0 +0 +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +3 + + +-- !query +select instr(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"collate(utf8_binary, unicode_ai)\"", + "inputType" : "\"STRING COLLATE UNICODE_AI\"", + "paramIndex" : "first", + "requiredType" : "\"STRING\"", + "sqlExpr" : "\"instr(collate(utf8_binary, unicode_ai), collate(utf8_lcase, unicode_ai))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 75, + "fragment" : "instr(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai)" + } ] +} + + +-- !query +select instr(utf8_binary, 'a'), instr(utf8_lcase, 'a') from t1 +-- !query schema +struct +-- !query output +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 1 +1 1 +1 1 +1 1 +1 1 +1 1 +21 21 +3 0 + + +-- !query +select instr(utf8_binary, 'AaAA' collate utf8_lcase), instr(utf8_lcase, 'AAa' collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +1 0 +1 0 +1 5 + + +-- !query +select find_in_set(utf8_binary, utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", + "sqlState" : "42P22", + "messageParameters" : { + "expr" : "\"find_in_set(utf8_binary, utf8_lcase)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 43, + "fragment" : "find_in_set(utf8_binary, utf8_lcase)" + } ] +} + + +-- !query +select find_in_set(s, utf8_binary) from t1 +-- !query schema +struct +-- !query output +0 +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + + +-- !query +select find_in_set(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" + } +} + + +-- !query +select find_in_set(utf8_binary, utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +1 +1 +1 +1 +1 + + +-- !query +select find_in_set(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t1 +-- !query schema +struct +-- !query output +0 +0 +0 +0 +0 +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 + + +-- !query +select find_in_set(utf8_binary, 'aaAaaAaA,i̇o'), find_in_set(utf8_lcase, 'aaAaaAaA,i̇o') from t1 +-- !query schema +struct +-- !query output +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 1 +0 1 +0 2 +0 2 +0 2 + + +-- !query +select find_in_set(utf8_binary, 'aaAaaAaA,i̇o' collate utf8_lcase), find_in_set(utf8_lcase, 'aaAaaAaA,i̇o' collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +1 0 +1 0 +1 1 +2 0 +2 0 +2 2 + + +-- !query +select find_in_set(utf8_binary, 'aaAaaAaA,i̇o ' collate utf8_lcase_rtrim), find_in_set(utf8_lcase, 'aaAaaAaA,i̇o' collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +1 0 +1 0 +1 1 +2 0 +2 0 +2 0 +2 2 + + +-- !query +select startswith(utf8_binary, utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", + "sqlState" : "42P22", + "messageParameters" : { + "expr" : "\"startswith(utf8_binary, utf8_lcase)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 42, + "fragment" : "startswith(utf8_binary, utf8_lcase)" + } ] +} + + +-- !query +select startswith(s, utf8_binary) from t1 +-- !query schema +struct +-- !query output +false +false +true +true +true +true +true +true +true +true +true +true +true +true +true + + +-- !query +select startswith(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" + } +} + + +-- !query +select startswith(utf8_binary, utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +false +false +false +false +false +false +false +false +true +true +true +true +true +true +true + + +-- !query +select startswith(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t1 +-- !query schema +struct +-- !query output +false +false +false +false +false +true +true +true +true +true +true +true +true +true +true + + +-- !query +select startswith(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"collate(utf8_binary, unicode_ai)\"", + "inputType" : "\"STRING COLLATE UNICODE_AI\"", + "paramIndex" : "first", + "requiredType" : "\"STRING\"", + "sqlExpr" : "\"startswith(collate(utf8_binary, unicode_ai), collate(utf8_lcase, unicode_ai))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 80, + "fragment" : "startswith(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai)" + } ] +} + + +-- !query +select startswith(utf8_binary, 'aaAaaAaA'), startswith(utf8_lcase, 'aaAaaAaA') from t1 +-- !query schema +struct +-- !query output +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +false true +false true +false true + + +-- !query +select startswith(utf8_binary, 'aaAaaAaA' collate utf8_lcase), startswith(utf8_lcase, 'aaAaaAaA' collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +true false +true true +true true + + +-- !query +select startswith(utf8_binary, 'aaAaaAaA ' collate utf8_lcase_rtrim), startswith(utf8_lcase, 'aaAaaAaA' collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +true false +true true +true true + + +-- !query +select translate(utf8_lcase, utf8_lcase, '12345') from t1 +-- !query schema +struct +-- !query output +1 +11111111 +11111111 +111111111111111111111111 +12 +12 +123 +123 +123 +123 +12332 +12335532 +1234 +1234321 +123454142544 + + +-- !query +select translate(utf8_binary, utf8_lcase, '12345') from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", + "sqlState" : "42P22", + "messageParameters" : { + "expr" : "\"translate(utf8_binary, utf8_lcase, 12345)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 50, + "fragment" : "translate(utf8_binary, utf8_lcase, '12345')" + } ] +} + + +-- !query +select translate(utf8_binary, 'aBc' collate utf8_lcase, '12345' collate utf8_binary) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING COLLATE UTF8_LCASE\", \"STRING\"" + } +} + + +-- !query +select translate(utf8_binary, 'SQL' collate utf8_lcase, '12345' collate utf8_lcase) from t1 +-- !query schema +struct +-- !query output +1omething e31e. Nothing here. +1park +He33o, wor3d! Nice day. +aaAaAAaA +aaAaAAaA +aaAaAAaA +abc +abcdcba +bbAbAAbA +efd2 +kitten +İo +İo +İo +İo + + +-- !query +select translate(utf8_binary, 'SQL' collate unicode_ai, '12345' collate unicode_ai) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"utf8_binary\"", + "inputType" : "\"STRING COLLATE UNICODE_AI\"", + "paramIndex" : "first", + "requiredType" : "\"STRING\"", + "sqlExpr" : "\"translate(utf8_binary, collate(SQL, unicode_ai), collate(12345, unicode_ai))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 83, + "fragment" : "translate(utf8_binary, 'SQL' collate unicode_ai, '12345' collate unicode_ai)" + } ] +} + + +-- !query +select translate(utf8_lcase, 'aaAaaAaA', '12345'), translate(utf8_binary, 'aaAaaAaA', '12345') from t1 +-- !query schema +struct +-- !query output +1 bb3b33b3 +11111111 11313313 +11111111 11313313 +111111111111111111111111 11313313 +1BcDCb1 1bcdcb1 +1bc 1bc +Hello, world! Nice d1y. Hello, world! Nice d1y. +SQL Sp1rk +Something else. Nothing here. Something else. Nothing here. +efd2 efd2 +i̇o İo +sitTing kitten +İo İo +İo İo +İo İo + + +-- !query +select translate(utf8_lcase, 'aBc' collate utf8_binary, '12345'), translate(utf8_binary, 'aBc' collate utf8_lcase, '12345') from t1 +-- !query schema +struct +-- !query output +1 22121121 +11A11A1A 11111111 +11A11A1A11A11A1A11A11A1A 11111111 +11A1AA1A 11111111 +123DCbA 123d321 +1b3 123 +Hello, world! Ni3e d1y. Hello, world! Ni3e d1y. +SQL Sp1rk +Something else. Nothing here. Something else. Nothing here. +efd2 efd2 +i̇o İo +sitTing kitten +İo İo +İo İo +İo İo + + +-- !query +select translate(utf8_lcase, 'aBc ' collate utf8_binary_rtrim, '12345'), translate(utf8_binary, 'aBc' collate utf8_lcase, '12345') from t1 +-- !query schema +struct +-- !query output +1 22121121 +11A11A1A 11111111 +11A11A1A11A11A1A11A11A1A 11111111 +11A1AA1A 11111111 +123DCbA 123d321 +1b3 123 +Hello,4world!4Ni3e4d1y. Hello, world! Ni3e d1y. +SQL Sp1rk +Something4else.4Nothing4here. Something else. Nothing here. +efd2 efd2 +i̇o İo +sitTing kitten +İo İo +İo İo +İo4 İo + + +-- !query +select replace(utf8_binary, utf8_lcase, 'abc') from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", + "sqlState" : "42P22", + "messageParameters" : { + "expr" : "\"replace(utf8_binary, utf8_lcase, abc)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 46, + "fragment" : "replace(utf8_binary, utf8_lcase, 'abc')" + } ] +} + + +-- !query +select replace(s, utf8_binary, 'abc') from t1 +-- !query schema +struct +-- !query output +abc +abc +abc +abc +abc +abc +abc +abc +abc +abc +abc +abc +abc +bbAbaAbA +İo + + +-- !query +select replace(utf8_binary collate utf8_binary, s collate utf8_lcase, 'abc') from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" + } +} + + +-- !query +select replace(utf8_binary, utf8_lcase collate utf8_binary, 'abc') from t1 +-- !query schema +struct +-- !query output +Spark +aaAaAAaA +aaAaAAaA +abc +abc +abc +abc +abc +abc +abc +abcdcba +bbAbAAbA +kitten +İo +İo + + +-- !query +select replace(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase, 'abc') from t1 +-- !query schema +struct +-- !query output +Spark +aaAaAAaA +abc +abc +abc +abc +abc +abc +abc +abc +abc +abc +bbabcbabcabcbabc +kitten +İo + + +-- !query +select replace(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 'abc') from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"collate(utf8_binary, unicode_ai)\"", + "inputType" : "\"STRING COLLATE UNICODE_AI\"", + "paramIndex" : "first", + "requiredType" : "\"STRING\"", + "sqlExpr" : "\"replace(collate(utf8_binary, unicode_ai), collate(utf8_lcase, unicode_ai), 'abc' collate UNICODE_AI)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 84, + "fragment" : "replace(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 'abc')" + } ] +} + + +-- !query +select replace(utf8_binary, 'aaAaaAaA', 'abc'), replace(utf8_lcase, 'aaAaaAaA', 'abc') from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA abc +aaAaAAaA abc +aaAaAAaA abcabcabc +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select replace(utf8_binary, 'aaAaaAaA' collate utf8_lcase, 'abc'), replace(utf8_lcase, 'aaAaaAaA' collate utf8_binary, 'abc') from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +abc aaAaAAaA +abc abc +abc abc +abc abcabcabc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select replace(utf8_binary, 'aaAaaAaA ' collate utf8_lcase_rtrim, 'abc'), replace(utf8_lcase, 'aaAaaAaA' collate utf8_binary, 'abc') from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. Hello, world! Nice day. +Something else. Nothing here. Something else. Nothing here. +Spark SQL +aaAaAAaA aaAaAAaA +aaAaAAaA abc +aaAaAAaA abcabcabc +abc abc +abcdcba aBcDCbA +bbAbAAbA a +efd2 efd2 +kitten sitTing +İo i̇o +İo İo +İo İo +İo İo + + +-- !query +select endswith(utf8_binary, utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", + "sqlState" : "42P22", + "messageParameters" : { + "expr" : "\"endswith(utf8_binary, utf8_lcase)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 40, + "fragment" : "endswith(utf8_binary, utf8_lcase)" + } ] +} + + +-- !query +select endswith(s, utf8_binary) from t1 +-- !query schema +struct +-- !query output +false +false +true +true +true +true +true +true +true +true +true +true +true +true +true + + +-- !query +select endswith(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" + } +} + + +-- !query +select endswith(utf8_binary, utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +false +false +false +false +false +false +false +false +false +true +true +true +true +true +true + + +-- !query +select endswith(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t1 +-- !query schema +struct +-- !query output +false +false +false +false +false +true +true +true +true +true +true +true +true +true +true + + +-- !query +select endswith(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"collate(utf8_binary, unicode_ai)\"", + "inputType" : "\"STRING COLLATE UNICODE_AI\"", + "paramIndex" : "first", + "requiredType" : "\"STRING\"", + "sqlExpr" : "\"endswith(collate(utf8_binary, unicode_ai), collate(utf8_lcase, unicode_ai))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 78, + "fragment" : "endswith(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai)" + } ] +} + + +-- !query +select endswith(utf8_binary, 'aaAaaAaA'), endswith(utf8_lcase, 'aaAaaAaA') from t1 +-- !query schema +struct +-- !query output +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +false true +false true +false true + + +-- !query +select endswith(utf8_binary, 'aaAaaAaA' collate utf8_lcase), endswith(utf8_lcase, 'aaAaaAaA' collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +true false +true true +true true + + +-- !query +select endswith(utf8_binary, 'aaAaaAaA ' collate utf8_lcase_rtrim), endswith(utf8_lcase, 'aaAaaAaA' collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +false false +true false +true true +true true + + +-- !query +select repeat(utf8_binary, 3), repeat(utf8_lcase, 2) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day.Hello, world! Nice day.Hello, world! Nice day. Hello, world! Nice day.Hello, world! Nice day. +Something else. Nothing here.Something else. Nothing here.Something else. Nothing here. Something else. Nothing here.Something else. Nothing here. +SparkSparkSpark SQLSQL +aaAaAAaAaaAaAAaAaaAaAAaA aaAaAAaAaaAaAAaA +aaAaAAaAaaAaAAaAaaAaAAaA aaAaaAaAaaAaaAaA +aaAaAAaAaaAaAAaAaaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaAaaAaaAaAaaAaaAaAaaAaaAaA +abcabcabc abcabc +abcdcbaabcdcbaabcdcba aBcDCbAaBcDCbA +bbAbAAbAbbAbAAbAbbAbAAbA aa +efd2efd2efd2 efd2efd2 +kittenkittenkitten sitTingsitTing +İo İo İo İoİo +İoİoİo i̇oi̇o +İoİoİo İo İo +İoİoİo İoİo + + +-- !query +select repeat(utf8_binary collate utf8_lcase, 3), repeat(utf8_lcase collate utf8_binary, 2) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day.Hello, world! Nice day.Hello, world! Nice day. Hello, world! Nice day.Hello, world! Nice day. +Something else. Nothing here.Something else. Nothing here.Something else. Nothing here. Something else. Nothing here.Something else. Nothing here. +SparkSparkSpark SQLSQL +aaAaAAaAaaAaAAaAaaAaAAaA aaAaAAaAaaAaAAaA +aaAaAAaAaaAaAAaAaaAaAAaA aaAaaAaAaaAaaAaA +aaAaAAaAaaAaAAaAaaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaAaaAaaAaAaaAaaAaAaaAaaAaA +abcabcabc abcabc +abcdcbaabcdcbaabcdcba aBcDCbAaBcDCbA +bbAbAAbAbbAbAAbAbbAbAAbA aa +efd2efd2efd2 efd2efd2 +kittenkittenkitten sitTingsitTing +İo İo İo İoİo +İoİoİo i̇oi̇o +İoİoİo İo İo +İoİoİo İoİo + + +-- !query +select chr(ascii) from t2 +-- !query schema +struct +-- !query output +B +a + + +-- !query +select sentences(utf8_binary), sentences(utf8_lcase) from t1 +-- !query schema +struct>,sentences(utf8_lcase, , ):array>> +-- !query output +[["Hello","world"],["Nice","day"]] [["Hello","world"],["Nice","day"]] +[["Something","else"],["Nothing","here"]] [["Something","else"],["Nothing","here"]] +[["Spark"]] [["SQL"]] +[["aaAaAAaA"]] [["aaAaAAaA"]] +[["aaAaAAaA"]] [["aaAaaAaA"]] +[["aaAaAAaA"]] [["aaAaaAaAaaAaaAaAaaAaaAaA"]] +[["abc"]] [["abc"]] +[["abcdcba"]] [["aBcDCbA"]] +[["bbAbAAbA"]] [["a"]] +[["efd2"]] [["efd2"]] +[["kitten"]] [["sitTing"]] +[["İo"]] [["i̇o"]] +[["İo"]] [["İo"]] +[["İo"]] [["İo"]] +[["İo"]] [["İo"]] + + +-- !query +select sentences(utf8_binary collate utf8_lcase), sentences(utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct>,sentences(collate(utf8_lcase, utf8_binary), , ):array>> +-- !query output +[["Hello","world"],["Nice","day"]] [["Hello","world"],["Nice","day"]] +[["Something","else"],["Nothing","here"]] [["Something","else"],["Nothing","here"]] +[["Spark"]] [["SQL"]] +[["aaAaAAaA"]] [["aaAaAAaA"]] +[["aaAaAAaA"]] [["aaAaaAaA"]] +[["aaAaAAaA"]] [["aaAaaAaAaaAaaAaAaaAaaAaA"]] +[["abc"]] [["abc"]] +[["abcdcba"]] [["aBcDCbA"]] +[["bbAbAAbA"]] [["a"]] +[["efd2"]] [["efd2"]] +[["kitten"]] [["sitTing"]] +[["İo"]] [["i̇o"]] +[["İo"]] [["İo"]] +[["İo"]] [["İo"]] +[["İo"]] [["İo"]] + + +-- !query +select upper(utf8_binary), upper(utf8_lcase) from t1 +-- !query schema +struct +-- !query output +AAAAAAAA AAAAAAAA +AAAAAAAA AAAAAAAA +AAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAA +ABC ABC +ABCDCBA ABCDCBA +BBABAABA A +EFD2 EFD2 +HELLO, WORLD! NICE DAY. HELLO, WORLD! NICE DAY. +KITTEN SITTING +SOMETHING ELSE. NOTHING HERE. SOMETHING ELSE. NOTHING HERE. +SPARK SQL +İO İO +İO İO +İO İO +İO İO + + +-- !query +select upper(utf8_binary collate utf8_lcase), upper(utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +AAAAAAAA AAAAAAAA +AAAAAAAA AAAAAAAA +AAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAA +ABC ABC +ABCDCBA ABCDCBA +BBABAABA A +EFD2 EFD2 +HELLO, WORLD! NICE DAY. HELLO, WORLD! NICE DAY. +KITTEN SITTING +SOMETHING ELSE. NOTHING HERE. SOMETHING ELSE. NOTHING HERE. +SPARK SQL +İO İO +İO İO +İO İO +İO İO + + +-- !query +select lower(utf8_binary), lower(utf8_lcase) from t1 +-- !query schema +struct +-- !query output +aaaaaaaa aaaaaaaa +aaaaaaaa aaaaaaaa +aaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaa +abc abc +abcdcba abcdcba +bbabaaba a +efd2 efd2 +hello, world! nice day. hello, world! nice day. +i̇o i̇o +i̇o i̇o +i̇o i̇o +i̇o i̇o +kitten sitting +something else. nothing here. something else. nothing here. +spark sql + + +-- !query +select lower(utf8_binary collate utf8_lcase), lower(utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +aaaaaaaa aaaaaaaa +aaaaaaaa aaaaaaaa +aaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaa +abc abc +abcdcba abcdcba +bbabaaba a +efd2 efd2 +hello, world! nice day. hello, world! nice day. +i̇o i̇o +i̇o i̇o +i̇o i̇o +i̇o i̇o +kitten sitting +something else. nothing here. something else. nothing here. +spark sql + + +-- !query +select initcap(utf8_binary), initcap(utf8_lcase) from t1 +-- !query schema +struct +-- !query output +Aaaaaaaa Aaaaaaaa +Aaaaaaaa Aaaaaaaa +Aaaaaaaa Aaaaaaaaaaaaaaaaaaaaaaaa +Abc Abc +Abcdcba Abcdcba +Bbabaaba A +Efd2 Efd2 +Hello, World! Nice Day. Hello, World! Nice Day. +Kitten Sitting +Something Else. Nothing Here. Something Else. Nothing Here. +Spark Sql +İo İo +İo İo +İo İo +İo İo + + +-- !query +select initcap(utf8_binary collate utf8_lcase), initcap(utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +Aaaaaaaa Aaaaaaaa +Aaaaaaaa Aaaaaaaa +Aaaaaaaa Aaaaaaaaaaaaaaaaaaaaaaaa +Abc Abc +Abcdcba Abcdcba +Bbabaaba A +Efd2 Efd2 +Hello, World! Nice Day. Hello, World! Nice Day. +Kitten Sitting +Something Else. Nothing Here. Something Else. Nothing Here. +Spark Sql +İo İo +İo İo +İo İo +İo İo + + +-- !query +select overlay(utf8_binary, utf8_lcase, 2) from t1 +-- !query schema +struct +-- !query output +HHello, world! Nice day. +SSQLk +SSomething else. Nothing here. +aaBcDCbA +aaaAaAAaA +aaaAaaAaA +aaaAaaAaAaaAaaAaAaaAaaAaA +aabc +baAbAAbA +eefd2 +ksitTing +İi̇o +İİo +İİo +İİo + + +-- !query +select overlay(s, utf8_binary,1) from t1 +-- !query schema +struct +-- !query output +Hello, world! Nice day. +Something else. Nothing here. +Spark +aaAaAAaA +aaAaAAaA +aaAaAAaA +abc +abcdcba +bbAbAAbA +efd2 +kitten +İo +İo +İo +İo + + +-- !query +select overlay(utf8_binary collate utf8_binary, s collate utf8_lcase, 3) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" + } +} + + +-- !query +select overlay(utf8_binary, utf8_lcase collate utf8_binary, 2) from t1 +-- !query schema +struct +-- !query output +HHello, world! Nice day. +SSQLk +SSomething else. Nothing here. +aaBcDCbA +aaaAaAAaA +aaaAaaAaA +aaaAaaAaAaaAaaAaAaaAaaAaA +aabc +baAbAAbA +eefd2 +ksitTing +İi̇o +İİo +İİo +İİo + + +-- !query +select overlay(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase, 2) from t1 +-- !query schema +struct +-- !query output +HHello, world! Nice day. +SSQLk +SSomething else. Nothing here. +aaBcDCbA +aaaAaAAaA +aaaAaaAaA +aaaAaaAaAaaAaaAaAaaAaaAaA +aabc +baAbAAbA +eefd2 +ksitTing +İi̇o +İİo +İİo +İİo + + +-- !query +select overlay(utf8_binary, 'a', 2), overlay(utf8_lcase, 'a', 2) from t1 +-- !query schema +struct +-- !query output +Hallo, world! Nice day. Hallo, world! Nice day. +Saark SaL +Samething else. Nothing here. Samething else. Nothing here. +aaAaAAaA aaAaAAaA +aaAaAAaA aaAaaAaA +aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA +aac aac +aacdcba aacDCbA +baAbAAbA aa +ead2 ead2 +katten satTing +İa iao +İa İa +İa İa +İa İa + + +-- !query +select overlay(utf8_binary, 'AaAA' collate utf8_lcase, 2), overlay(utf8_lcase, 'AAa' collate utf8_binary, 2) from t1 +-- !query schema +struct +-- !query output +HAaAA, world! Nice day. HAAao, world! Nice day. +SAaAA SAAa +SAaAAhing else. Nothing here. SAAathing else. Nothing here. +aAaAA aAAa +aAaAAAaA aAAaAAaA +aAaAAAaA aAAaaAaA +aAaAAAaA aAAaaAaAaaAaaAaAaaAaaAaA +aAaAAba aAAaCbA +bAaAAAbA aAAa +eAaAA eAAa +kAaAAn sAAaing +İAaAA iAAa +İAaAA İAAa +İAaAA İAAa +İAaAA İAAa + + +-- !query +select format_string(format, utf8_binary, utf8_lcase) from t3 +-- !query schema +struct +-- !query output +abCdEabCdE + + +-- !query +select format_string(format collate utf8_lcase, utf8_lcase, utf8_binary collate utf8_lcase, 3), format_string(format, utf8_lcase collate utf8_binary, utf8_binary) from t3 +-- !query schema +struct +-- !query output +abCdEabCdE abCdEabCdE + + +-- !query +select format_string(format, utf8_binary, utf8_lcase) from t3 +-- !query schema +struct +-- !query output +abCdEabCdE + + +-- !query +select length(utf8_binary), length(utf8_lcase) from t1 +-- !query schema +struct +-- !query output +2 2 +2 3 +2 3 +23 23 +29 29 +3 2 +3 3 +4 4 +5 3 +6 7 +7 7 +8 1 +8 24 +8 8 +8 8 + + +-- !query +select length(utf8_binary collate utf8_lcase), length(utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +2 2 +2 3 +2 3 +23 23 +29 29 +3 2 +3 3 +4 4 +5 3 +6 7 +7 7 +8 1 +8 24 +8 8 +8 8 + + +-- !query +select bit_length(utf8_binary), bit_length(utf8_lcase) from t1 +-- !query schema +struct +-- !query output +184 184 +232 232 +24 24 +24 24 +24 32 +24 32 +32 24 +32 32 +40 24 +48 56 +56 56 +64 192 +64 64 +64 64 +64 8 + + +-- !query +select bit_length(utf8_binary collate utf8_lcase), bit_length(utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +184 184 +232 232 +24 24 +24 24 +24 32 +24 32 +32 24 +32 32 +40 24 +48 56 +56 56 +64 192 +64 64 +64 64 +64 8 + + +-- !query +select octet_length(utf8_binary), octet_length(utf8_lcase) from t1 +-- !query schema +struct +-- !query output +23 23 +29 29 +3 3 +3 3 +3 4 +3 4 +4 3 +4 4 +5 3 +6 7 +7 7 +8 1 +8 24 +8 8 +8 8 + + +-- !query +select octet_length(utf8_binary collate utf8_lcase), octet_length(utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +23 23 +29 29 +3 3 +3 3 +3 4 +3 4 +4 3 +4 4 +5 3 +6 7 +7 7 +8 1 +8 24 +8 8 +8 8 + + +-- !query +select octet_length(utf8_binary collate utf8_lcase_rtrim), octet_length(utf8_lcase collate utf8_binary_rtrim) from t1 +-- !query schema +struct +-- !query output +23 23 +29 29 +3 3 +3 3 +3 4 +3 4 +4 3 +4 4 +5 3 +6 7 +7 7 +8 1 +8 24 +8 8 +8 8 + + +-- !query +select substr(utf8_binary, 2, 2), substr(utf8_lcase, 2, 2) from t1 +-- !query schema +struct +-- !query output +aA aA +aA aA +aA aA +bA +bc Bc +bc bc +el el +fd fd +it it +o o +o o +o ̇o +o o +om om +pa QL + + +-- !query +select substr(utf8_binary collate utf8_lcase, 2, 2), substr(utf8_lcase collate utf8_binary, 2, 2) from t1 +-- !query schema +struct +-- !query output +aA aA +aA aA +aA aA +bA +bc Bc +bc bc +el el +fd fd +it it +o o +o o +o ̇o +o o +om om +pa QL + + +-- !query +select right(utf8_binary, 2), right(utf8_lcase, 2) from t1 +-- !query schema +struct +-- !query output +aA aA +aA aA +aA aA +bA a +ba bA +bc bc +d2 d2 +e. e. +en ng +o İo +rk QL +y. y. +İo o +İo İo +İo ̇o + + +-- !query +select right(utf8_binary collate utf8_lcase, 2), right(utf8_lcase collate utf8_binary, 2) from t1 +-- !query schema +struct +-- !query output +aA aA +aA aA +aA aA +bA a +ba bA +bc bc +d2 d2 +e. e. +en ng +o İo +rk QL +y. y. +İo o +İo İo +İo ̇o + + +-- !query +select left(utf8_binary, '2' collate utf8_lcase), left(utf8_lcase, 2) from t1 +-- !query schema +struct +-- !query output +He He +So So +Sp SQ +aa aa +aa aa +aa aa +ab aB +ab ab +bb a +ef ef +ki si +İo i̇ +İo İo +İo İo +İo İo + + +-- !query +select left(utf8_binary collate utf8_lcase, 2), left(utf8_lcase collate utf8_binary, 2) from t1 +-- !query schema +struct +-- !query output +He He +So So +Sp SQ +aa aa +aa aa +aa aa +ab aB +ab ab +bb a +ef ef +ki si +İo i̇ +İo İo +İo İo +İo İo + + +-- !query +select locate(utf8_binary, utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", + "sqlState" : "42P22", + "messageParameters" : { + "expr" : "\"locate(utf8_binary, utf8_lcase, 1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 38, + "fragment" : "locate(utf8_binary, utf8_lcase)" + } ] +} + + +-- !query +select locate(s, utf8_binary) from t1 +-- !query schema +struct +-- !query output +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + + +-- !query +select locate(utf8_binary collate utf8_binary, s collate utf8_lcase) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "COLLATION_MISMATCH.EXPLICIT", + "sqlState" : "42P21", + "messageParameters" : { + "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" + } +} + + +-- !query +select locate(utf8_binary, utf8_lcase collate utf8_binary) from t1 +-- !query schema +struct +-- !query output +0 +0 +0 +0 +0 +0 +0 +0 +1 +1 +1 +1 +1 +1 +1 + + +-- !query +select locate(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase, 3) from t1 +-- !query schema +struct +-- !query output +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +3 + + +-- !query +select locate(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 3) from t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"collate(utf8_binary, unicode_ai)\"", + "inputType" : "\"STRING COLLATE UNICODE_AI\"", + "paramIndex" : "first", + "requiredType" : "\"STRING\"", + "sqlExpr" : "\"locate(collate(utf8_binary, unicode_ai), collate(utf8_lcase, unicode_ai), 3)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 79, + "fragment" : "locate(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 3)" + } ] +} + + +-- !query +select locate(utf8_binary, 'a'), locate(utf8_lcase, 'a') from t1 +-- !query schema +struct +-- !query output +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 1 + + +-- !query +select locate(utf8_binary, 'AaAA' collate utf8_lcase, 4), locate(utf8_lcase, 'AAa' collate utf8_binary, 4) from t1 +-- !query schema +struct +-- !query output +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 + + +-- !query +select locate(utf8_binary, 'AaAA ' collate utf8_binary_rtrim, 4), locate(utf8_lcase, 'AAa ' collate utf8_binary, 4) from t1 +-- !query schema +struct +-- !query output +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 +0 0 + + +-- !query +drop table t1 +-- !query schema +struct<> +-- !query output + + + +-- !query +drop table t2 +-- !query schema +struct<> +-- !query output + + + +-- !query +drop table t3 +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/collations.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/collations.sql.out deleted file mode 100644 index 2055ec0c2c8..00000000000 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/collations.sql.out +++ /dev/null @@ -1,5834 +0,0 @@ --- Automatically generated by SQLQueryTestSuite --- !query -create table t1(utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet --- !query schema -struct<> --- !query output - - - --- !query -insert into t1 values('aaa', 'aaa') --- !query schema -struct<> --- !query output - - - --- !query -insert into t1 values('AAA', 'AAA') --- !query schema -struct<> --- !query output - - - --- !query -insert into t1 values('bbb', 'bbb') --- !query schema -struct<> --- !query output - - - --- !query -insert into t1 values('BBB', 'BBB') --- !query schema -struct<> --- !query output - - - --- !query -describe table t1 --- !query schema -struct --- !query output -utf8_binary string -utf8_lcase string collate UTF8_LCASE - - --- !query -select count(*) from t1 group by utf8_binary --- !query schema -struct --- !query output -1 -1 -1 -1 - - --- !query -select count(*) from t1 group by utf8_lcase --- !query schema -struct --- !query output -2 -2 - - --- !query -select * from t1 where utf8_binary = 'aaa' --- !query schema -struct --- !query output -aaa aaa - - --- !query -select * from t1 where utf8_lcase = 'aaa' collate utf8_lcase --- !query schema -struct --- !query output -AAA AAA -aaa aaa - - --- !query -select * from t1 where utf8_binary < 'bbb' --- !query schema -struct --- !query output -AAA AAA -BBB BBB -aaa aaa - - --- !query -select * from t1 where utf8_lcase < 'bbb' collate utf8_lcase --- !query schema -struct --- !query output -AAA AAA -aaa aaa - - --- !query -select l.utf8_binary, r.utf8_lcase from t1 l join t1 r on l.utf8_lcase = r.utf8_lcase --- !query schema -struct --- !query output -AAA AAA -AAA aaa -BBB BBB -BBB bbb -aaa AAA -aaa aaa -bbb BBB -bbb bbb - - --- !query -create table t2(utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet --- !query schema -struct<> --- !query output - - - --- !query -insert into t2 values('aaa', 'aaa') --- !query schema -struct<> --- !query output - - - --- !query -insert into t2 values('bbb', 'bbb') --- !query schema -struct<> --- !query output - - - --- !query -select * from t1 anti join t2 on t1.utf8_lcase = t2.utf8_lcase --- !query schema -struct --- !query output - - - --- !query -drop table t2 --- !query schema -struct<> --- !query output - - - --- !query -drop table t1 --- !query schema -struct<> --- !query output - - - --- !query -select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') except select col1 collate utf8_lcase from values ('aaa'), ('bbb') --- !query schema -struct --- !query output -zzz - - --- !query -select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') except all select col1 collate utf8_lcase from values ('aaa'), ('bbb') --- !query schema -struct --- !query output -aaa -bbb -zzz -zzz - - --- !query -select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') union select col1 collate utf8_lcase from values ('aaa'), ('bbb') --- !query schema -struct --- !query output -aaa -bbb -zzz - - --- !query -select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') union all select col1 collate utf8_lcase from values ('aaa'), ('bbb') --- !query schema -struct --- !query output -AAA -BBB -ZZZ -aaa -aaa -bbb -bbb -zzz - - --- !query -select col1 collate utf8_lcase from values ('aaa'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') intersect select col1 collate utf8_lcase from values ('aaa'), ('bbb') --- !query schema -struct --- !query output -aaa -bbb - - --- !query -select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') except select col1 collate unicode_ci from values ('aaa'), ('bbb') --- !query schema -struct<> --- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "INCOMPATIBLE_COLUMN_TYPE", - "sqlState" : "42825", - "messageParameters" : { - "columnOrdinalNumber" : "first", - "dataType1" : "\"STRING COLLATE UNICODE_CI\"", - "dataType2" : "\"STRING COLLATE UTF8_LCASE\"", - "hint" : "", - "operator" : "EXCEPT", - "tableOrdinalNumber" : "second" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 1, - "stopIndex" : 162, - "fragment" : "select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') except select col1 collate unicode_ci from values ('aaa'), ('bbb')" - } ] -} - - --- !query -select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') except all select col1 collate unicode_ci from values ('aaa'), ('bbb') --- !query schema -struct<> --- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "INCOMPATIBLE_COLUMN_TYPE", - "sqlState" : "42825", - "messageParameters" : { - "columnOrdinalNumber" : "first", - "dataType1" : "\"STRING COLLATE UNICODE_CI\"", - "dataType2" : "\"STRING COLLATE UTF8_LCASE\"", - "hint" : "", - "operator" : "EXCEPT ALL", - "tableOrdinalNumber" : "second" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 1, - "stopIndex" : 166, - "fragment" : "select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') except all select col1 collate unicode_ci from values ('aaa'), ('bbb')" - } ] -} - - --- !query -select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') union select col1 collate unicode_ci from values ('aaa'), ('bbb') --- !query schema -struct<> --- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "INCOMPATIBLE_COLUMN_TYPE", - "sqlState" : "42825", - "messageParameters" : { - "columnOrdinalNumber" : "first", - "dataType1" : "\"STRING COLLATE UNICODE_CI\"", - "dataType2" : "\"STRING COLLATE UTF8_LCASE\"", - "hint" : "", - "operator" : "UNION", - "tableOrdinalNumber" : "second" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 1, - "stopIndex" : 161, - "fragment" : "select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') union select col1 collate unicode_ci from values ('aaa'), ('bbb')" - } ] -} - - --- !query -select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') union all select col1 collate unicode_ci from values ('aaa'), ('bbb') --- !query schema -struct<> --- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "INCOMPATIBLE_COLUMN_TYPE", - "sqlState" : "42825", - "messageParameters" : { - "columnOrdinalNumber" : "first", - "dataType1" : "\"STRING COLLATE UNICODE_CI\"", - "dataType2" : "\"STRING COLLATE UTF8_LCASE\"", - "hint" : "", - "operator" : "UNION", - "tableOrdinalNumber" : "second" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 1, - "stopIndex" : 165, - "fragment" : "select col1 collate utf8_lcase from values ('aaa'), ('AAA'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') union all select col1 collate unicode_ci from values ('aaa'), ('bbb')" - } ] -} - - --- !query -select col1 collate utf8_lcase from values ('aaa'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') intersect select col1 collate unicode_ci from values ('aaa'), ('bbb') --- !query schema -struct<> --- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "INCOMPATIBLE_COLUMN_TYPE", - "sqlState" : "42825", - "messageParameters" : { - "columnOrdinalNumber" : "first", - "dataType1" : "\"STRING COLLATE UNICODE_CI\"", - "dataType2" : "\"STRING COLLATE UTF8_LCASE\"", - "hint" : "", - "operator" : "INTERSECT", - "tableOrdinalNumber" : "second" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 1, - "stopIndex" : 156, - "fragment" : "select col1 collate utf8_lcase from values ('aaa'), ('bbb'), ('BBB'), ('zzz'), ('ZZZ') intersect select col1 collate unicode_ci from values ('aaa'), ('bbb')" - } ] -} - - --- !query -create table t1 (c1 struct) USING PARQUET --- !query schema -struct<> --- !query output - - - --- !query -insert into t1 values (named_struct('utf8_binary', 'aaa', 'utf8_lcase', 'aaa')) --- !query schema -struct<> --- !query output - - - --- !query -insert into t1 values (named_struct('utf8_binary', 'AAA', 'utf8_lcase', 'AAA')) --- !query schema -struct<> --- !query output - - - --- !query -select count(*) from t1 group by c1.utf8_binary --- !query schema -struct --- !query output -1 -1 - - --- !query -select count(*) from t1 group by c1.utf8_lcase --- !query schema -struct --- !query output -2 - - --- !query -drop table t1 --- !query schema -struct<> --- !query output - - - --- !query -select array_contains(ARRAY('aaa' collate utf8_lcase),'AAA' collate utf8_lcase) --- !query schema -struct --- !query output -true - - --- !query -select array_position(ARRAY('aaa' collate utf8_lcase, 'bbb' collate utf8_lcase),'BBB' collate utf8_lcase) --- !query schema -struct --- !query output -2 - - --- !query -select nullif('aaa' COLLATE utf8_lcase, 'AAA' COLLATE utf8_lcase) --- !query schema -struct --- !query output -NULL - - --- !query -select least('aaa' COLLATE utf8_lcase, 'AAA' collate utf8_lcase, 'a' collate utf8_lcase) --- !query schema -struct --- !query output -a - - --- !query -select arrays_overlap(array('aaa' collate utf8_lcase), array('AAA' collate utf8_lcase)) --- !query schema -struct --- !query output -true - - --- !query -select array_distinct(array('aaa' collate utf8_lcase, 'AAA' collate utf8_lcase)) --- !query schema -struct> --- !query output -["aaa"] - - --- !query -select array_union(array('aaa' collate utf8_lcase), array('AAA' collate utf8_lcase)) --- !query schema -struct> --- !query output -["aaa"] - - --- !query -select array_intersect(array('aaa' collate utf8_lcase), array('AAA' collate utf8_lcase)) --- !query schema -struct> --- !query output -["aaa"] - - --- !query -select array_except(array('aaa' collate utf8_lcase), array('AAA' collate utf8_lcase)) --- !query schema -struct> --- !query output -[] - - --- !query -select 'a' collate unicode < 'A' --- !query schema -struct<(collate(a, unicode) < 'A' collate UNICODE):boolean> --- !query output -true - - --- !query -select 'a' collate unicode_ci = 'A' --- !query schema -struct<(collate(a, unicode_ci) = 'A' collate UNICODE_CI):boolean> --- !query output -true - - --- !query -select 'a' collate unicode_ai = 'Ã¥' --- !query schema -struct<(collate(a, unicode_ai) = 'Ã¥' collate UNICODE_AI):boolean> --- !query output -true - - --- !query -select 'a' collate unicode_ci_ai = 'Ã…' --- !query schema -struct<(collate(a, unicode_ci_ai) = 'Ã…' collate UNICODE_CI_AI):boolean> --- !query output -true - - --- !query -select 'a' collate en < 'A' --- !query schema -struct<(collate(a, en) < 'A' collate en):boolean> --- !query output -true - - --- !query -select 'a' collate en_ci = 'A' --- !query schema -struct<(collate(a, en_ci) = 'A' collate en_CI):boolean> --- !query output -true - - --- !query -select 'a' collate en_ai = 'Ã¥' --- !query schema -struct<(collate(a, en_ai) = 'Ã¥' collate en_AI):boolean> --- !query output -true - - --- !query -select 'a' collate en_ci_ai = 'Ã…' --- !query schema -struct<(collate(a, en_ci_ai) = 'Ã…' collate en_CI_AI):boolean> --- !query output -true - - --- !query -select 'Kypper' collate sv < 'Köpfe' --- !query schema -struct<(collate(Kypper, sv) < 'Köpfe' collate sv):boolean> --- !query output -true - - --- !query -select 'Kypper' collate de > 'Köpfe' --- !query schema -struct<(collate(Kypper, de) > 'Köpfe' collate de):boolean> --- !query output -true - - --- !query -select 'I' collate tr_ci = 'ı' --- !query schema -struct<(collate(I, tr_ci) = 'ı' collate tr_CI):boolean> --- !query output -true - - --- !query -create table t4 (text string collate utf8_binary, pairDelim string collate utf8_lcase, keyValueDelim string collate utf8_binary) using parquet --- !query schema -struct<> --- !query output - - - --- !query -insert into t4 values('a:1,b:2,c:3', ',', ':') --- !query schema -struct<> --- !query output - - - --- !query -select str_to_map(text, pairDelim, keyValueDelim) from t4 --- !query schema -struct<> --- !query output -org.apache.spark.SparkRuntimeException -{ - "errorClass" : "INDETERMINATE_COLLATION", - "sqlState" : "42P22" -} - - --- !query -select str_to_map(text collate utf8_binary, pairDelim collate utf8_lcase, keyValueDelim collate utf8_binary) from t4 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" - } -} - - --- !query -select str_to_map(text collate utf8_binary, pairDelim collate utf8_binary, keyValueDelim collate utf8_binary) from t4 --- !query schema -struct> --- !query output -{"a":"1","b":"2","c":"3"} - - --- !query -select str_to_map(text collate unicode_ai, pairDelim collate unicode_ai, keyValueDelim collate unicode_ai) from t4 --- !query schema -struct<> --- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", - "sqlState" : "42K09", - "messageParameters" : { - "inputSql" : "\"collate(text, unicode_ai)\"", - "inputType" : "\"STRING COLLATE UNICODE_AI\"", - "paramIndex" : "first", - "requiredType" : "\"STRING\"", - "sqlExpr" : "\"str_to_map(collate(text, unicode_ai), collate(pairDelim, unicode_ai), collate(keyValueDelim, unicode_ai))\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 106, - "fragment" : "str_to_map(text collate unicode_ai, pairDelim collate unicode_ai, keyValueDelim collate unicode_ai)" - } ] -} - - --- !query -drop table t4 --- !query schema -struct<> --- !query output - - - --- !query -create table t5(s string, utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet --- !query schema -struct<> --- !query output - - - --- !query -insert into t5 values ('Spark', 'Spark', 'SQL') --- !query schema -struct<> --- !query output - - - --- !query -insert into t5 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaAAaA') --- !query schema -struct<> --- !query output - - - --- !query -insert into t5 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaaAaA') --- !query schema -struct<> --- !query output - - - --- !query -insert into t5 values ('aaAaAAaA', 'aaAaAAaA', 'aaAaaAaAaaAaaAaAaaAaaAaA') --- !query schema -struct<> --- !query output - - - --- !query -insert into t5 values ('bbAbaAbA', 'bbAbAAbA', 'a') --- !query schema -struct<> --- !query output - - - --- !query -insert into t5 values ('İo', 'İo', 'İo') --- !query schema -struct<> --- !query output - - - --- !query -insert into t5 values ('İo', 'İo', 'İo ') --- !query schema -struct<> --- !query output - - - --- !query -insert into t5 values ('İo', 'İo ', 'İo') --- !query schema -struct<> --- !query output - - - --- !query -insert into t5 values ('İo', 'İo', 'i̇o') --- !query schema -struct<> --- !query output - - - --- !query -insert into t5 values ('efd2', 'efd2', 'efd2') --- !query schema -struct<> --- !query output - - - --- !query -insert into t5 values ('Hello, world! Nice day.', 'Hello, world! Nice day.', 'Hello, world! Nice day.') --- !query schema -struct<> --- !query output - - - --- !query -insert into t5 values ('Something else. Nothing here.', 'Something else. Nothing here.', 'Something else. Nothing here.') --- !query schema -struct<> --- !query output - - - --- !query -insert into t5 values ('kitten', 'kitten', 'sitTing') --- !query schema -struct<> --- !query output - - - --- !query -insert into t5 values ('abc', 'abc', 'abc') --- !query schema -struct<> --- !query output - - - --- !query -insert into t5 values ('abcdcba', 'abcdcba', 'aBcDCbA') --- !query schema -struct<> --- !query output - - - --- !query -create table t6(ascii long) using parquet --- !query schema -struct<> --- !query output - - - --- !query -insert into t6 values (97) --- !query schema -struct<> --- !query output - - - --- !query -insert into t6 values (66) --- !query schema -struct<> --- !query output - - - --- !query -create table t7(ascii double) using parquet --- !query schema -struct<> --- !query output - - - --- !query -insert into t7 values (97.52143) --- !query schema -struct<> --- !query output - - - --- !query -insert into t7 values (66.421) --- !query schema -struct<> --- !query output - - - --- !query -create table t8(format string collate utf8_binary, utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet --- !query schema -struct<> --- !query output - - - --- !query -insert into t8 values ('%s%s', 'abCdE', 'abCdE') --- !query schema -struct<> --- !query output - - - --- !query -create table t9(num long) using parquet --- !query schema -struct<> --- !query output - - - --- !query -insert into t9 values (97) --- !query schema -struct<> --- !query output - - - --- !query -insert into t9 values (66) --- !query schema -struct<> --- !query output - - - --- !query -create table t10(utf8_binary string collate utf8_binary, utf8_lcase string collate utf8_lcase) using parquet --- !query schema -struct<> --- !query output - - - --- !query -insert into t10 values ('aaAaAAaA', 'aaAaaAaA') --- !query schema -struct<> --- !query output - - - --- !query -insert into t10 values ('efd2', 'efd2') --- !query schema -struct<> --- !query output - - - --- !query -select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -SQL SQL -Something else. Nothing here. Something else. Nothing here. -a a -aBcDCbA aBcDCbA -aaAaAAaA aaAaAAaA -aaAaaAaA aaAaaAaA -aaAaaAaAaaAaaAaAaaAaaAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -efd2 efd2 -i̇o i̇o -sitTing sitTing -İo İo -İo İo -İo İo - - --- !query -select concat_ws(' ', utf8_binary, utf8_lcase) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo İo -İo i̇o -İo İo -İo İo - - --- !query -select concat_ws(' ' collate utf8_binary, utf8_binary, 'SQL' collate utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" - } -} - - --- !query -select concat_ws(' ' collate utf8_lcase, utf8_binary, 'SQL' collate utf8_lcase) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. SQL -Something else. Nothing here. SQL -Spark SQL -aaAaAAaA SQL -aaAaAAaA SQL -aaAaAAaA SQL -abc SQL -abcdcba SQL -bbAbAAbA SQL -efd2 SQL -kitten SQL -İo SQL -İo SQL -İo SQL -İo SQL - - --- !query -select concat_ws(',', utf8_lcase, 'word'), concat_ws(',', utf8_binary, 'word') from t5 --- !query schema -struct --- !query output -Hello, world! Nice day.,word Hello, world! Nice day.,word -SQL,word Spark,word -Something else. Nothing here.,word Something else. Nothing here.,word -a,word bbAbAAbA,word -aBcDCbA,word abcdcba,word -aaAaAAaA,word aaAaAAaA,word -aaAaaAaA,word aaAaAAaA,word -aaAaaAaAaaAaaAaAaaAaaAaA,word aaAaAAaA,word -abc,word abc,word -efd2,word efd2,word -i̇o,word İo,word -sitTing,word kitten,word -İo ,word İo,word -İo,word İo ,word -İo,word İo,word - - --- !query -select concat_ws(',', utf8_lcase, 'word' collate utf8_binary), concat_ws(',', utf8_binary, 'word' collate utf8_lcase) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day.,word Hello, world! Nice day.,word -SQL,word Spark,word -Something else. Nothing here.,word Something else. Nothing here.,word -a,word bbAbAAbA,word -aBcDCbA,word abcdcba,word -aaAaAAaA,word aaAaAAaA,word -aaAaaAaA,word aaAaAAaA,word -aaAaaAaAaaAaaAaAaaAaaAaA,word aaAaAAaA,word -abc,word abc,word -efd2,word efd2,word -i̇o,word İo,word -sitTing,word kitten,word -İo ,word İo,word -İo,word İo ,word -İo,word İo,word - - --- !query -select elt(2, s, utf8_binary) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. -Something else. Nothing here. -Spark -aaAaAAaA -aaAaAAaA -aaAaAAaA -abc -abcdcba -bbAbAAbA -efd2 -kitten -İo -İo -İo -İo - - --- !query -select elt(2, utf8_binary, utf8_lcase, s) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. -SQL -Something else. Nothing here. -a -aBcDCbA -aaAaAAaA -aaAaaAaA -aaAaaAaAaaAaaAaAaaAaaAaA -abc -efd2 -i̇o -sitTing -İo -İo -İo - - --- !query -select elt(1, utf8_binary collate utf8_binary, utf8_lcase collate utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" - } -} - - --- !query -select elt(1, utf8_binary collate utf8_binary, utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. -Something else. Nothing here. -Spark -aaAaAAaA -aaAaAAaA -aaAaAAaA -abc -abcdcba -bbAbAAbA -efd2 -kitten -İo -İo -İo -İo - - --- !query -select elt(1, utf8_binary collate utf8_binary, utf8_lcase) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. -Something else. Nothing here. -Spark -aaAaAAaA -aaAaAAaA -aaAaAAaA -abc -abcdcba -bbAbAAbA -efd2 -kitten -İo -İo -İo -İo - - --- !query -select elt(1, utf8_binary, 'word'), elt(1, utf8_lcase, 'word') from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select elt(1, utf8_binary, 'word' collate utf8_lcase), elt(1, utf8_lcase, 'word' collate utf8_binary) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select split_part(utf8_binary, utf8_lcase, 3) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.SparkRuntimeException -{ - "errorClass" : "INDETERMINATE_COLLATION", - "sqlState" : "42P22" -} - - --- !query -select split_part(s, utf8_binary, 1) from t5 --- !query schema -struct --- !query output - - - - - - - - - - - - - -bbAbaAbA -İo - - --- !query -select split_part(utf8_binary collate utf8_binary, s collate utf8_lcase, 1) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" - } -} - - --- !query -select split_part(utf8_binary, utf8_lcase collate utf8_binary, 2) from t5 --- !query schema -struct --- !query output - - - --- !query -select split_part(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase, 2) from t5 --- !query schema -struct --- !query output - - - - - - - - - - - - - - -b - - --- !query -select split_part(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 2) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", - "sqlState" : "42K09", - "messageParameters" : { - "inputSql" : "\"collate(utf8_binary, unicode_ai)\"", - "inputType" : "\"STRING COLLATE UNICODE_AI\"", - "paramIndex" : "first", - "requiredType" : "\"STRING\"", - "sqlExpr" : "\"split_part(collate(utf8_binary, unicode_ai), collate(utf8_lcase, unicode_ai), 2)\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 83, - "fragment" : "split_part(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 2)" - } ] -} - - --- !query -select split_part(utf8_binary, 'a', 3), split_part(utf8_lcase, 'a', 3) from t5 --- !query schema -struct --- !query output - - - - - - - - - - - - -A -A -A - - --- !query -select split_part(utf8_binary, 'a' collate utf8_lcase, 3), split_part(utf8_lcase, 'a' collate utf8_binary, 3) from t5 --- !query schema -struct --- !query output - - - - - - - - - - - - - A - A - A - - --- !query -select split_part(utf8_binary, 'a ' collate utf8_lcase_rtrim, 3), split_part(utf8_lcase, 'a' collate utf8_binary, 3) from t5 --- !query schema -struct --- !query output - - - - - - - - - - - - - A - A - A - - --- !query -select contains(utf8_binary, utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", - "sqlState" : "42P22", - "messageParameters" : { - "expr" : "\"contains(utf8_binary, utf8_lcase)\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 40, - "fragment" : "contains(utf8_binary, utf8_lcase)" - } ] -} - - --- !query -select contains(s, utf8_binary) from t5 --- !query schema -struct --- !query output -false -false -true -true -true -true -true -true -true -true -true -true -true -true -true - - --- !query -select contains(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" - } -} - - --- !query -select contains(utf8_binary, utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -false -false -false -false -false -false -false -false -true -true -true -true -true -true -true - - --- !query -select contains(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t5 --- !query schema -struct --- !query output -false -false -false -false -true -true -true -true -true -true -true -true -true -true -true - - --- !query -select contains(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", - "sqlState" : "42K09", - "messageParameters" : { - "inputSql" : "\"collate(utf8_binary, unicode_ai)\"", - "inputType" : "\"STRING COLLATE UNICODE_AI\"", - "paramIndex" : "first", - "requiredType" : "\"STRING\"", - "sqlExpr" : "\"contains(collate(utf8_binary, unicode_ai), collate(utf8_lcase, unicode_ai))\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 78, - "fragment" : "contains(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai)" - } ] -} - - --- !query -select contains(utf8_binary, 'a'), contains(utf8_lcase, 'a') from t5 --- !query schema -struct --- !query output -false false -false false -false false -false false -false false -false false -false false -false true -true false -true true -true true -true true -true true -true true -true true - - --- !query -select contains(utf8_binary, 'AaAA' collate utf8_lcase), contains(utf8_lcase, 'AAa' collate utf8_binary) from t5 --- !query schema -struct --- !query output -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -true false -true false -true true - - --- !query -select contains(utf8_binary, 'AaAA ' collate utf8_lcase_rtrim), contains(utf8_lcase, 'AAa ' collate utf8_binary_rtrim) from t5 --- !query schema -struct --- !query output -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -true false -true false -true true - - --- !query -select substring_index(utf8_binary, utf8_lcase, 2) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", - "sqlState" : "42P22", - "messageParameters" : { - "expr" : "\"substring_index(utf8_binary, utf8_lcase, 2)\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 50, - "fragment" : "substring_index(utf8_binary, utf8_lcase, 2)" - } ] -} - - --- !query -select substring_index(s, utf8_binary,1) from t5 --- !query schema -struct --- !query output - - - - - - - - - - - - - -bbAbaAbA -İo - - --- !query -select substring_index(utf8_binary collate utf8_binary, s collate utf8_lcase, 3) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" - } -} - - --- !query -select substring_index(utf8_binary, utf8_lcase collate utf8_binary, 2) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. -Something else. Nothing here. -Spark -aaAaAAaA -aaAaAAaA -aaAaAAaA -abc -abcdcba -bbAbAAbA -efd2 -kitten -İo -İo -İo -İo - - --- !query -select substring_index(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase, 2) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. -Something else. Nothing here. -Spark -aaAaAAaA -aaAaAAaA -aaAaAAaA -abc -abcdcba -bbAb -efd2 -kitten -İo -İo -İo -İo - - --- !query -select substring_index(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 2) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", - "sqlState" : "42K09", - "messageParameters" : { - "inputSql" : "\"collate(utf8_binary, unicode_ai)\"", - "inputType" : "\"STRING COLLATE UNICODE_AI\"", - "paramIndex" : "first", - "requiredType" : "\"STRING\"", - "sqlExpr" : "\"substring_index(collate(utf8_binary, unicode_ai), collate(utf8_lcase, unicode_ai), 2)\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 88, - "fragment" : "substring_index(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 2)" - } ] -} - - --- !query -select substring_index(utf8_binary, 'a', 2), substring_index(utf8_lcase, 'a', 2) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -a a -a a -a a -abc abc -abcdcb aBcDCb -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select substring_index(utf8_binary, 'AaAA' collate utf8_lcase, 2), substring_index(utf8_lcase, 'AAa' collate utf8_binary, 2) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -a aaAaAAaA -a aaAaaAaA -a aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select substring_index(utf8_binary, 'AaAA ' collate utf8_lcase_rtrim, 2), substring_index(utf8_lcase, 'AAa' collate utf8_binary, 2) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -a aaAaAAaA -a aaAaaAaA -a aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select instr(utf8_binary, utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", - "sqlState" : "42P22", - "messageParameters" : { - "expr" : "\"instr(utf8_binary, utf8_lcase)\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 37, - "fragment" : "instr(utf8_binary, utf8_lcase)" - } ] -} - - --- !query -select instr(s, utf8_binary) from t5 --- !query schema -struct --- !query output -0 -0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 - - --- !query -select instr(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" - } -} - - --- !query -select instr(utf8_binary, utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -0 -0 -0 -0 -0 -0 -0 -0 -1 -1 -1 -1 -1 -1 -1 - - --- !query -select instr(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t5 --- !query schema -struct --- !query output -0 -0 -0 -0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -3 - - --- !query -select instr(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", - "sqlState" : "42K09", - "messageParameters" : { - "inputSql" : "\"collate(utf8_binary, unicode_ai)\"", - "inputType" : "\"STRING COLLATE UNICODE_AI\"", - "paramIndex" : "first", - "requiredType" : "\"STRING\"", - "sqlExpr" : "\"instr(collate(utf8_binary, unicode_ai), collate(utf8_lcase, unicode_ai))\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 75, - "fragment" : "instr(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai)" - } ] -} - - --- !query -select instr(utf8_binary, 'a'), instr(utf8_lcase, 'a') from t5 --- !query schema -struct --- !query output -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 1 -1 1 -1 1 -1 1 -1 1 -1 1 -21 21 -3 0 - - --- !query -select instr(utf8_binary, 'AaAA' collate utf8_lcase), instr(utf8_lcase, 'AAa' collate utf8_binary) from t5 --- !query schema -struct --- !query output -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -1 0 -1 0 -1 5 - - --- !query -select find_in_set(utf8_binary, utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", - "sqlState" : "42P22", - "messageParameters" : { - "expr" : "\"find_in_set(utf8_binary, utf8_lcase)\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 43, - "fragment" : "find_in_set(utf8_binary, utf8_lcase)" - } ] -} - - --- !query -select find_in_set(s, utf8_binary) from t5 --- !query schema -struct --- !query output -0 -0 -0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 - - --- !query -select find_in_set(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" - } -} - - --- !query -select find_in_set(utf8_binary, utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -1 -1 -1 -1 -1 - - --- !query -select find_in_set(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t5 --- !query schema -struct --- !query output -0 -0 -0 -0 -0 -0 -0 -1 -1 -1 -1 -1 -1 -1 -1 - - --- !query -select find_in_set(utf8_binary, 'aaAaaAaA,i̇o'), find_in_set(utf8_lcase, 'aaAaaAaA,i̇o') from t5 --- !query schema -struct --- !query output -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 1 -0 1 -0 2 -0 2 -0 2 - - --- !query -select find_in_set(utf8_binary, 'aaAaaAaA,i̇o' collate utf8_lcase), find_in_set(utf8_lcase, 'aaAaaAaA,i̇o' collate utf8_binary) from t5 --- !query schema -struct --- !query output -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -1 0 -1 0 -1 1 -2 0 -2 0 -2 2 - - --- !query -select find_in_set(utf8_binary, 'aaAaaAaA,i̇o ' collate utf8_lcase_rtrim), find_in_set(utf8_lcase, 'aaAaaAaA,i̇o' collate utf8_binary) from t5 --- !query schema -struct --- !query output -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -1 0 -1 0 -1 1 -2 0 -2 0 -2 0 -2 2 - - --- !query -select startswith(utf8_binary, utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", - "sqlState" : "42P22", - "messageParameters" : { - "expr" : "\"startswith(utf8_binary, utf8_lcase)\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 42, - "fragment" : "startswith(utf8_binary, utf8_lcase)" - } ] -} - - --- !query -select startswith(s, utf8_binary) from t5 --- !query schema -struct --- !query output -false -false -true -true -true -true -true -true -true -true -true -true -true -true -true - - --- !query -select startswith(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" - } -} - - --- !query -select startswith(utf8_binary, utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -false -false -false -false -false -false -false -false -true -true -true -true -true -true -true - - --- !query -select startswith(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t5 --- !query schema -struct --- !query output -false -false -false -false -false -true -true -true -true -true -true -true -true -true -true - - --- !query -select startswith(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", - "sqlState" : "42K09", - "messageParameters" : { - "inputSql" : "\"collate(utf8_binary, unicode_ai)\"", - "inputType" : "\"STRING COLLATE UNICODE_AI\"", - "paramIndex" : "first", - "requiredType" : "\"STRING\"", - "sqlExpr" : "\"startswith(collate(utf8_binary, unicode_ai), collate(utf8_lcase, unicode_ai))\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 80, - "fragment" : "startswith(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai)" - } ] -} - - --- !query -select startswith(utf8_binary, 'aaAaaAaA'), startswith(utf8_lcase, 'aaAaaAaA') from t5 --- !query schema -struct --- !query output -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -false true -false true -false true - - --- !query -select startswith(utf8_binary, 'aaAaaAaA' collate utf8_lcase), startswith(utf8_lcase, 'aaAaaAaA' collate utf8_binary) from t5 --- !query schema -struct --- !query output -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -true false -true true -true true - - --- !query -select startswith(utf8_binary, 'aaAaaAaA ' collate utf8_lcase_rtrim), startswith(utf8_lcase, 'aaAaaAaA' collate utf8_binary) from t5 --- !query schema -struct --- !query output -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -true false -true true -true true - - --- !query -select translate(utf8_lcase, utf8_lcase, '12345') from t5 --- !query schema -struct --- !query output -1 -11111111 -11111111 -111111111111111111111111 -12 -12 -123 -123 -123 -123 -12332 -12335532 -1234 -1234321 -123454142544 - - --- !query -select translate(utf8_binary, utf8_lcase, '12345') from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", - "sqlState" : "42P22", - "messageParameters" : { - "expr" : "\"translate(utf8_binary, utf8_lcase, 12345)\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 50, - "fragment" : "translate(utf8_binary, utf8_lcase, '12345')" - } ] -} - - --- !query -select translate(utf8_binary, 'aBc' collate utf8_lcase, '12345' collate utf8_binary) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING COLLATE UTF8_LCASE\", \"STRING\"" - } -} - - --- !query -select translate(utf8_binary, 'SQL' collate utf8_lcase, '12345' collate utf8_lcase) from t5 --- !query schema -struct --- !query output -1omething e31e. Nothing here. -1park -He33o, wor3d! Nice day. -aaAaAAaA -aaAaAAaA -aaAaAAaA -abc -abcdcba -bbAbAAbA -efd2 -kitten -İo -İo -İo -İo - - --- !query -select translate(utf8_binary, 'SQL' collate unicode_ai, '12345' collate unicode_ai) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", - "sqlState" : "42K09", - "messageParameters" : { - "inputSql" : "\"utf8_binary\"", - "inputType" : "\"STRING COLLATE UNICODE_AI\"", - "paramIndex" : "first", - "requiredType" : "\"STRING\"", - "sqlExpr" : "\"translate(utf8_binary, collate(SQL, unicode_ai), collate(12345, unicode_ai))\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 83, - "fragment" : "translate(utf8_binary, 'SQL' collate unicode_ai, '12345' collate unicode_ai)" - } ] -} - - --- !query -select translate(utf8_lcase, 'aaAaaAaA', '12345'), translate(utf8_binary, 'aaAaaAaA', '12345') from t5 --- !query schema -struct --- !query output -1 bb3b33b3 -11111111 11313313 -11111111 11313313 -111111111111111111111111 11313313 -1BcDCb1 1bcdcb1 -1bc 1bc -Hello, world! Nice d1y. Hello, world! Nice d1y. -SQL Sp1rk -Something else. Nothing here. Something else. Nothing here. -efd2 efd2 -i̇o İo -sitTing kitten -İo İo -İo İo -İo İo - - --- !query -select translate(utf8_lcase, 'aBc' collate utf8_binary, '12345'), translate(utf8_binary, 'aBc' collate utf8_lcase, '12345') from t5 --- !query schema -struct --- !query output -1 22121121 -11A11A1A 11111111 -11A11A1A11A11A1A11A11A1A 11111111 -11A1AA1A 11111111 -123DCbA 123d321 -1b3 123 -Hello, world! Ni3e d1y. Hello, world! Ni3e d1y. -SQL Sp1rk -Something else. Nothing here. Something else. Nothing here. -efd2 efd2 -i̇o İo -sitTing kitten -İo İo -İo İo -İo İo - - --- !query -select translate(utf8_lcase, 'aBc ' collate utf8_binary_rtrim, '12345'), translate(utf8_binary, 'aBc' collate utf8_lcase, '12345') from t5 --- !query schema -struct --- !query output -1 22121121 -11A11A1A 11111111 -11A11A1A11A11A1A11A11A1A 11111111 -11A1AA1A 11111111 -123DCbA 123d321 -1b3 123 -Hello,4world!4Ni3e4d1y. Hello, world! Ni3e d1y. -SQL Sp1rk -Something4else.4Nothing4here. Something else. Nothing here. -efd2 efd2 -i̇o İo -sitTing kitten -İo İo -İo İo -İo4 İo - - --- !query -select replace(utf8_binary, utf8_lcase, 'abc') from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", - "sqlState" : "42P22", - "messageParameters" : { - "expr" : "\"replace(utf8_binary, utf8_lcase, abc)\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 46, - "fragment" : "replace(utf8_binary, utf8_lcase, 'abc')" - } ] -} - - --- !query -select replace(s, utf8_binary, 'abc') from t5 --- !query schema -struct --- !query output -abc -abc -abc -abc -abc -abc -abc -abc -abc -abc -abc -abc -abc -bbAbaAbA -İo - - --- !query -select replace(utf8_binary collate utf8_binary, s collate utf8_lcase, 'abc') from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" - } -} - - --- !query -select replace(utf8_binary, utf8_lcase collate utf8_binary, 'abc') from t5 --- !query schema -struct --- !query output -Spark -aaAaAAaA -aaAaAAaA -abc -abc -abc -abc -abc -abc -abc -abcdcba -bbAbAAbA -kitten -İo -İo - - --- !query -select replace(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase, 'abc') from t5 --- !query schema -struct --- !query output -Spark -aaAaAAaA -abc -abc -abc -abc -abc -abc -abc -abc -abc -abc -bbabcbabcabcbabc -kitten -İo - - --- !query -select replace(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 'abc') from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", - "sqlState" : "42K09", - "messageParameters" : { - "inputSql" : "\"collate(utf8_binary, unicode_ai)\"", - "inputType" : "\"STRING COLLATE UNICODE_AI\"", - "paramIndex" : "first", - "requiredType" : "\"STRING\"", - "sqlExpr" : "\"replace(collate(utf8_binary, unicode_ai), collate(utf8_lcase, unicode_ai), 'abc' collate UNICODE_AI)\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 84, - "fragment" : "replace(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 'abc')" - } ] -} - - --- !query -select replace(utf8_binary, 'aaAaaAaA', 'abc'), replace(utf8_lcase, 'aaAaaAaA', 'abc') from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA abc -aaAaAAaA abc -aaAaAAaA abcabcabc -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select replace(utf8_binary, 'aaAaaAaA' collate utf8_lcase, 'abc'), replace(utf8_lcase, 'aaAaaAaA' collate utf8_binary, 'abc') from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -abc aaAaAAaA -abc abc -abc abc -abc abcabcabc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select replace(utf8_binary, 'aaAaaAaA ' collate utf8_lcase_rtrim, 'abc'), replace(utf8_lcase, 'aaAaaAaA' collate utf8_binary, 'abc') from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA aaAaAAaA -aaAaAAaA abc -aaAaAAaA abcabcabc -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select endswith(utf8_binary, utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", - "sqlState" : "42P22", - "messageParameters" : { - "expr" : "\"endswith(utf8_binary, utf8_lcase)\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 40, - "fragment" : "endswith(utf8_binary, utf8_lcase)" - } ] -} - - --- !query -select endswith(s, utf8_binary) from t5 --- !query schema -struct --- !query output -false -false -true -true -true -true -true -true -true -true -true -true -true -true -true - - --- !query -select endswith(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" - } -} - - --- !query -select endswith(utf8_binary, utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -false -false -false -false -false -false -false -false -false -true -true -true -true -true -true - - --- !query -select endswith(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t5 --- !query schema -struct --- !query output -false -false -false -false -false -true -true -true -true -true -true -true -true -true -true - - --- !query -select endswith(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", - "sqlState" : "42K09", - "messageParameters" : { - "inputSql" : "\"collate(utf8_binary, unicode_ai)\"", - "inputType" : "\"STRING COLLATE UNICODE_AI\"", - "paramIndex" : "first", - "requiredType" : "\"STRING\"", - "sqlExpr" : "\"endswith(collate(utf8_binary, unicode_ai), collate(utf8_lcase, unicode_ai))\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 78, - "fragment" : "endswith(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai)" - } ] -} - - --- !query -select endswith(utf8_binary, 'aaAaaAaA'), endswith(utf8_lcase, 'aaAaaAaA') from t5 --- !query schema -struct --- !query output -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -false true -false true -false true - - --- !query -select endswith(utf8_binary, 'aaAaaAaA' collate utf8_lcase), endswith(utf8_lcase, 'aaAaaAaA' collate utf8_binary) from t5 --- !query schema -struct --- !query output -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -true false -true true -true true - - --- !query -select endswith(utf8_binary, 'aaAaaAaA ' collate utf8_lcase_rtrim), endswith(utf8_lcase, 'aaAaaAaA' collate utf8_binary) from t5 --- !query schema -struct --- !query output -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -false false -true false -true true -true true - - --- !query -select repeat(utf8_binary, 3), repeat(utf8_lcase, 2) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day.Hello, world! Nice day.Hello, world! Nice day. Hello, world! Nice day.Hello, world! Nice day. -Something else. Nothing here.Something else. Nothing here.Something else. Nothing here. Something else. Nothing here.Something else. Nothing here. -SparkSparkSpark SQLSQL -aaAaAAaAaaAaAAaAaaAaAAaA aaAaAAaAaaAaAAaA -aaAaAAaAaaAaAAaAaaAaAAaA aaAaaAaAaaAaaAaA -aaAaAAaAaaAaAAaAaaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaAaaAaaAaAaaAaaAaAaaAaaAaA -abcabcabc abcabc -abcdcbaabcdcbaabcdcba aBcDCbAaBcDCbA -bbAbAAbAbbAbAAbAbbAbAAbA aa -efd2efd2efd2 efd2efd2 -kittenkittenkitten sitTingsitTing -İo İo İo İoİo -İoİoİo i̇oi̇o -İoİoİo İo İo -İoİoİo İoİo - - --- !query -select repeat(utf8_binary collate utf8_lcase, 3), repeat(utf8_lcase collate utf8_binary, 2) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day.Hello, world! Nice day.Hello, world! Nice day. Hello, world! Nice day.Hello, world! Nice day. -Something else. Nothing here.Something else. Nothing here.Something else. Nothing here. Something else. Nothing here.Something else. Nothing here. -SparkSparkSpark SQLSQL -aaAaAAaAaaAaAAaAaaAaAAaA aaAaAAaAaaAaAAaA -aaAaAAaAaaAaAAaAaaAaAAaA aaAaaAaAaaAaaAaA -aaAaAAaAaaAaAAaAaaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaAaaAaaAaAaaAaaAaAaaAaaAaA -abcabcabc abcabc -abcdcbaabcdcbaabcdcba aBcDCbAaBcDCbA -bbAbAAbAbbAbAAbAbbAbAAbA aa -efd2efd2efd2 efd2efd2 -kittenkittenkitten sitTingsitTing -İo İo İo İoİo -İoİoİo i̇oi̇o -İoİoİo İo İo -İoİoİo İoİo - - --- !query -select ascii(utf8_binary), ascii(utf8_lcase) from t5 --- !query schema -struct --- !query output -101 101 -107 115 -304 105 -304 304 -304 304 -304 304 -72 72 -83 83 -83 83 -97 97 -97 97 -97 97 -97 97 -97 97 -98 97 - - --- !query -select ascii(utf8_binary collate utf8_lcase), ascii(utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -101 101 -107 115 -304 105 -304 304 -304 304 -304 304 -72 72 -83 83 -83 83 -97 97 -97 97 -97 97 -97 97 -97 97 -98 97 - - --- !query -select unbase64(utf8_binary), unbase64(utf8_lcase) from t10 --- !query schema -struct --- !query output -i�� i�h� -y�v y�v - - --- !query -select unbase64(utf8_binary collate utf8_lcase), unbase64(utf8_lcase collate utf8_binary) from t10 --- !query schema -struct --- !query output -i�� i�h� -y�v y�v - - --- !query -select chr(ascii) from t6 --- !query schema -struct --- !query output -B -a - - --- !query -select base64(utf8_binary), base64(utf8_lcase) from t5 --- !query schema -struct --- !query output -SGVsbG8sIHdvcmxkISBOaWNlIGRheS4= SGVsbG8sIHdvcmxkISBOaWNlIGRheS4= -U29tZXRoaW5nIGVsc2UuIE5vdGhpbmcgaGVyZS4= U29tZXRoaW5nIGVsc2UuIE5vdGhpbmcgaGVyZS4= -U3Bhcms= U1FM -YWFBYUFBYUE= YWFBYUFBYUE= -YWFBYUFBYUE= YWFBYWFBYUE= -YWFBYUFBYUE= YWFBYWFBYUFhYUFhYUFhQWFhQWFhQWFB -YWJj YWJj -YWJjZGNiYQ== YUJjRENiQQ== -YmJBYkFBYkE= YQ== -ZWZkMg== ZWZkMg== -a2l0dGVu c2l0VGluZw== -xLBv acyHbw== -xLBv xLBv -xLBv xLBvIA== -xLBvIA== xLBv - - --- !query -select base64(utf8_binary collate utf8_lcase), base64(utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -SGVsbG8sIHdvcmxkISBOaWNlIGRheS4= SGVsbG8sIHdvcmxkISBOaWNlIGRheS4= -U29tZXRoaW5nIGVsc2UuIE5vdGhpbmcgaGVyZS4= U29tZXRoaW5nIGVsc2UuIE5vdGhpbmcgaGVyZS4= -U3Bhcms= U1FM -YWFBYUFBYUE= YWFBYUFBYUE= -YWFBYUFBYUE= YWFBYWFBYUE= -YWFBYUFBYUE= YWFBYWFBYUFhYUFhYUFhQWFhQWFhQWFB -YWJj YWJj -YWJjZGNiYQ== YUJjRENiQQ== -YmJBYkFBYkE= YQ== -ZWZkMg== ZWZkMg== -a2l0dGVu c2l0VGluZw== -xLBv acyHbw== -xLBv xLBv -xLBv xLBvIA== -xLBvIA== xLBv - - --- !query -select decode(encode(utf8_binary, 'utf-8'), 'utf-8'), decode(encode(utf8_lcase, 'utf-8'), 'utf-8') from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select decode(encode(utf8_binary collate utf8_lcase, 'utf-8'), 'utf-8'), decode(encode(utf8_lcase collate utf8_binary, 'utf-8'), 'utf-8') from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select format_number(ascii, '###.###') from t7 --- !query schema -struct --- !query output -66.421 -97.521 - - --- !query -select format_number(ascii, '###.###' collate utf8_lcase) from t7 --- !query schema -struct --- !query output -66.421 -97.521 - - --- !query -select encode(utf8_binary, 'utf-8'), encode(utf8_lcase, 'utf-8') from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select encode(utf8_binary collate utf8_lcase, 'utf-8'), encode(utf8_lcase collate utf8_binary, 'utf-8') from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select to_binary(utf8_binary, 'utf-8'), to_binary(utf8_lcase, 'utf-8') from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select to_binary(utf8_binary collate utf8_lcase, 'utf-8'), to_binary(utf8_lcase collate utf8_binary, 'utf-8') from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select sentences(utf8_binary), sentences(utf8_lcase) from t5 --- !query schema -struct>,sentences(utf8_lcase, , ):array>> --- !query output -[["Hello","world"],["Nice","day"]] [["Hello","world"],["Nice","day"]] -[["Something","else"],["Nothing","here"]] [["Something","else"],["Nothing","here"]] -[["Spark"]] [["SQL"]] -[["aaAaAAaA"]] [["aaAaAAaA"]] -[["aaAaAAaA"]] [["aaAaaAaA"]] -[["aaAaAAaA"]] [["aaAaaAaAaaAaaAaAaaAaaAaA"]] -[["abc"]] [["abc"]] -[["abcdcba"]] [["aBcDCbA"]] -[["bbAbAAbA"]] [["a"]] -[["efd2"]] [["efd2"]] -[["kitten"]] [["sitTing"]] -[["İo"]] [["i̇o"]] -[["İo"]] [["İo"]] -[["İo"]] [["İo"]] -[["İo"]] [["İo"]] - - --- !query -select sentences(utf8_binary collate utf8_lcase), sentences(utf8_lcase collate utf8_binary) from t5 --- !query schema -struct>,sentences(collate(utf8_lcase, utf8_binary), , ):array>> --- !query output -[["Hello","world"],["Nice","day"]] [["Hello","world"],["Nice","day"]] -[["Something","else"],["Nothing","here"]] [["Something","else"],["Nothing","here"]] -[["Spark"]] [["SQL"]] -[["aaAaAAaA"]] [["aaAaAAaA"]] -[["aaAaAAaA"]] [["aaAaaAaA"]] -[["aaAaAAaA"]] [["aaAaaAaAaaAaaAaAaaAaaAaA"]] -[["abc"]] [["abc"]] -[["abcdcba"]] [["aBcDCbA"]] -[["bbAbAAbA"]] [["a"]] -[["efd2"]] [["efd2"]] -[["kitten"]] [["sitTing"]] -[["İo"]] [["i̇o"]] -[["İo"]] [["İo"]] -[["İo"]] [["İo"]] -[["İo"]] [["İo"]] - - --- !query -select upper(utf8_binary), upper(utf8_lcase) from t5 --- !query schema -struct --- !query output -AAAAAAAA AAAAAAAA -AAAAAAAA AAAAAAAA -AAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAA -ABC ABC -ABCDCBA ABCDCBA -BBABAABA A -EFD2 EFD2 -HELLO, WORLD! NICE DAY. HELLO, WORLD! NICE DAY. -KITTEN SITTING -SOMETHING ELSE. NOTHING HERE. SOMETHING ELSE. NOTHING HERE. -SPARK SQL -İO İO -İO İO -İO İO -İO İO - - --- !query -select upper(utf8_binary collate utf8_lcase), upper(utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -AAAAAAAA AAAAAAAA -AAAAAAAA AAAAAAAA -AAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAA -ABC ABC -ABCDCBA ABCDCBA -BBABAABA A -EFD2 EFD2 -HELLO, WORLD! NICE DAY. HELLO, WORLD! NICE DAY. -KITTEN SITTING -SOMETHING ELSE. NOTHING HERE. SOMETHING ELSE. NOTHING HERE. -SPARK SQL -İO İO -İO İO -İO İO -İO İO - - --- !query -select lower(utf8_binary), lower(utf8_lcase) from t5 --- !query schema -struct --- !query output -aaaaaaaa aaaaaaaa -aaaaaaaa aaaaaaaa -aaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaa -abc abc -abcdcba abcdcba -bbabaaba a -efd2 efd2 -hello, world! nice day. hello, world! nice day. -i̇o i̇o -i̇o i̇o -i̇o i̇o -i̇o i̇o -kitten sitting -something else. nothing here. something else. nothing here. -spark sql - - --- !query -select lower(utf8_binary collate utf8_lcase), lower(utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -aaaaaaaa aaaaaaaa -aaaaaaaa aaaaaaaa -aaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaa -abc abc -abcdcba abcdcba -bbabaaba a -efd2 efd2 -hello, world! nice day. hello, world! nice day. -i̇o i̇o -i̇o i̇o -i̇o i̇o -i̇o i̇o -kitten sitting -something else. nothing here. something else. nothing here. -spark sql - - --- !query -select initcap(utf8_binary), initcap(utf8_lcase) from t5 --- !query schema -struct --- !query output -Aaaaaaaa Aaaaaaaa -Aaaaaaaa Aaaaaaaa -Aaaaaaaa Aaaaaaaaaaaaaaaaaaaaaaaa -Abc Abc -Abcdcba Abcdcba -Bbabaaba A -Efd2 Efd2 -Hello, World! Nice Day. Hello, World! Nice Day. -Kitten Sitting -Something Else. Nothing Here. Something Else. Nothing Here. -Spark Sql -İo İo -İo İo -İo İo -İo İo - - --- !query -select initcap(utf8_binary collate utf8_lcase), initcap(utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -Aaaaaaaa Aaaaaaaa -Aaaaaaaa Aaaaaaaa -Aaaaaaaa Aaaaaaaaaaaaaaaaaaaaaaaa -Abc Abc -Abcdcba Abcdcba -Bbabaaba A -Efd2 Efd2 -Hello, World! Nice Day. Hello, World! Nice Day. -Kitten Sitting -Something Else. Nothing Here. Something Else. Nothing Here. -Spark Sql -İo İo -İo İo -İo İo -İo İo - - --- !query -select overlay(utf8_binary, utf8_lcase, 2) from t5 --- !query schema -struct --- !query output -HHello, world! Nice day. -SSQLk -SSomething else. Nothing here. -aaBcDCbA -aaaAaAAaA -aaaAaaAaA -aaaAaaAaAaaAaaAaAaaAaaAaA -aabc -baAbAAbA -eefd2 -ksitTing -İi̇o -İİo -İİo -İİo - - --- !query -select overlay(s, utf8_binary,1) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. -Something else. Nothing here. -Spark -aaAaAAaA -aaAaAAaA -aaAaAAaA -abc -abcdcba -bbAbAAbA -efd2 -kitten -İo -İo -İo -İo - - --- !query -select overlay(utf8_binary collate utf8_binary, s collate utf8_lcase, 3) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" - } -} - - --- !query -select overlay(utf8_binary, utf8_lcase collate utf8_binary, 2) from t5 --- !query schema -struct --- !query output -HHello, world! Nice day. -SSQLk -SSomething else. Nothing here. -aaBcDCbA -aaaAaAAaA -aaaAaaAaA -aaaAaaAaAaaAaaAaAaaAaaAaA -aabc -baAbAAbA -eefd2 -ksitTing -İi̇o -İİo -İİo -İİo - - --- !query -select overlay(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase, 2) from t5 --- !query schema -struct --- !query output -HHello, world! Nice day. -SSQLk -SSomething else. Nothing here. -aaBcDCbA -aaaAaAAaA -aaaAaaAaA -aaaAaaAaAaaAaaAaAaaAaaAaA -aabc -baAbAAbA -eefd2 -ksitTing -İi̇o -İİo -İİo -İİo - - --- !query -select overlay(utf8_binary, 'a', 2), overlay(utf8_lcase, 'a', 2) from t5 --- !query schema -struct --- !query output -Hallo, world! Nice day. Hallo, world! Nice day. -Saark SaL -Samething else. Nothing here. Samething else. Nothing here. -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA -aac aac -aacdcba aacDCbA -baAbAAbA aa -ead2 ead2 -katten satTing -İa iao -İa İa -İa İa -İa İa - - --- !query -select overlay(utf8_binary, 'AaAA' collate utf8_lcase, 2), overlay(utf8_lcase, 'AAa' collate utf8_binary, 2) from t5 --- !query schema -struct --- !query output -HAaAA, world! Nice day. HAAao, world! Nice day. -SAaAA SAAa -SAaAAhing else. Nothing here. SAAathing else. Nothing here. -aAaAA aAAa -aAaAAAaA aAAaAAaA -aAaAAAaA aAAaaAaA -aAaAAAaA aAAaaAaAaaAaaAaAaaAaaAaA -aAaAAba aAAaCbA -bAaAAAbA aAAa -eAaAA eAAa -kAaAAn sAAaing -İAaAA iAAa -İAaAA İAAa -İAaAA İAAa -İAaAA İAAa - - --- !query -select format_string(format, utf8_binary, utf8_lcase) from t8 --- !query schema -struct --- !query output -abCdEabCdE - - --- !query -select format_string(format collate utf8_lcase, utf8_lcase, utf8_binary collate utf8_lcase, 3), format_string(format, utf8_lcase collate utf8_binary, utf8_binary) from t8 --- !query schema -struct --- !query output -abCdEabCdE abCdEabCdE - - --- !query -select format_string(format, utf8_binary, utf8_lcase) from t8 --- !query schema -struct --- !query output -abCdEabCdE - - --- !query -select soundex(utf8_binary), soundex(utf8_lcase) from t5 --- !query schema -struct --- !query output -A000 A000 -A000 A000 -A000 A000 -A120 A120 -A123 A123 -B110 A000 -E130 E130 -H464 H464 -K350 S352 -S162 S400 -S535 S535 -İo I000 -İo İo -İo İo -İo İo - - --- !query -select soundex(utf8_binary collate utf8_lcase), soundex(utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -A000 A000 -A000 A000 -A000 A000 -A120 A120 -A123 A123 -B110 A000 -E130 E130 -H464 H464 -K350 S352 -S162 S400 -S535 S535 -İo I000 -İo İo -İo İo -İo İo - - --- !query -select length(utf8_binary), length(utf8_lcase) from t5 --- !query schema -struct --- !query output -2 2 -2 3 -2 3 -23 23 -29 29 -3 2 -3 3 -4 4 -5 3 -6 7 -7 7 -8 1 -8 24 -8 8 -8 8 - - --- !query -select length(utf8_binary collate utf8_lcase), length(utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -2 2 -2 3 -2 3 -23 23 -29 29 -3 2 -3 3 -4 4 -5 3 -6 7 -7 7 -8 1 -8 24 -8 8 -8 8 - - --- !query -select bit_length(utf8_binary), bit_length(utf8_lcase) from t5 --- !query schema -struct --- !query output -184 184 -232 232 -24 24 -24 24 -24 32 -24 32 -32 24 -32 32 -40 24 -48 56 -56 56 -64 192 -64 64 -64 64 -64 8 - - --- !query -select bit_length(utf8_binary collate utf8_lcase), bit_length(utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -184 184 -232 232 -24 24 -24 24 -24 32 -24 32 -32 24 -32 32 -40 24 -48 56 -56 56 -64 192 -64 64 -64 64 -64 8 - - --- !query -select octet_length(utf8_binary), octet_length(utf8_lcase) from t5 --- !query schema -struct --- !query output -23 23 -29 29 -3 3 -3 3 -3 4 -3 4 -4 3 -4 4 -5 3 -6 7 -7 7 -8 1 -8 24 -8 8 -8 8 - - --- !query -select octet_length(utf8_binary collate utf8_lcase), octet_length(utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -23 23 -29 29 -3 3 -3 3 -3 4 -3 4 -4 3 -4 4 -5 3 -6 7 -7 7 -8 1 -8 24 -8 8 -8 8 - - --- !query -select octet_length(utf8_binary collate utf8_lcase_rtrim), octet_length(utf8_lcase collate utf8_binary_rtrim) from t5 --- !query schema -struct --- !query output -23 23 -29 29 -3 3 -3 3 -3 4 -3 4 -4 3 -4 4 -5 3 -6 7 -7 7 -8 1 -8 24 -8 8 -8 8 - - --- !query -select luhn_check(num) from t9 --- !query schema -struct --- !query output -false -false - - --- !query -select levenshtein(utf8_binary, utf8_lcase) from t5 --- !query schema -struct --- !query output -0 -0 -0 -0 -0 -0 -1 -1 -1 -16 -2 -4 -4 -4 -8 - - --- !query -select levenshtein(s, utf8_binary) from t5 --- !query schema -struct --- !query output -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -1 -1 - - --- !query -select levenshtein(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" - } -} - - --- !query -select levenshtein(utf8_binary, utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -0 -0 -0 -0 -0 -0 -1 -1 -1 -16 -2 -4 -4 -4 -8 - - --- !query -select levenshtein(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t5 --- !query schema -struct --- !query output -0 -0 -0 -0 -0 -0 -1 -1 -1 -16 -2 -4 -4 -4 -8 - - --- !query -select levenshtein(utf8_binary, 'a'), levenshtein(utf8_lcase, 'a') from t5 --- !query schema -struct --- !query output -2 2 -2 2 -2 3 -2 3 -22 22 -29 29 -3 2 -4 3 -4 4 -6 6 -6 7 -7 23 -7 7 -7 7 -8 0 - - --- !query -select levenshtein(utf8_binary, 'AaAA' collate utf8_lcase, 3), levenshtein(utf8_lcase, 'AAa' collate utf8_binary, 4) from t5 --- !query schema -struct --- !query output --1 -1 --1 -1 --1 -1 --1 -1 --1 -1 --1 -1 --1 -1 --1 2 --1 3 --1 3 --1 3 --1 3 --1 3 --1 4 -3 3 - - --- !query -select is_valid_utf8(utf8_binary), is_valid_utf8(utf8_lcase) from t5 --- !query schema -struct --- !query output -true true -true true -true true -true true -true true -true true -true true -true true -true true -true true -true true -true true -true true -true true -true true - - --- !query -select is_valid_utf8(utf8_binary collate utf8_lcase), is_valid_utf8(utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -true true -true true -true true -true true -true true -true true -true true -true true -true true -true true -true true -true true -true true -true true -true true - - --- !query -select is_valid_utf8(utf8_binary collate utf8_lcase_rtrim), is_valid_utf8(utf8_lcase collate utf8_binary_rtrim) from t5 --- !query schema -struct --- !query output -true true -true true -true true -true true -true true -true true -true true -true true -true true -true true -true true -true true -true true -true true -true true - - --- !query -select make_valid_utf8(utf8_binary), make_valid_utf8(utf8_lcase) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select make_valid_utf8(utf8_binary collate utf8_lcase), make_valid_utf8(utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select make_valid_utf8(utf8_binary collate utf8_lcase_rtrim), make_valid_utf8(utf8_lcase collate utf8_binary_rtrim) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select validate_utf8(utf8_binary), validate_utf8(utf8_lcase) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select validate_utf8(utf8_binary collate utf8_lcase), validate_utf8(utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select validate_utf8(utf8_binary collate utf8_lcase_rtrim), validate_utf8(utf8_lcase collate utf8_binary_rtrim) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select try_validate_utf8(utf8_binary), try_validate_utf8(utf8_lcase) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select try_validate_utf8(utf8_binary collate utf8_lcase), try_validate_utf8(utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select try_validate_utf8(utf8_binary collate utf8_lcase_rtrim), try_validate_utf8(utf8_lcase collate utf8_binary_rtrim) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -abcdcba aBcDCbA -bbAbAAbA a -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select substr(utf8_binary, 2, 2), substr(utf8_lcase, 2, 2) from t5 --- !query schema -struct --- !query output -aA aA -aA aA -aA aA -bA -bc Bc -bc bc -el el -fd fd -it it -o o -o o -o ̇o -o o -om om -pa QL - - --- !query -select substr(utf8_binary collate utf8_lcase, 2, 2), substr(utf8_lcase collate utf8_binary, 2, 2) from t5 --- !query schema -struct --- !query output -aA aA -aA aA -aA aA -bA -bc Bc -bc bc -el el -fd fd -it it -o o -o o -o ̇o -o o -om om -pa QL - - --- !query -select right(utf8_binary, 2), right(utf8_lcase, 2) from t5 --- !query schema -struct --- !query output -aA aA -aA aA -aA aA -bA a -ba bA -bc bc -d2 d2 -e. e. -en ng -o İo -rk QL -y. y. -İo o -İo İo -İo ̇o - - --- !query -select right(utf8_binary collate utf8_lcase, 2), right(utf8_lcase collate utf8_binary, 2) from t5 --- !query schema -struct --- !query output -aA aA -aA aA -aA aA -bA a -ba bA -bc bc -d2 d2 -e. e. -en ng -o İo -rk QL -y. y. -İo o -İo İo -İo ̇o - - --- !query -select left(utf8_binary, '2' collate utf8_lcase), left(utf8_lcase, 2) from t5 --- !query schema -struct --- !query output -He He -So So -Sp SQ -aa aa -aa aa -aa aa -ab aB -ab ab -bb a -ef ef -ki si -İo i̇ -İo İo -İo İo -İo İo - - --- !query -select left(utf8_binary collate utf8_lcase, 2), left(utf8_lcase collate utf8_binary, 2) from t5 --- !query schema -struct --- !query output -He He -So So -Sp SQ -aa aa -aa aa -aa aa -ab aB -ab ab -bb a -ef ef -ki si -İo i̇ -İo İo -İo İo -İo İo - - --- !query -select rpad(utf8_binary, 8, utf8_lcase) from t5 --- !query schema -struct --- !query output -Hello, w -Somethin -SparkSQL -aaAaAAaA -aaAaAAaA -aaAaAAaA -abcabcab -abcdcbaa -bbAbAAbA -efd2efd2 -kittensi -İo İoİoİ -İoi̇oi̇o -İoİo İo -İoİoİoİo - - --- !query -select rpad(s, 8, utf8_binary) from t5 --- !query schema -struct --- !query output -Hello, w -Somethin -SparkSpa -aaAaAAaA -aaAaAAaA -aaAaAAaA -abcabcab -abcdcbaa -bbAbaAbA -efd2efd2 -kittenki -İoİo İo -İoİoİoİo -İoİoİoİo -İoİoİoİo - - --- !query -select rpad(utf8_binary collate utf8_binary, 8, s collate utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" - } -} - - --- !query -select rpad(utf8_binary, 8, utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -Hello, w -Somethin -SparkSQL -aaAaAAaA -aaAaAAaA -aaAaAAaA -abcabcab -abcdcbaa -bbAbAAbA -efd2efd2 -kittensi -İo İoİoİ -İoi̇oi̇o -İoİo İo -İoİoİoİo - - --- !query -select rpad(utf8_binary collate utf8_lcase, 8, utf8_lcase collate utf8_lcase) from t5 --- !query schema -struct --- !query output -Hello, w -Somethin -SparkSQL -aaAaAAaA -aaAaAAaA -aaAaAAaA -abcabcab -abcdcbaa -bbAbAAbA -efd2efd2 -kittensi -İo İoİoİ -İoi̇oi̇o -İoİo İo -İoİoİoİo - - --- !query -select lpad(utf8_binary collate utf8_binary_rtrim, 8, utf8_lcase collate utf8_binary_rtrim) from t5 --- !query schema -struct --- !query output -Hello, w -SQLSpark -Somethin -aaAaAAaA -aaAaAAaA -aaAaAAaA -aabcdcba -abcababc -bbAbAAbA -efd2efd2 -i̇oi̇oİo -sikitten -İo İo İo -İoİoİoİo -İoİoİİo - - --- !query -select rpad(utf8_binary, 8, 'a'), rpad(utf8_lcase, 8, 'a') from t5 --- !query schema -struct --- !query output -Hello, w Hello, w -Somethin Somethin -Sparkaaa SQLaaaaa -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaA -abcaaaaa abcaaaaa -abcdcbaa aBcDCbAa -bbAbAAbA aaaaaaaa -efd2aaaa efd2aaaa -kittenaa sitTinga -İo aaaaa İoaaaaaa -İoaaaaaa i̇oaaaaa -İoaaaaaa İo aaaaa -İoaaaaaa İoaaaaaa - - --- !query -select rpad(utf8_binary, 8, 'AaAA' collate utf8_lcase), rpad(utf8_lcase, 8, 'AAa' collate utf8_binary) from t5 --- !query schema -struct --- !query output -Hello, w Hello, w -Somethin Somethin -SparkAaA SQLAAaAA -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaA -abcAaAAA abcAAaAA -abcdcbaA aBcDCbAA -bbAbAAbA aAAaAAaA -efd2AaAA efd2AAaA -kittenAa sitTingA -İo AaAAA İoAAaAAa -İoAaAAAa i̇oAAaAA -İoAaAAAa İo AAaAA -İoAaAAAa İoAAaAAa - - --- !query -select lpad(utf8_binary, 8, utf8_lcase) from t5 --- !query schema -struct --- !query output -Hello, w -SQLSpark -Somethin -aaAaAAaA -aaAaAAaA -aaAaAAaA -aabcdcba -abcababc -bbAbAAbA -efd2efd2 -i̇oi̇oİo -sikitten -İo İo İo -İoİoİoİo -İoİoİİo - - --- !query -select lpad(s, 8, utf8_binary) from t5 --- !query schema -struct --- !query output -Hello, w -Somethin -SpaSpark -aaAaAAaA -aaAaAAaA -aaAaAAaA -aabcdcba -abcababc -bbAbaAbA -efd2efd2 -kikitten -İo İo İo -İoİoİoİo -İoİoİoİo -İoİoİoİo - - --- !query -select lpad(utf8_binary collate utf8_binary, 8, s collate utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" - } -} - - --- !query -select lpad(utf8_binary, 8, utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -Hello, w -SQLSpark -Somethin -aaAaAAaA -aaAaAAaA -aaAaAAaA -aabcdcba -abcababc -bbAbAAbA -efd2efd2 -i̇oi̇oİo -sikitten -İo İo İo -İoİoİoİo -İoİoİİo - - --- !query -select lpad(utf8_binary collate utf8_lcase, 8, utf8_lcase collate utf8_lcase) from t5 --- !query schema -struct --- !query output -Hello, w -SQLSpark -Somethin -aaAaAAaA -aaAaAAaA -aaAaAAaA -aabcdcba -abcababc -bbAbAAbA -efd2efd2 -i̇oi̇oİo -sikitten -İo İo İo -İoİoİoİo -İoİoİİo - - --- !query -select lpad(utf8_binary collate utf8_binary_rtrim, 8, utf8_lcase collate utf8_binary_rtrim) from t5 --- !query schema -struct --- !query output -Hello, w -SQLSpark -Somethin -aaAaAAaA -aaAaAAaA -aaAaAAaA -aabcdcba -abcababc -bbAbAAbA -efd2efd2 -i̇oi̇oİo -sikitten -İo İo İo -İoİoİoİo -İoİoİİo - - --- !query -select lpad(utf8_binary, 8, 'a'), lpad(utf8_lcase, 8, 'a') from t5 --- !query schema -struct --- !query output -Hello, w Hello, w -Somethin Somethin -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaA -aaaSpark aaaaaSQL -aaaaaabc aaaaaabc -aaaaaaİo aaaaaaİo -aaaaaaİo aaaaai̇o -aaaaaaİo aaaaaİo -aaaaaİo aaaaaaİo -aaaaefd2 aaaaefd2 -aabcdcba aaBcDCbA -aakitten asitTing -bbAbAAbA aaaaaaaa - - --- !query -select lpad(utf8_binary, 8, 'AaAA' collate utf8_lcase), lpad(utf8_lcase, 8, 'AAa' collate utf8_binary) from t5 --- !query schema -struct --- !query output -AaAAAabc AAaAAabc -AaAAAaİo AAaAAaİo -AaAAAaİo AAaAAi̇o -AaAAAaİo AAaAAİo -AaAAAİo AAaAAaİo -AaAAefd2 AAaAefd2 -AaASpark AAaAASQL -Aabcdcba AaBcDCbA -Aakitten AsitTing -Hello, w Hello, w -Somethin Somethin -aaAaAAaA aaAaAAaA -aaAaAAaA aaAaaAaA -aaAaAAaA aaAaaAaA -bbAbAAbA AAaAAaAa - - --- !query -select locate(utf8_binary, utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", - "sqlState" : "42P22", - "messageParameters" : { - "expr" : "\"locate(utf8_binary, utf8_lcase, 1)\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 38, - "fragment" : "locate(utf8_binary, utf8_lcase)" - } ] -} - - --- !query -select locate(s, utf8_binary) from t5 --- !query schema -struct --- !query output -0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 - - --- !query -select locate(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" - } -} - - --- !query -select locate(utf8_binary, utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output -0 -0 -0 -0 -0 -0 -0 -0 -1 -1 -1 -1 -1 -1 -1 - - --- !query -select locate(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase, 3) from t5 --- !query schema -struct --- !query output -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -3 - - --- !query -select locate(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 3) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", - "sqlState" : "42K09", - "messageParameters" : { - "inputSql" : "\"collate(utf8_binary, unicode_ai)\"", - "inputType" : "\"STRING COLLATE UNICODE_AI\"", - "paramIndex" : "first", - "requiredType" : "\"STRING\"", - "sqlExpr" : "\"locate(collate(utf8_binary, unicode_ai), collate(utf8_lcase, unicode_ai), 3)\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 79, - "fragment" : "locate(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai, 3)" - } ] -} - - --- !query -select locate(utf8_binary, 'a'), locate(utf8_lcase, 'a') from t5 --- !query schema -struct --- !query output -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 1 - - --- !query -select locate(utf8_binary, 'AaAA' collate utf8_lcase, 4), locate(utf8_lcase, 'AAa' collate utf8_binary, 4) from t5 --- !query schema -struct --- !query output -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 - - --- !query -select locate(utf8_binary, 'AaAA ' collate utf8_binary_rtrim, 4), locate(utf8_lcase, 'AAa ' collate utf8_binary, 4) from t5 --- !query schema -struct --- !query output -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 -0 0 - - --- !query -select TRIM(utf8_binary, utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", - "sqlState" : "42P22", - "messageParameters" : { - "expr" : "\"TRIM(BOTH utf8_binary FROM utf8_lcase)\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 36, - "fragment" : "TRIM(utf8_binary, utf8_lcase)" - } ] -} - - --- !query -select TRIM(s, utf8_binary) from t5 --- !query schema -struct --- !query output - - - --- !query -select TRIM(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING COLLATE UTF8_LCASE\", \"STRING\"" - } -} - - --- !query -select TRIM(utf8_binary, utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output - - - - - - - - - - -BcDCbA -QL -a -i̇ -sitTing - - --- !query -select TRIM(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t5 --- !query schema -struct --- !query output - - - - - - - - - - - - - -QL -sitTing - - --- !query -select TRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", - "sqlState" : "42K09", - "messageParameters" : { - "inputSql" : "\"collate(utf8_lcase, unicode_ai)\"", - "inputType" : "\"STRING COLLATE UNICODE_AI\"", - "paramIndex" : "first", - "requiredType" : "\"STRING\"", - "sqlExpr" : "\"TRIM(BOTH collate(utf8_binary, unicode_ai) FROM collate(utf8_lcase, unicode_ai))\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 74, - "fragment" : "TRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai)" - } ] -} - - --- !query -select TRIM(utf8_binary collate utf8_binary_rtrim, utf8_lcase collate utf8_binary_rtrim) from t5 --- !query schema -struct --- !query output - - - - - - - - - - -BcDCbA -QL -a -i̇ -sitTing - - --- !query -select TRIM('ABc', utf8_binary), TRIM('ABc', utf8_lcase) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAa -aaAaAAa -aaAaAAa -ab -abcdcba D -bbAbAAb -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select TRIM('ABc' collate utf8_lcase, utf8_binary), TRIM('AAa' collate utf8_binary, utf8_lcase) from t5 --- !query schema -struct --- !query output - - - - - bc -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -d BcDCb -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select BTRIM(utf8_binary, utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", - "sqlState" : "42P22", - "messageParameters" : { - "expr" : "\"TRIM(BOTH utf8_lcase FROM utf8_binary)\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 37, - "fragment" : "BTRIM(utf8_binary, utf8_lcase)" - } ] -} - - --- !query -select BTRIM(s, utf8_binary) from t5 --- !query schema -struct --- !query output - - - - - - - - - - - - - - -a - - --- !query -select BTRIM(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING\", \"STRING COLLATE UTF8_LCASE\"" - } -} - - --- !query -select BTRIM(utf8_binary, utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output - - - - - - - - - - -bbAbAAbA -d -kitte -park -İ - - --- !query -select BTRIM(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t5 --- !query schema -struct --- !query output - - - - - - - - - - - -bbAbAAb -kitte -park -İ - - --- !query -select BTRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", - "sqlState" : "42K09", - "messageParameters" : { - "inputSql" : "\"collate(utf8_binary, unicode_ai)\"", - "inputType" : "\"STRING COLLATE UNICODE_AI\"", - "paramIndex" : "first", - "requiredType" : "\"STRING\"", - "sqlExpr" : "\"TRIM(BOTH collate(utf8_lcase, unicode_ai) FROM collate(utf8_binary, unicode_ai))\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 75, - "fragment" : "BTRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai)" - } ] -} - - --- !query -select BTRIM(utf8_binary collate utf8_binary_rtrim, utf8_lcase collate utf8_binary_rtrim) from t5 --- !query schema -struct --- !query output - - - - - - - - - - -bbAbAAbA -d -kitte -park -İ - - --- !query -select BTRIM('ABc', utf8_binary), BTRIM('ABc', utf8_lcase) from t5 --- !query schema -struct --- !query output -AB -AB -AB B -ABc ABc -ABc ABc -ABc ABc -ABc ABc -ABc ABc -ABc ABc -ABc ABc -ABc ABc -Bc Bc -Bc Bc -Bc Bc -Bc Bc - - --- !query -select BTRIM('ABc' collate utf8_lcase, utf8_binary), BTRIM('AAa' collate utf8_binary, utf8_lcase) from t5 --- !query schema -struct --- !query output - - AA -ABc AAa -ABc AAa -ABc AAa -ABc AAa -ABc AAa -ABc AAa -ABc AAa -B AA -Bc -Bc -Bc -Bc AAa -c AA - - --- !query -select LTRIM(utf8_binary, utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", - "sqlState" : "42P22", - "messageParameters" : { - "expr" : "\"TRIM(LEADING utf8_binary FROM utf8_lcase)\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 37, - "fragment" : "LTRIM(utf8_binary, utf8_lcase)" - } ] -} - - --- !query -select LTRIM(s, utf8_binary) from t5 --- !query schema -struct --- !query output - - - --- !query -select LTRIM(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING COLLATE UTF8_LCASE\", \"STRING\"" - } -} - - --- !query -select LTRIM(utf8_binary, utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output - - - - - - - - - - -BcDCbA -QL -a -i̇o -sitTing - - --- !query -select LTRIM(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t5 --- !query schema -struct --- !query output - - - - - - - - - - - - - -QL -sitTing - - --- !query -select LTRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", - "sqlState" : "42K09", - "messageParameters" : { - "inputSql" : "\"collate(utf8_lcase, unicode_ai)\"", - "inputType" : "\"STRING COLLATE UNICODE_AI\"", - "paramIndex" : "first", - "requiredType" : "\"STRING\"", - "sqlExpr" : "\"TRIM(LEADING collate(utf8_binary, unicode_ai) FROM collate(utf8_lcase, unicode_ai))\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 75, - "fragment" : "LTRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai)" - } ] -} - - --- !query -select LTRIM(utf8_binary collate utf8_binary_rtrim, utf8_lcase collate utf8_binary_rtrim) from t5 --- !query schema -struct --- !query output - - - - - - - - - - -BcDCbA -QL -a -i̇o -sitTing - - --- !query -select LTRIM('ABc', utf8_binary), LTRIM('ABc', utf8_lcase) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAaA -aaAaAAaA -aaAaAAaA -abc -abcdcba DCbA -bbAbAAbA -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select LTRIM('ABc' collate utf8_lcase, utf8_binary), LTRIM('AAa' collate utf8_binary, utf8_lcase) from t5 --- !query schema -struct --- !query output - - - - - bc -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -dcba BcDCbA -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select RTRIM(utf8_binary, utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "INDETERMINATE_COLLATION_IN_EXPRESSION", - "sqlState" : "42P22", - "messageParameters" : { - "expr" : "\"TRIM(TRAILING utf8_binary FROM utf8_lcase)\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 37, - "fragment" : "RTRIM(utf8_binary, utf8_lcase)" - } ] -} - - --- !query -select RTRIM(s, utf8_binary) from t5 --- !query schema -struct --- !query output - - - - - - - - - - - - - - -İo - - --- !query -select RTRIM(utf8_binary collate utf8_binary, s collate utf8_lcase) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "COLLATION_MISMATCH.EXPLICIT", - "sqlState" : "42P21", - "messageParameters" : { - "explicitTypes" : "\"STRING COLLATE UTF8_LCASE\", \"STRING\"" - } -} - - --- !query -select RTRIM(utf8_binary, utf8_lcase collate utf8_binary) from t5 --- !query schema -struct --- !query output - - - - - - - - - -SQL -a -aBcDCbA -i̇ -sitTing -İo - - --- !query -select RTRIM(utf8_binary collate utf8_lcase, utf8_lcase collate utf8_lcase) from t5 --- !query schema -struct --- !query output - - - - - - - - - - - - -SQL -sitTing -İo - - --- !query -select RTRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai) from t5 --- !query schema -struct<> --- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", - "sqlState" : "42K09", - "messageParameters" : { - "inputSql" : "\"collate(utf8_lcase, unicode_ai)\"", - "inputType" : "\"STRING COLLATE UNICODE_AI\"", - "paramIndex" : "first", - "requiredType" : "\"STRING\"", - "sqlExpr" : "\"TRIM(TRAILING collate(utf8_binary, unicode_ai) FROM collate(utf8_lcase, unicode_ai))\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 75, - "fragment" : "RTRIM(utf8_binary collate unicode_ai, utf8_lcase collate unicode_ai)" - } ] -} - - --- !query -select RTRIM(utf8_binary collate utf8_binary_rtrim, utf8_lcase collate utf8_binary_rtrim) from t5 --- !query schema -struct --- !query output - - - - - - - - - - -SQL -a -aBcDCbA -i̇ -sitTing - - --- !query -select RTRIM('ABc', utf8_binary), RTRIM('ABc', utf8_lcase) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -aaAaAAa -aaAaAAa -aaAaAAa -ab -abcdcba aBcD -bbAbAAb -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select RTRIM('ABc' collate utf8_lcase, utf8_binary), RTRIM('AAa' collate utf8_binary, utf8_lcase) from t5 --- !query schema -struct --- !query output - - - - - abc -Hello, world! Nice day. Hello, world! Nice day. -Something else. Nothing here. Something else. Nothing here. -Spark SQL -abcd aBcDCb -efd2 efd2 -kitten sitTing -İo i̇o -İo İo -İo İo -İo İo - - --- !query -select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -SQL SQL -Something else. Nothing here. Something else. Nothing here. -a a -aBcDCbA aBcDCbA -aaAaAAaA aaAaAAaA -aaAaaAaA aaAaaAaA -aaAaaAaAaaAaaAaAaaAaaAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -efd2 efd2 -i̇o i̇o -sitTing sitTing -İo İo -İo İo -İo İo - - --- !query -select `concat_ws(' ' collate UTF8_LCASE, utf8_lcase, utf8_lcase)` from ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 -) --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -SQL SQL -Something else. Nothing here. Something else. Nothing here. -a a -aBcDCbA aBcDCbA -aaAaAAaA aaAaAAaA -aaAaaAaA aaAaaAaA -aaAaaAaAaaAaaAaAaaAaaAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -efd2 efd2 -i̇o i̇o -sitTing sitTing -İo İo -İo İo -İo İo - - --- !query -select * from ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 -) --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -SQL SQL -Something else. Nothing here. Something else. Nothing here. -a a -aBcDCbA aBcDCbA -aaAaAAaA aaAaAAaA -aaAaaAaA aaAaaAaA -aaAaaAaAaaAaaAaAaaAaaAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -efd2 efd2 -i̇o i̇o -sitTing sitTing -İo İo -İo İo -İo İo - - --- !query -select subq1.* from ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 -) AS subq1 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -SQL SQL -Something else. Nothing here. Something else. Nothing here. -a a -aBcDCbA aBcDCbA -aaAaAAaA aaAaAAaA -aaAaaAaA aaAaaAaA -aaAaaAaAaaAaaAaAaaAaaAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -efd2 efd2 -i̇o i̇o -sitTing sitTing -İo İo -İo İo -İo İo - - --- !query -with cte as ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 -) -select * from cte --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -SQL SQL -Something else. Nothing here. Something else. Nothing here. -a a -aBcDCbA aBcDCbA -aaAaAAaA aaAaAAaA -aaAaaAaA aaAaaAaA -aaAaaAaAaaAaaAaAaaAaaAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -efd2 efd2 -i̇o i̇o -sitTing sitTing -İo İo -İo İo -İo İo - - --- !query -select * from values (1) where exists ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 -) --- !query schema -struct --- !query output -1 - - --- !query -select ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 limit 1 -) --- !query schema -struct --- !query output -Something else. Nothing here. Something else. Nothing here. - - --- !query -select ( - with cte as ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 - ) - select * from cte limit 1 -) --- !query schema -struct --- !query output -Something else. Nothing here. Something else. Nothing here. - - --- !query -select * from ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 limit 1 -) -where ( - `concat_ws(' ' collate UTF8_LCASE, utf8_lcase, utf8_lcase)` == 'aaa' -) --- !query schema -struct --- !query output - - - --- !query -select lower(`concat_ws(' ' collate UTF8_LCASE, utf8_lcase, utf8_lcase)`) from ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 - group by 1 - order by 1 -) --- !query schema -struct --- !query output -a a -aaaaaaaa aaaaaaaa -aaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaa -abc abc -abcdcba abcdcba -efd2 efd2 -hello, world! nice day. hello, world! nice day. -i̇o i̇o -i̇o i̇o -sitting sitting -something else. nothing here. something else. nothing here. -sql sql - - --- !query -select lower(`concat_ws(' ' collate UTF8_LCASE, utf8_lcase, utf8_lcase)`) from ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 - group by 1 - order by max(concat_ws(' ', utf8_lcase, utf8_lcase)) -) --- !query schema -struct --- !query output -a a -aaaaaaaa aaaaaaaa -aaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaa -abc abc -abcdcba abcdcba -efd2 efd2 -hello, world! nice day. hello, world! nice day. -i̇o i̇o -i̇o i̇o -sitting sitting -something else. nothing here. something else. nothing here. -sql sql - - --- !query -create temporary view v1 as ( - select concat_ws(' ', utf8_lcase, utf8_lcase) from t5 -) --- !query schema -struct<> --- !query output - - - --- !query -select * from v1 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -SQL SQL -Something else. Nothing here. Something else. Nothing here. -a a -aBcDCbA aBcDCbA -aaAaAAaA aaAaAAaA -aaAaaAaA aaAaaAaA -aaAaaAaAaaAaaAaAaaAaaAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -efd2 efd2 -i̇o i̇o -sitTing sitTing -İo İo -İo İo -İo İo - - --- !query -select `concat_ws(' ' collate UTF8_LCASE, utf8_lcase, utf8_lcase)` from v1 --- !query schema -struct --- !query output -Hello, world! Nice day. Hello, world! Nice day. -SQL SQL -Something else. Nothing here. Something else. Nothing here. -a a -aBcDCbA aBcDCbA -aaAaAAaA aaAaAAaA -aaAaaAaA aaAaaAaA -aaAaaAaAaaAaaAaAaaAaaAaA aaAaaAaAaaAaaAaAaaAaaAaA -abc abc -efd2 efd2 -i̇o i̇o -sitTing sitTing -İo İo -İo İo -İo İo - - --- !query -drop view v1 --- !query schema -struct<> --- !query output - - - --- !query -drop table t5 --- !query schema -struct<> --- !query output - - - --- !query -drop table t6 --- !query schema -struct<> --- !query output - - - --- !query -drop table t7 --- !query schema -struct<> --- !query output - - - --- !query -drop table t8 --- !query schema -struct<> --- !query output - - - --- !query -drop table t9 --- !query schema -struct<> --- !query output - - - --- !query -drop table t10 --- !query schema -struct<> --- !query output - diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/csv-functions.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/csv-functions.sql.out index 19b24cc1201..d4aa14c48f4 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/csv-functions.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/csv-functions.sql.out @@ -188,6 +188,32 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException } +-- !query +select schema_of_csv(42) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"42\"", + "inputType" : "\"INT\"", + "paramIndex" : "first", + "requiredType" : "\"STRING\"", + "sqlExpr" : "\"schema_of_csv(42)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 24, + "fragment" : "schema_of_csv(42)" + } ] +} + + -- !query CREATE TEMPORARY VIEW csvTable(csvField, a) AS SELECT * FROM VALUES ('1,abc', 'a') -- !query schema diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/cte-recursion.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/cte-recursion.sql.out new file mode 100644 index 00000000000..536fc6c4ea6 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/cte-recursion.sql.out @@ -0,0 +1,2245 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +WITH r(level) AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r WHERE level < 9 +) +SELECT * FROM r +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "TABLE_OR_VIEW_NOT_FOUND", + "sqlState" : "42P01", + "messageParameters" : { + "relationName" : "`r`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 67, + "stopIndex" : 67, + "fragment" : "r" + } ] +} + + +-- !query +WITH RECURSIVE r AS ( + SELECT 0 AS level + UNION ALL + SELECT level + 1 FROM r WHERE level < 9 +) +SELECT * FROM r +-- !query schema +struct +-- !query output +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 + + +-- !query +WITH RECURSIVE r(level) AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r WHERE level < 9 +) +SELECT * FROM r +-- !query schema +struct +-- !query output +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 + + +-- !query +WITH RECURSIVE r(c) AS ( + SELECT 'a' + UNION ALL + SELECT c || char(ascii(substr(c, -1)) + 1) FROM r WHERE LENGTH(c) < 10 +) +SELECT * FROM r +-- !query schema +struct +-- !query output +a +ab +abc +abcd +abcde +abcdef +abcdefg +abcdefgh +abcdefghi +abcdefghij + + +-- !query +WITH RECURSIVE r(level) AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r +) +SELECT * FROM r +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkException +{ + "errorClass" : "RECURSION_LEVEL_LIMIT_EXCEEDED", + "sqlState" : "42836", + "messageParameters" : { + "levelLimit" : "25" + } +} + + +-- !query +CREATE TEMPORARY VIEW ZeroAndOne(current, next) AS VALUES + (0,0), + (0,1), + (1,0), + (1,1) +-- !query schema +struct<> +-- !query output + + + +-- !query +WITH RECURSIVE t(n) AS ( + SELECT 1 + UNION ALL + SELECT next FROM t LEFT JOIN ZeroAndOne ON n = current +) +SELECT * FROM t +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkException +{ + "errorClass" : "RECURSION_ROW_LIMIT_EXCEEDED", + "sqlState" : "42836", + "messageParameters" : { + "rowLimit" : "50" + } +} + + +-- !query +DROP VIEW ZeroAndOne +-- !query schema +struct<> +-- !query output + + + +-- !query +WITH RECURSIVE r(level) MAX RECURSION LEVEL 35 AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r WHERE level < 30 + ) +SELECT * FROM r +-- !query schema +struct +-- !query output +0 +1 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +2 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +3 +30 +4 +5 +6 +7 +8 +9 + + +-- !query +WITH r(level) MAX RECURSION LEVEL 35 AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r WHERE level < 30 +) +SELECT * FROM r +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "_LEGACY_ERROR_TEMP_0035", + "messageParameters" : { + "message" : "Cannot specify MAX RECURSION LEVEL when the CTE is not marked as RECURSIVE" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 125, + "fragment" : "WITH r(level) MAX RECURSION LEVEL 35 AS (\n VALUES 0\n UNION ALL\n SELECT level + 1 FROM r WHERE level < 30\n)\nSELECT * FROM r" + } ] +} + + +-- !query +WITH RECURSIVE r(level) AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r WHERE level < 150 +) +SELECT * FROM r +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkException +{ + "errorClass" : "RECURSION_LEVEL_LIMIT_EXCEEDED", + "sqlState" : "42836", + "messageParameters" : { + "levelLimit" : "25" + } +} + + +-- !query +CREATE TEMPORARY VIEW ZeroAndOne(current, next) AS VALUES + (0,0), + (0,1), + (1,0), + (1,1) +-- !query schema +struct<> +-- !query output + + + +-- !query +WITH RECURSIVE t(n) AS ( + SELECT 1 + UNION ALL + SELECT next FROM t LEFT JOIN ZeroAndOne ON n = current + ) +SELECT * FROM t LIMIT 60 +-- !query schema +struct +-- !query output +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + + +-- !query +DROP VIEW ZeroAndOne +-- !query schema +struct<> +-- !query output + + + +-- !query +WITH RECURSIVE t(n) MAX RECURSION LEVEL 100 AS ( + SELECT 1 + UNION ALL + SELECT n + 1 FROM t WHERE n < 60 + ) +SELECT * FROM t LIMIT ALL +-- !query schema +struct +-- !query output +1 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +2 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +3 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +4 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +5 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +6 +60 +7 +8 +9 + + +-- !query +WITH RECURSIVE t MAX RECURSION LEVEL 100 AS ( + SELECT 1 AS n + UNION ALL + SELECT n + 1 FROM t WHERE n < 60 + ) +SELECT * FROM t LIMIT ALL +-- !query schema +struct +-- !query output +1 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +2 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +3 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +4 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +5 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +6 +60 +7 +8 +9 + + +-- !query +WITH RECURSIVE t MAX RECURSION LEVEL 100 AS ( + SELECT 1 AS n + UNION ALL + SELECT n + 1 FROM t WHERE n < 60 + ) + (SELECT n FROM t LIMIT ALL) UNION ALL (SELECT n FROM t) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkException +{ + "errorClass" : "RECURSION_ROW_LIMIT_EXCEEDED", + "sqlState" : "42836", + "messageParameters" : { + "rowLimit" : "50" + } +} + + +-- !query +WITH RECURSIVE t MAX RECURSION LEVEL 100 AS ( + SELECT 1 AS n + UNION ALL + SELECT n + 1 FROM t WHERE n < 60 + ) + (SELECT n FROM t LIMIT ALL) UNION ALL (SELECT n FROM t LIMIT ALL) +-- !query schema +struct +-- !query output +1 +1 +10 +10 +11 +11 +12 +12 +13 +13 +14 +14 +15 +15 +16 +16 +17 +17 +18 +18 +19 +19 +2 +2 +20 +20 +21 +21 +22 +22 +23 +23 +24 +24 +25 +25 +26 +26 +27 +27 +28 +28 +29 +29 +3 +3 +30 +30 +31 +31 +32 +32 +33 +33 +34 +34 +35 +35 +36 +36 +37 +37 +38 +38 +39 +39 +4 +4 +40 +40 +41 +41 +42 +42 +43 +43 +44 +44 +45 +45 +46 +46 +47 +47 +48 +48 +49 +49 +5 +5 +50 +50 +51 +51 +52 +52 +53 +53 +54 +54 +55 +55 +56 +56 +57 +57 +58 +58 +59 +59 +6 +6 +60 +60 +7 +7 +8 +8 +9 +9 + + +-- !query +WITH RECURSIVE r(level) AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r +) +SELECT * FROM r LIMIT 10 +-- !query schema +struct +-- !query output +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 + + +-- !query +WITH RECURSIVE r AS ( + SELECT 0 as level + UNION + SELECT (level + 1) % 10 FROM r +) +SELECT * FROM r +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UNION_NOT_SUPPORTED_IN_RECURSIVE_CTE", + "sqlState" : "42836", + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 100, + "fragment" : "WITH RECURSIVE r AS (\n SELECT 0 as level\n UNION\n SELECT (level + 1) % 10 FROM r\n)\nSELECT * FROM r" + } ] +} + + +-- !query +WITH RECURSIVE r(level) AS ( + VALUES 0 + UNION + SELECT (level + 1) % 10 FROM r +) +SELECT * FROM r +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UNION_NOT_SUPPORTED_IN_RECURSIVE_CTE", + "sqlState" : "42836", + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 98, + "fragment" : "WITH RECURSIVE r(level) AS (\n VALUES 0\n UNION\n SELECT (level + 1) % 10 FROM r\n)\nSELECT * FROM r" + } ] +} + + +-- !query +WITH RECURSIVE r(level) AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r +) +SELECT level, level FROM r ORDER BY 1 LIMIT 10 +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkException +{ + "errorClass" : "RECURSION_LEVEL_LIMIT_EXCEEDED", + "sqlState" : "42836", + "messageParameters" : { + "levelLimit" : "25" + } +} + + +-- !query +WITH RECURSIVE r(level) AS ( + SELECT level + 1 FROM r WHERE level < 9 +) +SELECT * FROM r +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_CTE", + "sqlState" : "42836" +} + + +-- !query +WITH RECURSIVE r(level) AS ( + SELECT level + 1 FROM r WHERE level < 9 + UNION ALL + VALUES 0 +) +SELECT * FROM r +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_CTE", + "sqlState" : "42836" +} + + +-- !query +WITH RECURSIVE t(n) AS ( + SELECT 1 + UNION ALL + SELECT 2 +) +SELECT * FROM t +-- !query schema +struct +-- !query output +1 +2 + + +-- !query +WITH RECURSIVE r(level) AS ( + VALUES 0 + INTERSECT + SELECT level + 1 FROM r WHERE level < 9 +) +SELECT * FROM r +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_CTE", + "sqlState" : "42836" +} + + +-- !query +WITH RECURSIVE t(col) ( + SELECT 1 + UNION ALL + SELECT (SELECT max(col) FROM t) +) +SELECT * FROM t LIMIT 5 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_REFERENCE.PLACE", + "sqlState" : "42836" +} + + +-- !query +WITH + t1 AS (SELECT 1 as n), + t2(n) AS ( + WITH RECURSIVE t3(n) AS ( + SELECT 1 + UNION ALL + SELECT n+1 FROM (SELECT MAX(n) FROM t3) + ) + SELECT * FROM t3 + ) +SELECT * FROM t2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_REFERENCE.PLACE", + "sqlState" : "42836" +} + + +-- !query +WITH RECURSIVE t1(n) AS ( + SELECT 1 + UNION ALL + SELECT (SELECT n+1 FROM t1 WHERE n<5) +) +SELECT * FROM t1 LIMIT 5 +-- !query schema +struct +-- !query output +1 +2 +3 +4 +5 + + +-- !query +WITH RECURSIVE + t1 AS ( + SELECT 1 AS level + UNION ALL ( + WITH t2 AS (SELECT level + 1 FROM t1 WHERE level < 10) + SELECT * FROM t2 + ) + ) +SELECT * FROM t1 +-- !query schema +struct +-- !query output +1 +10 +2 +3 +4 +5 +6 +7 +8 +9 + + +-- !query +SET spark.sql.legacy.ctePrecedencePolicy=CORRECTED +-- !query schema +struct +-- !query output +spark.sql.legacy.ctePrecedencePolicy CORRECTED + + +-- !query +WITH + t1 AS (SELECT 1), + t2 AS ( + WITH RECURSIVE + t1 AS ( + SELECT 1 AS level + UNION ALL ( + WITH t3 AS (SELECT level + 1 FROM t1 WHERE level < 10) + SELECT * FROM t3 + ) + ) + SELECT * FROM t1 + ) +SELECT * FROM t2 +-- !query schema +struct +-- !query output +1 +10 +2 +3 +4 +5 +6 +7 +8 +9 + + +-- !query +SET spark.sql.legacy.ctePrecedencePolicy=EXCEPTION +-- !query schema +struct +-- !query output +spark.sql.legacy.ctePrecedencePolicy EXCEPTION + + +-- !query +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 0) + UNION ALL + SELECT r1.level + 1, r1.data + FROM r AS r1 + JOIN r AS r2 ON r2.data = r1.data + WHERE r1.level < 9 +) +SELECT * FROM r +-- !query schema +struct +-- !query output +0 0 +1 0 +2 0 +3 0 +4 0 +5 0 +6 0 +7 0 +8 0 +9 0 + + +-- !query +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 0) + UNION ALL + SELECT level + 1, r.data + FROM r + LEFT OUTER JOIN ( + SELECT 0 AS data + ) AS t ON t.data = r.data + WHERE r.level < 9 +) +SELECT * FROM r +-- !query schema +struct +-- !query output +0 0 +1 0 +2 0 +3 0 +4 0 +5 0 +6 0 +7 0 +8 0 +9 0 + + +-- !query +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 0) + UNION ALL + SELECT level + 1, r.data + FROM ( + SELECT 0 AS data + ) AS t + LEFT OUTER JOIN r ON r.data = t.data + WHERE r.level < 9 +) +SELECT * FROM r +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_REFERENCE.PLACE", + "sqlState" : "42836" +} + + +-- !query +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 0) + UNION ALL + SELECT level + 1, r.data + FROM ( + SELECT 0 AS data + ) AS t + RIGHT OUTER JOIN r ON r.data = t.data + WHERE r.level < 9 +) +SELECT * FROM r +-- !query schema +struct +-- !query output +0 0 +1 0 +2 0 +3 0 +4 0 +5 0 +6 0 +7 0 +8 0 +9 0 + + +-- !query +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 0) + UNION ALL + SELECT level + 1, r.data + FROM r + RIGHT OUTER JOIN ( + SELECT 0 AS data + ) AS t ON t.data = r.data + WHERE r.level < 9 +) +SELECT * FROM r +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_REFERENCE.PLACE", + "sqlState" : "42836" +} + + +-- !query +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 0) + UNION ALL + SELECT level + 1, r.data + FROM r + FULL OUTER JOIN ( + SELECT 0 AS data + ) AS t ON t.data = r.data + WHERE r.level < 9 +) +SELECT * FROM r +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_REFERENCE.PLACE", + "sqlState" : "42836" +} + + +-- !query +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 0) + UNION ALL + SELECT level + 1, r.data + FROM r + LEFT SEMI JOIN ( + SELECT 0 AS data + ) AS t ON t.data = r.data + WHERE r.level < 9 +) +SELECT * FROM r +-- !query schema +struct +-- !query output +0 0 +1 0 +2 0 +3 0 +4 0 +5 0 +6 0 +7 0 +8 0 +9 0 + + +-- !query +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 0) + UNION ALL + SELECT level + 1, data + FROM ( + SELECT 0 AS level, 0 AS data + ) AS t + LEFT SEMI JOIN r ON r.data = t.data AND r.level < 9 +) +SELECT * FROM r +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_REFERENCE.PLACE", + "sqlState" : "42836" +} + + +-- !query +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 0) + UNION ALL + SELECT level + 1, r.data + FROM r + LEFT ANTI JOIN ( + SELECT -1 AS data + ) AS t ON t.data = r.data + WHERE r.level < 9 +) +SELECT * FROM r +-- !query schema +struct +-- !query output +0 0 +1 0 +2 0 +3 0 +4 0 +5 0 +6 0 +7 0 +8 0 +9 0 + + +-- !query +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 0) + UNION ALL + SELECT level + 1, data + FROM ( + SELECT 0 AS level, 0 AS data + ) AS t + LEFT ANTI JOIN r ON r.data = t.data AND r.level < 9 +) +SELECT * FROM r +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_REFERENCE.PLACE", + "sqlState" : "42836" +} + + +-- !query +WITH RECURSIVE r(level, data) AS ( + VALUES (0, 1L) + UNION ALL + SELECT MAX(level) + 1, SUM(data) FROM r WHERE level < 9 +) +SELECT * FROM r +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_REFERENCE.PLACE", + "sqlState" : "42836" +} + + +-- !query +WITH RECURSIVE r(n) AS ( + SELECT 1 + UNION ALL + SELECT n+1 FROM r GROUP BY n) +SELECT * FROM r +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_REFERENCE.PLACE", + "sqlState" : "42836" +} + + +-- !query +CREATE TEMPORARY VIEW rv AS +WITH RECURSIVE r(level) AS ( + VALUES (0) + UNION ALL + SELECT level + 1 FROM r WHERE level < 9 +) +SELECT * FROM r +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT * FROM rv +-- !query schema +struct +-- !query output +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 + + +-- !query +DROP VIEW rv +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE rt(level INT) USING csv +-- !query schema +struct<> +-- !query output + + + +-- !query +WITH RECURSIVE r(level) AS ( + VALUES (0) + UNION ALL + SELECT level + 1 FROM r WHERE level < 9 +) +INSERT INTO rt SELECT * FROM r +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT * from rt +-- !query schema +struct +-- !query output +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 + + +-- !query +DROP TABLE rt +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE rt2(level INT) USING csv +-- !query schema +struct<> +-- !query output + + + +-- !query +WITH RECURSIVE r(level) AS ( + VALUES (0) + UNION ALL + SELECT level + 1 FROM r WHERE level < 9 +) +FROM r +INSERT INTO rt2 SELECT * +INSERT INTO rt2 SELECT * +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT * FROM rt2 +-- !query schema +struct +-- !query output +0 +0 +1 +1 +2 +2 +3 +3 +4 +4 +5 +5 +6 +6 +7 +7 +8 +8 +9 +9 + + +-- !query +DROP TABLE rt2 +-- !query schema +struct<> +-- !query output + + + +-- !query +WITH RECURSIVE + r1 AS ( + SELECT 0 AS level + UNION ALL + SELECT level + 1 FROM r1 WHERE level < 9 + ), + r2 AS ( + SELECT 10 AS level + UNION ALL + SELECT level + 1 FROM r2 WHERE level < 19 + ) +SELECT * +FROM r1 +JOIN r2 ON r2.level = r1.level + 10 +-- !query schema +struct +-- !query output +0 10 +1 11 +2 12 +3 13 +4 14 +5 15 +6 16 +7 17 +8 18 +9 19 + + +-- !query +WITH RECURSIVE r AS ( + SELECT 0 AS level + UNION ALL + SELECT level + 1 FROM r WHERE level < 9 +) +SELECT * +FROM r AS r1 +JOIN r AS r2 ON r2.level = r1.level +-- !query schema +struct +-- !query output +0 0 +1 1 +2 2 +3 3 +4 4 +5 5 +6 6 +7 7 +8 8 +9 9 + + +-- !query +WITH RECURSIVE r2 AS ( + WITH RECURSIVE r1 AS ( + SELECT 0 AS innerlevel + UNION ALL + SELECT innerlevel + 1 FROM r1 WHERE innerlevel < 3 + ) + SELECT 0 AS outerlevel, innerlevel FROM r1 + UNION ALL + SELECT outerlevel + 1, innerlevel FROM r2 WHERE outerlevel < 3 +) +SELECT * FROM r2 +-- !query schema +struct +-- !query output +0 0 +0 1 +0 2 +0 3 +1 0 +1 1 +1 2 +1 3 +2 0 +2 1 +2 2 +2 3 +3 0 +3 1 +3 2 +3 3 + + +-- !query +WITH RECURSIVE r(level) AS ( + WITH RECURSIVE r(level) AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r WHERE level < 3 + ) + SELECT * FROM r + UNION ALL + SELECT level + 1 FROM r WHERE level < 3 +) +SELECT * FROM r +-- !query schema +struct +-- !query output +0 +1 +1 +2 +2 +3 +3 + + +-- !query +WITH RECURSIVE r(level) AS ( + (WITH RECURSIVE r(level) AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r WHERE level < 3 + ) + SELECT * FROM r) + UNION ALL + SELECT level + 1 FROM r WHERE level < 3 +) +SELECT * FROM r +-- !query schema +struct +-- !query output +0 +1 +1 +2 +2 +2 +3 +3 +3 +3 + + +-- !query +CREATE TEMPORARY VIEW routes(origin, destination) AS VALUES + ('New York', 'Washington'), + ('New York', 'Boston'), + ('Boston', 'New York'), + ('Washington', 'Boston'), + ('Washington', 'Raleigh') +-- !query schema +struct<> +-- !query output + + + +-- !query +WITH RECURSIVE destinations_from_new_york AS ( + SELECT 'New York' AS destination, ARRAY('New York') AS path, 0 AS length + UNION ALL + SELECT r.destination, CONCAT(d.path, ARRAY(r.destination)), d.length + 1 + FROM routes AS r + JOIN destinations_from_new_york AS d ON d.destination = r.origin AND NOT ARRAY_CONTAINS(d.path, r.destination) +) +SELECT * FROM destinations_from_new_york +-- !query schema +struct,length:int> +-- !query output +Boston ["New York","Boston"] 1 +Boston ["New York","Washington","Boston"] 2 +New York ["New York"] 0 +Raleigh ["New York","Washington","Raleigh"] 2 +Washington ["New York","Washington"] 1 + + +-- !query +DROP VIEW routes +-- !query schema +struct<> +-- !query output + + + +-- !query +WITH RECURSIVE fibonacci AS ( + VALUES (0, 1) AS t(a, b) + UNION ALL + SELECT b, a + b FROM fibonacci WHERE a < 10 +) +SELECT a FROM fibonacci ORDER BY a +-- !query schema +struct +-- !query output +0 +1 +1 +2 +3 +5 +8 +13 + + +-- !query +WITH RECURSIVE t1(a,b,c) AS ( + SELECT 1,1,1 + UNION ALL + SELECT a+1,a+1,a+1 FROM t1) +SELECT a FROM t1 LIMIT 5 +-- !query schema +struct +-- !query output +1 +2 +3 +4 +5 + + +-- !query +CREATE TABLE tb (next INT) USING json +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO tb VALUES (0), (1) +-- !query schema +struct<> +-- !query output + + + +-- !query +WITH RECURSIVE t(n) AS ( + SELECT 1 + UNION ALL + SELECT next FROM t CROSS JOIN tb + ) +SELECT * FROM t LIMIT 63 +-- !query schema +struct +-- !query output +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + + +-- !query +DROP TABLE tb +-- !query schema +struct<> +-- !query output + + + +-- !query +WITH RECURSIVE + x(id) AS (SELECT 1 UNION SELECT 2), + t(id, xid) AS ( + SELECT 0 AS id, 0 AS xid + UNION ALL + SELECT t.id + 1, xid * 10 + x.id FROM t CROSS JOIN x WHERE t.id < 3 + ) +SELECT * FROM t +-- !query schema +struct +-- !query output +0 0 +1 1 +1 2 +2 11 +2 12 +2 21 +2 22 +3 111 +3 112 +3 121 +3 122 +3 211 +3 212 +3 221 +3 222 + + +-- !query +WITH RECURSIVE t1(a, b) AS ( + SELECT 1, 1 + UNION ALL + SELECT a + b, a FROM t1 WHERE a < 20 +), +t2(n) AS ( + SELECT 1 + UNION ALL + SELECT n + 1 FROM t2, t1 WHERE n + 1 = a +) +SELECT * FROM t2 +-- !query schema +struct +-- !query output +1 +2 +3 + + +-- !query +WITH RECURSIVE t1 (n) AS ( + VALUES(1) + UNION ALL + ( + WITH t2(j) AS ( + SELECT n + 1 FROM t1 + ), + t3(k) AS ( + SELECT j FROM t2 + ) + SELECT k FROM t3 WHERE k <= 5 + ) +) +SELECT n FROM t1 +-- !query schema +struct +-- !query output +1 +2 +3 +4 +5 + + +-- !query +WITH RECURSIVE r2(outerlevel1, innerlevel1) AS ( + WITH RECURSIVE r1 AS ( + SELECT 0 AS innerlevel + UNION ALL + SELECT innerlevel + 1 FROM r1 WHERE innerlevel < 3 + ) + SELECT 0 AS outerlevel, innerlevel FROM r1 + UNION ALL + SELECT outerlevel1 + 1, innerlevel1 FROM r2 WHERE outerlevel1 < 3 +) +SELECT * FROM r2 +-- !query schema +struct +-- !query output +0 0 +0 1 +0 2 +0 3 +1 0 +1 1 +1 2 +1 3 +2 0 +2 1 +2 2 +2 3 +3 0 +3 1 +3 2 +3 3 + + +-- !query +WITH RECURSIVE t1(n) AS ( + WITH t2(n) AS (SELECT * FROM t1) + SELECT 1 + UNION ALL + SELECT n+1 FROM t2 WHERE n < 5) +SELECT * FROM t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_CTE", + "sqlState" : "42836" +} + + +-- !query +WITH RECURSIVE t1 AS ( + WITH t2(n) AS (SELECT * FROM t1) + SELECT 1 AS n + UNION ALL + SELECT n+1 FROM t2 WHERE n < 5) +SELECT * FROM t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_CTE", + "sqlState" : "42836" +} + + +-- !query +WITH RECURSIVE tmp(x) AS ( + values (1), (2), (3), (4), (5) +), rcte(x, y) AS ( + SELECT x, x FROM tmp WHERE x = 1 + UNION ALL + SELECT x + 1, x FROM rcte WHERE x < 5 +) +SELECT * FROM rcte +-- !query schema +struct +-- !query output +1 1 +2 1 +3 2 +4 3 +5 4 + + +-- !query +SET spark.sql.cteRecursionAnchorRowsLimitToConvertToLocalRelation=0 +-- !query schema +struct +-- !query output +spark.sql.cteRecursionAnchorRowsLimitToConvertToLocalRelation 0 + + +-- !query +WITH RECURSIVE tmp(x) AS ( + values (1), (2), (3), (4), (5) +), rcte(x, y) AS ( + SELECT x, x FROM tmp WHERE x = 1 + UNION ALL + SELECT x + 1, x FROM rcte WHERE x < 5 +) +SELECT * FROM rcte +-- !query schema +struct +-- !query output +1 1 +2 1 +3 2 +4 3 +5 4 + + +-- !query +SET spark.sql.cteRecursionAnchorRowsLimitToConvertToLocalRelation=100 +-- !query schema +struct +-- !query output +spark.sql.cteRecursionAnchorRowsLimitToConvertToLocalRelation 100 + + +-- !query +WITH RECURSIVE tmp(x) AS ( + values (1), (2), (3), (4), (5) +), rcte(x, y, z, t) AS ( + SELECT x, x, x, x FROM tmp WHERE x = 1 + UNION ALL + SELECT x + 1, x, y + 1, y FROM rcte WHERE x < 5 +) +SELECT * FROM rcte +-- !query schema +struct +-- !query output +1 1 1 1 +2 1 2 1 +3 2 2 1 +4 3 3 2 +5 4 4 3 + + +-- !query +WITH RECURSIVE randoms(val) AS ( + SELECT CAST(floor(rand(82374) * 5 + 1) AS INT) + UNION ALL + SELECT CAST(floor(rand(237685) * 5 + 1) AS INT) + FROM randoms +) +SELECT val FROM randoms LIMIT 5 +-- !query schema +struct +-- !query output +1 +3 +4 +4 +5 + + +-- !query +WITH RECURSIVE randoms(val) AS ( + SELECT CAST(UNIFORM(1, 6, 82374) AS INT) + UNION ALL + SELECT CAST(UNIFORM(1, 6, 237685) AS INT) + FROM randoms +) +SELECT val FROM randoms LIMIT 5 +-- !query schema +struct +-- !query output +1 +3 +4 +4 +5 + + +-- !query +WITH RECURSIVE randoms(val) AS ( + SELECT CAST(floor(randn(82374) * 5 + 1) AS INT) + UNION ALL + SELECT CAST(floor(randn(237685) * 5 + 1) AS INT) + FROM randoms +) +SELECT val FROM randoms LIMIT 5 +-- !query schema +struct +-- !query output +-2 +2 +2 +5 +6 + + +-- !query +WITH RECURSIVE randoms(val) AS ( + SELECT randstr(10, 82374) + UNION ALL + SELECT randstr(10, 237685) + FROM randoms +) +SELECT val FROM randoms LIMIT 5 +-- !query schema +struct +-- !query output +IpXzdTW03I +Zj7uI2Ex6e +dBlWnfo7rO +fmfDBMf60f +kFeBV7dQWi + + +-- !query +WITH RECURSIVE randoms(val) AS ( + SELECT UUID(82374) + UNION ALL + SELECT UUID(237685) + FROM randoms +) +SELECT val FROM randoms LIMIT 5 +-- !query schema +struct +-- !query output +19974dca-21f6-47ef-b58c-73908ab52aa0 +4ea190e3-c088-4ddd-a545-fb431059ae3c +8b88900e-f862-468c-8d3b-828188116155 +be4f5346-1c7f-4697-8a2c-1343347872c5 +d0032efe-ae60-461b-8582-f6a7c649f238 + + +-- !query +WITH RECURSIVE randoms(val) AS ( + SELECT ARRAY(1,2,3,4,5) + UNION ALL + SELECT SHUFFLE(ARRAY(1,2,3,4,5), 237685) + FROM randoms +) +SELECT val FROM randoms LIMIT 5 +-- !query schema +struct> +-- !query output +[1,2,3,4,5] +[1,2,3,5,4] +[2,1,5,3,4] +[4,3,2,5,1] +[4,5,1,2,3] + + +-- !query +WITH RECURSIVE t1(n, m) AS ( + SELECT 1, CAST(1 AS BIGINT) + UNION ALL + SELECT n+1, n+1 FROM t1 WHERE n < 5) +SELECT * FROM t1 +-- !query schema +struct +-- !query output +1 1 +2 2 +3 3 +4 4 +5 5 + + +-- !query +WITH RECURSIVE t1(n, m) AS ( + SELECT 1, 1 + UNION ALL + SELECT n+1, CAST(n+1 AS BIGINT) FROM t1 WHERE n < 5) +SELECT * FROM t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkException +{ + "errorClass" : "CANNOT_MERGE_INCOMPATIBLE_DATA_TYPE", + "sqlState" : "42825", + "messageParameters" : { + "left" : "\"INT\"", + "right" : "\"BIGINT\"" + } +} + + +-- !query +WITH RECURSIVE t1(n) AS ( + SELECT 1 + UNION ALL + SELECT CASE WHEN n < 5 THEN n + 1 ELSE NULL END FROM t1 +) +SELECT * FROM t1 LIMIT 25 +-- !query schema +struct +-- !query output +1 +2 +3 +4 +5 +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL + + +-- !query +WITH RECURSIVE t1(n) AS ( + SELECT 1 + UNION ALL + SELECT n + 1 FROM t1 WHERE n < 5 +) +SELECT (SELECT SUM(n) FROM (SELECT * FROM t1)), (SELECT SUM(n) FROM (SELECT * FROM t1 LIMIT 3)) +-- !query schema +struct +-- !query output +15 6 + + +-- !query +WITH RECURSIVE t1(n) AS ( + SELECT 1 + UNION ALL + SELECT n + 1 FROM t1 +) +SELECT (SELECT SUM(n) FROM (SELECT * FROM t1 LIMIT 5)), (SELECT SUM(n) FROM (SELECT * FROM t1 LIMIT 3)) +-- !query schema +struct +-- !query output +15 6 + + +-- !query +WITH RECURSIVE t1(n) AS ( + SELECT 1 + UNION ALL + SELECT n + 1 FROM t1 +), t2(m) AS ( + SELECT (SELECT SUM(n) FROM (SELECT n FROM t1 LIMIT 10) AS sums) + UNION ALL + SELECT m + (SELECT SUM(n) FROM (SELECT n FROM t1 LIMIT 3) AS sums) FROM t2 +) +SELECT * FROM t2 LIMIT 20 +-- !query schema +struct +-- !query output +103 +109 +115 +121 +127 +133 +139 +145 +151 +157 +163 +169 +55 +61 +67 +73 +79 +85 +91 +97 + + +-- !query +WITH RECURSIVE t1(n) AS ( + SELECT 1 + UNION ALL + SELECT n + 1 FROM t1 +) + ((SELECT n FROM t1) UNION ALL (SELECT n FROM t1)) LIMIT 20 +-- !query schema +struct +-- !query output +1 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +2 +20 +3 +4 +5 +6 +7 +8 +9 + + +-- !query +WITH RECURSIVE win(id, val) AS ( + SELECT 1, CAST(10 AS BIGINT) + UNION ALL + SELECT id + 1, SUM(val) OVER (ORDER BY id ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) + FROM win WHERE id < 3 +) +SELECT * FROM win +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_REFERENCE.PLACE", + "sqlState" : "42836" +} + + +-- !query +WITH RECURSIVE t1(n) AS ( + SELECT 1 + UNION ALL + (SELECT n + 1 FROM t1 WHERE n < 5 ORDER BY n) +) +SELECT * FROM t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_REFERENCE.PLACE", + "sqlState" : "42836" +} + + +-- !query +WITH RECURSIVE t1(n) AS ( + SELECT 1 FROM t1 + UNION ALL + SELECT n+1 FROM t1 WHERE n < 5) +SELECT * FROM t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_CTE", + "sqlState" : "42836" +} + + +-- !query +WITH RECURSIVE t1 AS ( + SELECT 1 AS n FROM t1 + UNION ALL + SELECT n+1 FROM t1 WHERE n < 5) +SELECT * FROM t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_CTE", + "sqlState" : "42836" +} + + +-- !query +WITH RECURSIVE t1(n) AS ( + WITH t2(m) AS (SELECT 1) + SELECT 1 FROM t1 + UNION ALL + SELECT n+1 FROM t1 WHERE n < 5) +SELECT * FROM t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_CTE", + "sqlState" : "42836" +} + + +-- !query +WITH RECURSIVE t1 AS ( + WITH t2(m) AS (SELECT 1) + SELECT 1 AS n FROM t1 + UNION ALL + SELECT n+1 FROM t1 WHERE n < 5) +SELECT * FROM t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_CTE", + "sqlState" : "42836" +} + + +-- !query +WITH RECURSIVE t AS ( + SELECT 1 AS n + UNION ALL + SELECT n + m + FROM (SELECT 2 as m) subq + JOIN t ON n = m + WHERE n <> m +) +SELECT * FROM t +-- !query schema +struct +-- !query output +1 diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/cte.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/cte.sql.out index 5dd2fdeca5e..8e07b9081f7 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/cte.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/cte.sql.out @@ -23,6 +23,14 @@ struct<> +-- !query +create table t4(col1 TIMESTAMP) +-- !query schema +struct<> +-- !query output + + + -- !query WITH s AS (SELECT 1 FROM s) SELECT * FROM s -- !query schema @@ -602,6 +610,188 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException } +-- !query +SELECT * FROM ( + ( + WITH cte AS (SELECT 1) + SELECT * FROM cte + ) UNION ALL ( + WITH cte AS (SELECT 2) + SELECT * FROM cte + ) +) +-- !query schema +struct<1:int> +-- !query output +1 +2 + + +-- !query +SELECT * FROM ( + ( + WITH cte AS (SELECT 2) + SELECT * FROM cte + ) UNION ALL ( + SELECT 1 WHERE EXISTS ( + SELECT * FROM cte + ) + ) +) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "TABLE_OR_VIEW_NOT_FOUND", + "sqlState" : "42P01", + "messageParameters" : { + "relationName" : "`cte`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 134, + "stopIndex" : 136, + "fragment" : "cte" + } ] +} + + +-- !query +SELECT + * +FROM + VALUES (1) +WHERE EXISTS ( + WITH cte AS (SELECT 1) + SELECT * FROM cte +) +UNION ALL ( + SELECT + * + FROM + VALUES (1) + WHERE EXISTS ( + WITH cte AS (SELECT 1) + SELECT * FROM cte + ) +) +-- !query schema +struct +-- !query output +1 +1 + + +-- !query +WITH cte AS ( + SELECT + * + FROM + VALUES (1) + WHERE EXISTS ( + WITH cte AS (SELECT 1) + SELECT * FROM cte + ) + UNION ALL ( + SELECT + * + FROM + VALUES (1) + WHERE EXISTS ( + WITH cte AS (SELECT 1) + SELECT * FROM cte + ) + ) +) +SELECT * FROM cte +-- !query schema +struct +-- !query output +1 +1 + + +-- !query +SELECT * FROM ( + WITH cte AS (SELECT 1) + SELECT + * + FROM VALUES (1) + WHERE EXISTS ( + WITH cte AS (SELECT 1) + SELECT * FROM cte + ) + UNION ALL ( + SELECT + * + FROM + VALUES (1) + WHERE EXISTS ( + WITH cte AS (SELECT 1) + SELECT * FROM cte + ) + ) +) +-- !query schema +struct +-- !query output +1 +1 + + +-- !query +WITH `a.b.c` AS ( + SELECT 1 +) +SELECT * FROM `a.b.c` +-- !query schema +struct<1:int> +-- !query output +1 + + +-- !query +SELECT * FROM ( + WITH cte1 AS (SELECT * FROM t4) SELECT t4.col1 FROM t4 JOIN cte1 USING (col1) +) +-- !query schema +struct +-- !query output + + + +-- !query +SELECT * FROM ( + WITH cte1 AS (SELECT * FROM t4) SELECT cte1.col1 FROM t4 JOIN cte1 USING (col1) +) +-- !query schema +struct +-- !query output + + + +-- !query +SELECT * FROM ( + WITH cte1 AS (SELECT * FROM t4) SELECT t4.col1 FROM cte1 JOIN t4 USING (col1) +) +-- !query schema +struct +-- !query output + + + +-- !query +SELECT * FROM ( + WITH cte1 AS (SELECT * FROM t4) SELECT cte1.col1 FROM cte1 JOIN t4 USING (col1) +) +-- !query schema +struct +-- !query output + + + -- !query DROP VIEW IF EXISTS t -- !query schema @@ -624,3 +814,11 @@ DROP VIEW IF EXISTS t3 struct<> -- !query output + + +-- !query +DROP TABLE IF EXISTS t4 +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/date.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/date.sql.out index aec320fe6b1..533795da1c4 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/date.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/date.sql.out @@ -53,7 +53,7 @@ struct<> -- !query output org.apache.spark.SparkDateTimeException { - "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS", + "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION", "sqlState" : "22023", "messageParameters" : { "ansiConfig" : "\"spark.sql.ansi.enabled\"", @@ -69,7 +69,7 @@ struct<> -- !query output org.apache.spark.SparkDateTimeException { - "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS", + "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION", "sqlState" : "22023", "messageParameters" : { "ansiConfig" : "\"spark.sql.ansi.enabled\"", @@ -207,7 +207,7 @@ org.apache.spark.SparkDateTimeException "errorClass" : "CANNOT_PARSE_TIMESTAMP", "sqlState" : "22007", "messageParameters" : { - "func" : "`try_to_timestamp`", + "func" : "`try_to_date`", "message" : "Invalid date 'February 29' as '1970' is not a leap year" } } @@ -802,7 +802,7 @@ struct<(2001-10-01 - DATE '2001-09-28'):interval day> -- !query select date '2001-09-28' - null -- !query schema -struct +struct<(DATE '2001-09-28' - NULL):interval day> -- !query output NULL @@ -886,7 +886,7 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException -- !query select date'2011-11-11' + null -- !query schema -struct +struct -- !query output NULL @@ -894,7 +894,7 @@ NULL -- !query select null + date'2011-11-11' -- !query schema -struct +struct -- !query output NULL diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/datetime-formatting-invalid.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/datetime-formatting-invalid.sql.out index 66b36befaa3..8e62ecd1717 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/datetime-formatting-invalid.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/datetime-formatting-invalid.sql.out @@ -306,8 +306,15 @@ select date_format('2018-11-17 13:33:33.333', 'V') -- !query schema struct<> -- !query output -java.lang.IllegalArgumentException -Pattern letter count must be 2: V +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "INVALID_DATETIME_PATTERN.WITH_SUGGESTION", + "sqlState" : "22007", + "messageParameters" : { + "docroot" : "https://spark.apache.org/docs/latest", + "pattern" : "'V'" + } +} -- !query @@ -332,8 +339,15 @@ select date_format('2018-11-17 13:33:33.333', 'XXXXXX') -- !query schema struct<> -- !query output -java.lang.IllegalArgumentException -Too many pattern letters: X +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "INVALID_DATETIME_PATTERN.WITH_SUGGESTION", + "sqlState" : "22007", + "messageParameters" : { + "docroot" : "https://spark.apache.org/docs/latest", + "pattern" : "'XXXXXX'" + } +} -- !query @@ -358,8 +372,15 @@ select date_format('2018-11-17 13:33:33.333', 'OO') -- !query schema struct<> -- !query output -java.lang.IllegalArgumentException -Pattern letter count must be 1 or 4: O +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "INVALID_DATETIME_PATTERN.WITH_SUGGESTION", + "sqlState" : "22007", + "messageParameters" : { + "docroot" : "https://spark.apache.org/docs/latest", + "pattern" : "'OO'" + } +} -- !query @@ -367,8 +388,15 @@ select date_format('2018-11-17 13:33:33.333', 'xxxxxx') -- !query schema struct<> -- !query output -java.lang.IllegalArgumentException -Too many pattern letters: x +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "INVALID_DATETIME_PATTERN.WITH_SUGGESTION", + "sqlState" : "22007", + "messageParameters" : { + "docroot" : "https://spark.apache.org/docs/latest", + "pattern" : "'xxxxxx'" + } +} -- !query @@ -554,8 +582,15 @@ select date_format('2018-11-17 13:33:33.333', 'C') -- !query schema struct<> -- !query output -java.lang.IllegalArgumentException -Unknown pattern letter: C +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "INVALID_DATETIME_PATTERN.WITH_SUGGESTION", + "sqlState" : "22007", + "messageParameters" : { + "docroot" : "https://spark.apache.org/docs/latest", + "pattern" : "'C'" + } +} -- !query @@ -563,5 +598,12 @@ select date_format('2018-11-17 13:33:33.333', 'I') -- !query schema struct<> -- !query output -java.lang.IllegalArgumentException -Unknown pattern letter: I +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "INVALID_DATETIME_PATTERN.WITH_SUGGESTION", + "sqlState" : "22007", + "messageParameters" : { + "docroot" : "https://spark.apache.org/docs/latest", + "pattern" : "'I'" + } +} diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/datetime-formatting-legacy.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/datetime-formatting-legacy.sql.out index b920f8f2965..ba0e9421e5b 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/datetime-formatting-legacy.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/datetime-formatting-legacy.sql.out @@ -47,8 +47,15 @@ select col, date_format(col, 'q qq'), to_char(col, 'q qq'), to_varchar(col, 'q q -- !query schema struct<> -- !query output -java.lang.IllegalArgumentException -Illegal pattern character 'q' +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "INVALID_DATETIME_PATTERN.WITH_SUGGESTION", + "sqlState" : "22007", + "messageParameters" : { + "docroot" : "https://spark.apache.org/docs/latest", + "pattern" : "'q qq'" + } +} -- !query @@ -56,8 +63,15 @@ select col, date_format(col, 'Q QQ QQQ QQQQ'), to_char(col, 'Q QQ QQQ QQQQ'), to -- !query schema struct<> -- !query output -java.lang.IllegalArgumentException -Illegal pattern character 'Q' +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "INVALID_DATETIME_PATTERN.WITH_SUGGESTION", + "sqlState" : "22007", + "messageParameters" : { + "docroot" : "https://spark.apache.org/docs/latest", + "pattern" : "'Q QQ QQQ QQQQ'" + } +} -- !query @@ -269,8 +283,15 @@ select col, date_format(col, 'VV'), to_char(col, 'VV'), to_varchar(col, 'VV') fr -- !query schema struct<> -- !query output -java.lang.IllegalArgumentException -Illegal pattern character 'V' +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "INVALID_DATETIME_PATTERN.WITH_SUGGESTION", + "sqlState" : "22007", + "messageParameters" : { + "docroot" : "https://spark.apache.org/docs/latest", + "pattern" : "'VV'" + } +} -- !query @@ -306,8 +327,15 @@ select col, date_format(col, 'XXXX XXXXX'), to_char(col, 'XXXX XXXXX'), to_varch -- !query schema struct<> -- !query output -java.lang.IllegalArgumentException -invalid ISO 8601 format: length=4 +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "INVALID_DATETIME_PATTERN.WITH_SUGGESTION", + "sqlState" : "22007", + "messageParameters" : { + "docroot" : "https://spark.apache.org/docs/latest", + "pattern" : "'XXXX XXXXX'" + } +} -- !query @@ -329,8 +357,15 @@ select col, date_format(col, 'O OOOO'), to_char(col, 'O OOOO'), to_varchar(col, -- !query schema struct<> -- !query output -java.lang.IllegalArgumentException -Illegal pattern character 'O' +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "INVALID_DATETIME_PATTERN.WITH_SUGGESTION", + "sqlState" : "22007", + "messageParameters" : { + "docroot" : "https://spark.apache.org/docs/latest", + "pattern" : "'O OOOO'" + } +} -- !query @@ -338,8 +373,15 @@ select col, date_format(col, 'x xx xxx xxxx xxxx xxxxx'), to_char(col, 'x xx xxx -- !query schema struct<> -- !query output -java.lang.IllegalArgumentException -Illegal pattern character 'x' +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "INVALID_DATETIME_PATTERN.WITH_SUGGESTION", + "sqlState" : "22007", + "messageParameters" : { + "docroot" : "https://spark.apache.org/docs/latest", + "pattern" : "'x xx xxx xxxx xxxx xxxxx'" + } +} -- !query diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/datetime-legacy.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/datetime-legacy.sql.out index 17ec4e58405..c774cfb1c0d 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/datetime-legacy.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/datetime-legacy.sql.out @@ -53,7 +53,7 @@ struct<> -- !query output org.apache.spark.SparkDateTimeException { - "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS", + "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION", "sqlState" : "22023", "messageParameters" : { "ansiConfig" : "\"spark.sql.ansi.enabled\"", @@ -69,7 +69,7 @@ struct<> -- !query output org.apache.spark.SparkDateTimeException { - "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS", + "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION", "sqlState" : "22023", "messageParameters" : { "ansiConfig" : "\"spark.sql.ansi.enabled\"", @@ -778,7 +778,7 @@ struct<(2001-10-01 - DATE '2001-09-28'):interval day> -- !query select date '2001-09-28' - null -- !query schema -struct +struct<(DATE '2001-09-28' - NULL):interval day> -- !query output NULL @@ -862,7 +862,7 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException -- !query select date'2011-11-11' + null -- !query schema -struct +struct -- !query output NULL @@ -870,7 +870,7 @@ NULL -- !query select null + date'2011-11-11' -- !query schema -struct +struct -- !query output NULL @@ -1323,7 +1323,7 @@ struct<> -- !query output org.apache.spark.SparkDateTimeException { - "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS", + "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION", "sqlState" : "22023", "messageParameters" : { "ansiConfig" : "\"spark.sql.ansi.enabled\"", @@ -1355,7 +1355,7 @@ struct<> -- !query output org.apache.spark.SparkDateTimeException { - "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS", + "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION", "sqlState" : "22023", "messageParameters" : { "ansiConfig" : "\"spark.sql.ansi.enabled\"", @@ -1371,7 +1371,7 @@ struct<> -- !query output org.apache.spark.SparkDateTimeException { - "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS", + "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION", "sqlState" : "22023", "messageParameters" : { "ansiConfig" : "\"spark.sql.ansi.enabled\"", @@ -1380,6 +1380,378 @@ org.apache.spark.SparkDateTimeException } +-- !query +SELECT make_timestamp(make_date(2021, 07, 11)) +-- !query schema +struct +-- !query output +2021-07-11 00:00:00 + + +-- !query +SELECT make_timestamp(DATE'1970-01-01') +-- !query schema +struct +-- !query output +1970-01-01 00:00:00 + + +-- !query +SELECT make_timestamp(NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678)) +-- !query schema +struct +-- !query output +2021-07-11 06:30:45.678 + + +-- !query +SELECT make_timestamp(DATE'1970-01-01', TIME'00:00:00') +-- !query schema +struct +-- !query output +1970-01-01 00:00:00 + + +-- !query +SELECT make_timestamp(NULL, TIME'00:00:00') +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(DATE'1970-01-01', NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(NULL, NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'MIT') +-- !query schema +struct +-- !query output +2021-07-10 10:30:45.678 + + +-- !query +SELECT make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'PST') +-- !query schema +struct +-- !query output +2021-07-11 06:30:45.678 + + +-- !query +SELECT make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'UTC') +-- !query schema +struct +-- !query output +2021-07-10 23:30:45.678 + + +-- !query +SELECT make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'CET') +-- !query schema +struct +-- !query output +2021-07-10 21:30:45.678 + + +-- !query +SELECT make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'JST') +-- !query schema +struct +-- !query output +2021-07-10 14:30:45.678 + + +-- !query +SELECT make_timestamp(DATE'1970-01-01', TIME'00:00:00', 'UTC') +-- !query schema +struct +-- !query output +1969-12-31 16:00:00 + + +-- !query +SELECT make_timestamp(NULL, TIME'00:00:00', 'UTC') +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(DATE'1970-01-01', NULL, 'UTC') +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(DATE'1970-01-01', TIME'00:00:00', NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(NULL, NULL, 'UTC') +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(NULL, TIME'00:00:00', NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(DATE'1970-01-01', NULL, NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(NULL, NULL, NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(timestamp '2018-11-17 13:33:33', TIME'0:0:0', 'CET') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"TIMESTAMP '2018-11-17 13:33:33'\"", + "inputType" : "\"TIMESTAMP\"", + "paramIndex" : "first", + "requiredType" : "\"DATE\"", + "sqlExpr" : "\"make_timestamp(TIMESTAMP '2018-11-17 13:33:33', TIME '00:00:00', CET)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 74, + "fragment" : "make_timestamp(timestamp '2018-11-17 13:33:33', TIME'0:0:0', 'CET')" + } ] +} + + +-- !query +SELECT make_timestamp(timestamp_ntz '2018-11-17 13:33:33', TIME'0:0:0', 'CET') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"TIMESTAMP_NTZ '2018-11-17 13:33:33'\"", + "inputType" : "\"TIMESTAMP_NTZ\"", + "paramIndex" : "first", + "requiredType" : "\"DATE\"", + "sqlExpr" : "\"make_timestamp(TIMESTAMP_NTZ '2018-11-17 13:33:33', TIME '00:00:00', CET)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 78, + "fragment" : "make_timestamp(timestamp_ntz '2018-11-17 13:33:33', TIME'0:0:0', 'CET')" + } ] +} + + +-- !query +SELECT make_timestamp(DATE'1970-01-01', timestamp '2018-11-17 13:33:33', 'CET') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"TIMESTAMP '2018-11-17 13:33:33'\"", + "inputType" : "\"TIMESTAMP\"", + "paramIndex" : "second", + "requiredType" : "\"TIME\"", + "sqlExpr" : "\"make_timestamp(DATE '1970-01-01', TIMESTAMP '2018-11-17 13:33:33', CET)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 79, + "fragment" : "make_timestamp(DATE'1970-01-01', timestamp '2018-11-17 13:33:33', 'CET')" + } ] +} + + +-- !query +SELECT make_timestamp(DATE'1970-01-01', timestamp_ntz '2018-11-17 13:33:33', 'CET') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"TIMESTAMP_NTZ '2018-11-17 13:33:33'\"", + "inputType" : "\"TIMESTAMP_NTZ\"", + "paramIndex" : "second", + "requiredType" : "\"TIME\"", + "sqlExpr" : "\"make_timestamp(DATE '1970-01-01', TIMESTAMP_NTZ '2018-11-17 13:33:33', CET)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 83, + "fragment" : "make_timestamp(DATE'1970-01-01', timestamp_ntz '2018-11-17 13:33:33', 'CET')" + } ] +} + + +-- !query +SELECT try_make_timestamp(make_date(2021, 07, 11)) +-- !query schema +struct +-- !query output +2021-07-11 00:00:00 + + +-- !query +SELECT try_make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678)) +-- !query schema +struct +-- !query output +2021-07-11 06:30:45.678 + + +-- !query +SELECT try_make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'CET') +-- !query schema +struct +-- !query output +2021-07-10 21:30:45.678 + + +-- !query +SELECT try_make_timestamp(NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT try_make_timestamp(NULL, NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT try_make_timestamp(NULL, NULL, NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT try_make_timestamp(timestamp '2018-11-17 13:33:33', TIME'0:0:0', 'CET') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"TIMESTAMP '2018-11-17 13:33:33'\"", + "inputType" : "\"TIMESTAMP\"", + "paramIndex" : "first", + "requiredType" : "\"DATE\"", + "sqlExpr" : "\"make_timestamp(TIMESTAMP '2018-11-17 13:33:33', TIME '00:00:00', CET)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 78, + "fragment" : "try_make_timestamp(timestamp '2018-11-17 13:33:33', TIME'0:0:0', 'CET')" + } ] +} + + +-- !query +SELECT try_make_timestamp(DATE'1970-01-01', timestamp_ntz '2018-11-17 13:33:33', 'CET') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"TIMESTAMP_NTZ '2018-11-17 13:33:33'\"", + "inputType" : "\"TIMESTAMP_NTZ\"", + "paramIndex" : "second", + "requiredType" : "\"TIME\"", + "sqlExpr" : "\"make_timestamp(DATE '1970-01-01', TIMESTAMP_NTZ '2018-11-17 13:33:33', CET)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 87, + "fragment" : "try_make_timestamp(DATE'1970-01-01', timestamp_ntz '2018-11-17 13:33:33', 'CET')" + } ] +} + + -- !query select TIMESTAMP_SECONDS(1230219000),TIMESTAMP_SECONDS(-1230219000),TIMESTAMP_SECONDS(null) -- !query schema @@ -2116,49 +2488,17 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException -- !query select timestamp'2011-11-11 11:11:11' + null -- !query schema -struct<> +struct -- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "DATATYPE_MISMATCH.BINARY_OP_DIFF_TYPES", - "sqlState" : "42K09", - "messageParameters" : { - "left" : "\"TIMESTAMP\"", - "right" : "\"VOID\"", - "sqlExpr" : "\"(TIMESTAMP '2011-11-11 11:11:11' + NULL)\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 44, - "fragment" : "timestamp'2011-11-11 11:11:11' + null" - } ] -} +NULL -- !query select null + timestamp'2011-11-11 11:11:11' -- !query schema -struct<> +struct -- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "DATATYPE_MISMATCH.BINARY_OP_DIFF_TYPES", - "sqlState" : "42K09", - "messageParameters" : { - "left" : "\"VOID\"", - "right" : "\"TIMESTAMP\"", - "sqlExpr" : "\"(NULL + TIMESTAMP '2011-11-11 11:11:11')\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 44, - "fragment" : "null + timestamp'2011-11-11 11:11:11'" - } ] -} +NULL -- !query diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/datetime-parsing-invalid.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/datetime-parsing-invalid.sql.out index 280040ba393..e03bd33b071 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/datetime-parsing-invalid.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/datetime-parsing-invalid.sql.out @@ -299,7 +299,7 @@ org.apache.spark.SparkDateTimeException "errorClass" : "CANNOT_PARSE_TIMESTAMP", "sqlState" : "22007", "messageParameters" : { - "func" : "`try_to_timestamp`", + "func" : "`try_to_date`", "message" : "Text '2020-01-27T20:06:11.847' could not be parsed at index 10" } } @@ -315,7 +315,7 @@ org.apache.spark.SparkDateTimeException "errorClass" : "CANNOT_PARSE_TIMESTAMP", "sqlState" : "22007", "messageParameters" : { - "func" : "`try_to_timestamp`", + "func" : "`try_to_date`", "message" : "Text 'Unparseable' could not be parsed at index 0" } } diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/decimalArithmeticOperations.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/decimalArithmeticOperations.sql.out index cb52778c420..5110af2189c 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/decimalArithmeticOperations.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/decimalArithmeticOperations.sql.out @@ -36,7 +36,7 @@ struct<> -- !query output org.apache.spark.SparkArithmeticException { - "errorClass" : "DIVIDE_BY_ZERO", + "errorClass" : "REMAINDER_BY_ZERO", "sqlState" : "22012", "messageParameters" : { "config" : "\"spark.sql.ansi.enabled\"" @@ -58,7 +58,7 @@ struct<> -- !query output org.apache.spark.SparkArithmeticException { - "errorClass" : "DIVIDE_BY_ZERO", + "errorClass" : "REMAINDER_BY_ZERO", "sqlState" : "22012", "messageParameters" : { "config" : "\"spark.sql.ansi.enabled\"" diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/describe.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/describe.sql.out index 3659267e8e9..989672c9428 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/describe.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/describe.sql.out @@ -453,6 +453,58 @@ org.apache.spark.sql.catalyst.parser.ParseException } +-- !query +DROP SCHEMA IF EXISTS test_schema +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE SCHEMA test_schema DEFAULT COLLATION UNICODE +-- !query schema +struct<> +-- !query output + + + +-- !query +DESCRIBE SCHEMA EXTENDED test_schema +-- !query schema +struct +-- !query output +Catalog Name spark_catalog +Collation UNICODE +Comment +Location [not included in comparison]/{warehouse_dir}/test_schema.db +Namespace Name test_schema +Owner [not included in comparison] +Properties + + +-- !query +ALTER SCHEMA test_schema DEFAULT COLLATION UTF8_LCASE +-- !query schema +struct<> +-- !query output + + + +-- !query +DESCRIBE SCHEMA EXTENDED test_schema +-- !query schema +struct +-- !query output +Catalog Name spark_catalog +Collation UTF8_LCASE +Comment +Location [not included in comparison]/{warehouse_dir}/test_schema.db +Namespace Name test_schema +Owner [not included in comparison] +Properties + + -- !query DESC temp_v -- !query schema diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/double-quoted-identifiers-enabled.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/double-quoted-identifiers-enabled.sql.out index 2444c399a87..e52435269dc 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/double-quoted-identifiers-enabled.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/double-quoted-identifiers-enabled.sql.out @@ -170,6 +170,28 @@ org.apache.spark.sql.AnalysisException } +-- !query +select 1 from "not_""exists" +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "TABLE_OR_VIEW_NOT_FOUND", + "sqlState" : "42P01", + "messageParameters" : { + "relationName" : "`not_\"exists`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 15, + "stopIndex" : 28, + "fragment" : "\"not_\"\"exists\"" + } ] +} + + -- !query SELECT 1 FROM `hello` -- !query schema diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/double-quoted-identifiers.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/double-quoted-identifiers.sql.out index 81a98a60590..2c0fd9587c8 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/double-quoted-identifiers.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/double-quoted-identifiers.sql.out @@ -127,6 +127,22 @@ org.apache.spark.sql.catalyst.parser.ParseException } +-- !query +select 1 from "not_""exists" +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'\"not_\"\"exists\"'", + "hint" : "" + } +} + + -- !query SELECT 1 FROM `hello` -- !query schema diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/execute-immediate.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/execute-immediate.sql.out index 9249d7eb3e5..dd1207b4f2b 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/execute-immediate.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/execute-immediate.sql.out @@ -423,17 +423,39 @@ org.apache.spark.sql.AnalysisException -- !query -EXECUTE IMMEDIATE 'SELECT * FROM tbl_view WHERE ? = id' USING id +DECLARE OR REPLACE testvarA INT +-- !query schema +struct<> +-- !query output + + + +-- !query +EXECUTE IMMEDIATE 'SET VAR testVarA = 1' INTO testVarA -- !query schema struct<> -- !query output org.apache.spark.sql.AnalysisException { - "errorClass" : "UNRESOLVED_VARIABLE", - "sqlState" : "42883", + "errorClass" : "INVALID_STATEMENT_FOR_EXECUTE_INTO", + "sqlState" : "07501", + "messageParameters" : { + "sqlString" : "SET VAR TESTVARA = 1" + } +} + + +-- !query +EXECUTE IMMEDIATE 'SELECT * FROM tbl_view WHERE ? = id' USING id +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITHOUT_SUGGESTION", + "sqlState" : "42703", "messageParameters" : { - "searchPath" : "`system`.`session`", - "variableName" : "`id`" + "objectName" : "`id`" }, "queryContext" : [ { "objectType" : "", @@ -446,7 +468,7 @@ org.apache.spark.sql.AnalysisException -- !query -EXECUTE IMMEDIATE 'SELECT * FROM tbl_view where ? = id and :first = name' USING 1, 'name2' as first +EXECUTE IMMEDIATE 'SELECT * FROM tbl_view where ? = id and :first = name' USING 1 as x, 'name2' as first -- !query schema struct<> -- !query output @@ -457,6 +479,21 @@ org.apache.spark.sql.AnalysisException } +-- !query +EXECUTE IMMEDIATE 'SELECT * FROM tbl_view where :x = id and :first = name' USING 1, 'name2' as first +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "ALL_PARAMETERS_MUST_BE_NAMED", + "sqlState" : "07001", + "messageParameters" : { + "exprs" : "\"1\"" + } +} + + -- !query EXECUTE IMMEDIATE 'SELECT * FROM tbl_view where :first = name' USING 1, 'name2' as first -- !query schema @@ -486,11 +523,11 @@ org.apache.spark.sql.catalyst.parser.ParseException "hint" : "" }, "queryContext" : [ { - "objectType" : "", + "objectType" : "EXECUTE IMMEDIATE", "objectName" : "", "startIndex" : 1, - "stopIndex" : 28, - "fragment" : "EXECUTE IMMEDIATE 'SELCT Fa'" + "stopIndex" : 8, + "fragment" : "SELCT Fa" } ] } @@ -509,11 +546,11 @@ org.apache.spark.sql.catalyst.parser.ParseException "hint" : "" }, "queryContext" : [ { - "objectType" : "", + "objectType" : "EXECUTE IMMEDIATE", "objectName" : "", "startIndex" : 1, - "stopIndex" : 40, - "fragment" : "EXECUTE IMMEDIATE 'SELCT Fa' INTO res_id" + "stopIndex" : 8, + "fragment" : "SELCT Fa" } ] } @@ -525,10 +562,10 @@ struct<> -- !query output org.apache.spark.sql.AnalysisException { - "errorClass" : "INVALID_VARIABLE_TYPE_FOR_QUERY_EXECUTE_IMMEDIATE", + "errorClass" : "INVALID_EXPR_TYPE_FOR_QUERY_EXECUTE_IMMEDIATE", "sqlState" : "42K09", "messageParameters" : { - "varType" : "\"INT\"" + "exprType" : "\"INT\"" } } @@ -552,23 +589,9 @@ struct<> -- !query EXECUTE IMMEDIATE 'SELECT * from tbl_view where name = :first' USING CONCAT(a , "me1") as first -- !query schema -struct<> +struct>> -- !query output -org.apache.spark.sql.AnalysisException -{ - "errorClass" : "UNSUPPORTED_EXPR_FOR_PARAMETER", - "sqlState" : "42K0E", - "messageParameters" : { - "invalidExprSql" : "\"CONCAT(a, me1)\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 70, - "stopIndex" : 86, - "fragment" : "CONCAT(a , \"me1\")" - } ] -} +10 name1 {"f1":1,"s2":{"f2":101,"f3":"a"}} -- !query @@ -747,22 +770,38 @@ org.apache.spark.sql.AnalysisException -- !query -EXECUTE IMMEDIATE 'EXECUTE IMMEDIATE \'SELECT id FROM tbl_view WHERE id = ? USING 10\'' +EXECUTE IMMEDIATE 'EXECUTE IMMEDIATE \'SELECT id FROM tbl_view WHERE id = ?\' USING 10' +-- !query schema +struct +-- !query output +10 + + +-- !query +SET VAR sql_string = null +-- !query schema +struct<> +-- !query output + + + +-- !query +EXECUTE IMMEDIATE sql_string -- !query schema struct<> -- !query output org.apache.spark.sql.AnalysisException { - "errorClass" : "NESTED_EXECUTE_IMMEDIATE", - "sqlState" : "07501", + "errorClass" : "NULL_QUERY_STRING_EXECUTE_IMMEDIATE", + "sqlState" : "22004", "messageParameters" : { - "sqlString" : "EXECUTE IMMEDIATE 'SELECT ID FROM TBL_VIEW WHERE ID = ? USING 10'" + "varName" : "`sql_string`" } } -- !query -SET VAR sql_string = null +SET VAR sql_string = 5 -- !query schema struct<> -- !query output @@ -774,12 +813,169 @@ EXECUTE IMMEDIATE sql_string -- !query schema struct<> -- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'5'", + "hint" : "" + }, + "queryContext" : [ { + "objectType" : "EXECUTE IMMEDIATE", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 1, + "fragment" : "5" + } ] +} + + +-- !query +SET VAR sql_string = 'hello' +-- !query schema +struct<> +-- !query output + + + +-- !query +EXECUTE IMMEDIATE length(sql_string) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_EXPR_TYPE_FOR_QUERY_EXECUTE_IMMEDIATE", + "sqlState" : "42K09", + "messageParameters" : { + "exprType" : "\"INT\"" + } +} + + +-- !query +EXECUTE IMMEDIATE 'SELECT 42 where ? = :first' USING 1, 2 as first +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_QUERY_MIXED_QUERY_PARAMETERS", + "sqlState" : "42613" +} + + +-- !query +DECLARE int_var INT +-- !query schema +struct<> +-- !query output + + + +-- !query +SET VAR int_var = 42 +-- !query schema +struct<> +-- !query output + + + +-- !query +EXECUTE IMMEDIATE int_var +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_EXPR_TYPE_FOR_QUERY_EXECUTE_IMMEDIATE", + "sqlState" : "42K09", + "messageParameters" : { + "exprType" : "\"INT\"" + } +} + + +-- !query +DECLARE null_var STRING +-- !query schema +struct<> +-- !query output + + + +-- !query +SET VAR null_var = null +-- !query schema +struct<> +-- !query output + + + +-- !query +EXECUTE IMMEDIATE null_var +-- !query schema +struct<> +-- !query output org.apache.spark.sql.AnalysisException { "errorClass" : "NULL_QUERY_STRING_EXECUTE_IMMEDIATE", "sqlState" : "22004", "messageParameters" : { - "varName" : "`sql_string`" + "varName" : "`null_var`" + } +} + + +-- !query +EXECUTE IMMEDIATE 'SELECT ?' USING (SELECT 1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UNSUPPORTED_EXPR_FOR_PARAMETER", + "sqlState" : "42K0E", + "messageParameters" : { + "invalidExprSql" : "\"scalarsubquery()\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 36, + "stopIndex" : 45, + "fragment" : "(SELECT 1)" + } ] +} + + +-- !query +EXECUTE IMMEDIATE 'SELECT :first' USING 2, 3 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "ALL_PARAMETERS_MUST_BE_NAMED", + "sqlState" : "07001", + "messageParameters" : { + "exprs" : "\"2\", \"3\"" + } +} + + +-- !query +EXECUTE IMMEDIATE (SELECT c FROM (VALUES(1)) AS T(c)) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_EXPR_TYPE_FOR_QUERY_EXECUTE_IMMEDIATE", + "sqlState" : "42K09", + "messageParameters" : { + "exprType" : "\"INT\"" } } @@ -790,3 +986,272 @@ DROP TABLE x struct<> -- !query output + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING 5 AS p +-- !query schema +struct +-- !query output +int 5 + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING 5L AS p +-- !query schema +struct +-- !query output +bigint 5 + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING 5S AS p +-- !query schema +struct +-- !query output +smallint 5 + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING 5Y AS p +-- !query schema +struct +-- !query output +tinyint 5 + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING 3.14F AS p +-- !query schema +struct +-- !query output +float 3.14 + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING 3.14159D AS p +-- !query schema +struct +-- !query output +double 3.14159 + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING 123.45BD AS p +-- !query schema +struct +-- !query output +decimal(5,2) 123.45 + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING true AS p +-- !query schema +struct +-- !query output +boolean true + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING false AS p +-- !query schema +struct +-- !query output +boolean false + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING 'hello world' AS p +-- !query schema +struct +-- !query output +string hello world + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING 'it''s a test' AS p +-- !query schema +struct +-- !query output +string it's a test + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING DATE '2023-12-25' AS p +-- !query schema +struct +-- !query output +date 2023-12-25 + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING TIMESTAMP '2023-12-25 10:30:45' AS p +-- !query schema +struct +-- !query output +timestamp 2023-12-25 10:30:45 + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING TIMESTAMP_NTZ '2023-12-25 10:30:45' AS p +-- !query schema +struct +-- !query output +timestamp_ntz 2023-12-25 10:30:45 + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING CAST(NULL AS INT) AS p +-- !query schema +struct +-- !query output +int NULL + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING CAST(NULL AS STRING) AS p +-- !query schema +struct +-- !query output +string NULL + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, hex(:p) as val' USING X'010203FF' AS p +-- !query schema +struct +-- !query output +binary 010203FF + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING INTERVAL '3' DAY AS p +-- !query schema +struct +-- !query output +interval day 3 00:00:00.000000000 + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING INTERVAL '2' YEAR AS p +-- !query schema +struct +-- !query output +interval year 2-0 + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING INTERVAL '1-2' YEAR TO MONTH AS p +-- !query schema +struct +-- !query output +interval year to month 1-2 + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING INTERVAL '3 4:5:6' DAY TO SECOND AS p +-- !query schema +struct +-- !query output +interval day to second 3 04:05:06.000000000 + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING 999.999BD AS p +-- !query schema +struct +-- !query output +decimal(6,3) 999.999 + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p1) as type1, :p1 as val1, typeof(:p2) as type2, :p2 as val2' + USING 42 as p1, 'test string' as p2 +-- !query schema +struct +-- !query output +int 42 string test string + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING ARRAY(1, 2, 3) AS p +-- !query schema +struct> +-- !query output +array [1,2,3] + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING ARRAY('a', 'b', 'c') AS p +-- !query schema +struct> +-- !query output +array ["a","b","c"] + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING ARRAY(ARRAY(1, 2), ARRAY(3, 4)) AS p +-- !query schema +struct>> +-- !query output +array> [[1,2],[3,4]] + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING MAP('key1', 'value1', 'key2', 'value2') AS p +-- !query schema +struct> +-- !query output +map {"key1":"value1","key2":"value2"} + + +-- !query +EXECUTE IMMEDIATE 'SELECT typeof(:p) as type, :p as val' USING MAP(1, 'one', 2, 'two') AS p +-- !query schema +struct> +-- !query output +map {1:"one",2:"two"} + + +-- !query +EXECUTE IMMEDIATE 'SELECT :param' +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UNBOUND_SQL_PARAMETER", + "sqlState" : "42P02", + "messageParameters" : { + "name" : "param" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 13, + "fragment" : ":param" + } ] +} + + +-- !query +EXECUTE IMMEDIATE 'SELECT ?' +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UNBOUND_SQL_PARAMETER", + "sqlState" : "42P02", + "messageParameters" : { + "name" : "_7" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 8, + "fragment" : "?" + } ] +} diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/explain-aqe.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/explain-aqe.sql.out index 16077a78f38..f2df635a5a4 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/explain-aqe.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/explain-aqe.sql.out @@ -956,6 +956,50 @@ Output [4]: [key#x, max(val)#x, key#x, max(val)#x] Arguments: isFinalPlan=false +-- !query +EXPLAIN FORMATTED + WITH RECURSIVE r(level) AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r WHERE level < 9 + ) +SELECT * FROM r +-- !query schema +struct +-- !query output +== Physical Plan == +* Project (6) ++- UnionLoop (1) + :- LocalRelation (2) + +- Project (5) + +- Filter (4) + +- UnionLoopRef (3) + + +(1) UnionLoop +Loop id: xxxx +Output [1]: [col1#x] +Limit: None + +(2) LocalRelation +Arguments: [col1#x] + +(3) UnionLoopRef +Loop id: xxxx +Output [1]: [col1#x] +Accumulated: false + +(4) Filter +Arguments: (isnotnull(col1#x) AND (col1#x < 9)) + +(5) Project +Arguments: [(col1#x + 1) AS (level + 1)#x] + +(6) Project [codegen id : 1] +Output [1]: [col1#x AS level#x] +Input [1]: [col1#x] + + -- !query EXPLAIN FORMATTED CREATE VIEW explain_view AS @@ -1145,9 +1189,10 @@ struct == Analyzed Logical Plan == InsertIntoHadoopFsRelationCommand file:[not included in comparison]/{warehouse_dir}/explain_temp5, false, [val#x], Parquet, [path=file:[not included in comparison]/{warehouse_dir}/explain_temp5], Append, `spark_catalog`.`default`.`explain_temp5`, org.apache.spark.sql.execution.datasources.CatalogFileIndex(file:[not included in comparison]/{warehouse_dir}/explain_temp5), [key, val] -+- Project [key#x, val#x] - +- SubqueryAlias spark_catalog.default.explain_temp4 - +- Relation spark_catalog.default.explain_temp4[key#x,val#x] parquet ++- Project [key#x AS key#x, val#x AS val#x] + +- Project [key#x, val#x] + +- SubqueryAlias spark_catalog.default.explain_temp4 + +- Relation spark_catalog.default.explain_temp4[key#x,val#x] parquet == Optimized Logical Plan == InsertIntoHadoopFsRelationCommand file:[not included in comparison]/{warehouse_dir}/explain_temp5, false, [val#x], Parquet, [path=file:[not included in comparison]/{warehouse_dir}/explain_temp5], Append, `spark_catalog`.`default`.`explain_temp5`, org.apache.spark.sql.execution.datasources.CatalogFileIndex(file:[not included in comparison]/{warehouse_dir}/explain_temp5), [key, val] diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/explain.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/explain.sql.out index 9d25b829e03..221a323b01b 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/explain.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/explain.sql.out @@ -851,6 +851,50 @@ Join type: Inner Join condition: None +-- !query +EXPLAIN FORMATTED + WITH RECURSIVE r(level) AS ( + VALUES 0 + UNION ALL + SELECT level + 1 FROM r WHERE level < 9 + ) +SELECT * FROM r +-- !query schema +struct +-- !query output +== Physical Plan == +* Project (6) ++- UnionLoop (1) + :- LocalRelation (2) + +- Project (5) + +- Filter (4) + +- UnionLoopRef (3) + + +(1) UnionLoop +Loop id: xxxx +Output [1]: [col1#x] +Limit: None + +(2) LocalRelation +Arguments: [col1#x] + +(3) UnionLoopRef +Loop id: xxxx +Output [1]: [col1#x] +Accumulated: false + +(4) Filter +Arguments: (isnotnull(col1#x) AND (col1#x < 9)) + +(5) Project +Arguments: [(col1#x + 1) AS (level + 1)#x] + +(6) Project [codegen id : 1] +Output [1]: [col1#x AS level#x] +Input [1]: [col1#x] + + -- !query EXPLAIN FORMATTED CREATE VIEW explain_view AS @@ -1037,9 +1081,10 @@ struct == Analyzed Logical Plan == InsertIntoHadoopFsRelationCommand file:[not included in comparison]/{warehouse_dir}/explain_temp5, false, [val#x], Parquet, [path=file:[not included in comparison]/{warehouse_dir}/explain_temp5], Append, `spark_catalog`.`default`.`explain_temp5`, org.apache.spark.sql.execution.datasources.CatalogFileIndex(file:[not included in comparison]/{warehouse_dir}/explain_temp5), [key, val] -+- Project [key#x, val#x] - +- SubqueryAlias spark_catalog.default.explain_temp4 - +- Relation spark_catalog.default.explain_temp4[key#x,val#x] parquet ++- Project [key#x AS key#x, val#x AS val#x] + +- Project [key#x, val#x] + +- SubqueryAlias spark_catalog.default.explain_temp4 + +- Relation spark_catalog.default.explain_temp4[key#x,val#x] parquet == Optimized Logical Plan == InsertIntoHadoopFsRelationCommand file:[not included in comparison]/{warehouse_dir}/explain_temp5, false, [val#x], Parquet, [path=file:[not included in comparison]/{warehouse_dir}/explain_temp5], Append, `spark_catalog`.`default`.`explain_temp5`, org.apache.spark.sql.execution.datasources.CatalogFileIndex(file:[not included in comparison]/{warehouse_dir}/explain_temp5), [key, val] diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/extract-value-resolution-edge-cases.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/extract-value-resolution-edge-cases.sql.out new file mode 100644 index 00000000000..0565edc99b9 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/extract-value-resolution-edge-cases.sql.out @@ -0,0 +1,39 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +CREATE TABLE t1(col1 STRUCT, a STRING) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT col1.a, a FROM t1 ORDER BY a +-- !query schema +struct +-- !query output + + + +-- !query +SELECT col1.a, a FROM t1 ORDER BY col1.a +-- !query schema +struct +-- !query output + + + +-- !query +SELECT split(col1, '-')[1] AS a FROM VALUES('a-b') ORDER BY split(col1, '-')[1] +-- !query schema +struct +-- !query output +b + + +-- !query +DROP TABLE t1 +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/generators.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/generators.sql.out new file mode 100644 index 00000000000..c9f254612b4 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/generators.sql.out @@ -0,0 +1,1158 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +CREATE OR REPLACE TEMPORARY VIEW testData AS SELECT * FROM VALUES +(1, 1), (1, 2), (2, 1), (2, 2), (3, 1), (3, 2), (null, 1), (3, null), (null, null) +AS testData(a, b) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT explode(array(a, b)) AS elem FROM testData +-- !query schema +struct +-- !query output +1 +1 +1 +1 +1 +1 +2 +2 +2 +2 +2 +3 +3 +3 +NULL +NULL +NULL +NULL + + +-- !query +SELECT explode(array(a, b)) AS elem, 'Spark' FROM testData +-- !query schema +struct +-- !query output +1 Spark +1 Spark +1 Spark +1 Spark +1 Spark +1 Spark +2 Spark +2 Spark +2 Spark +2 Spark +2 Spark +3 Spark +3 Spark +3 Spark +NULL Spark +NULL Spark +NULL Spark +NULL Spark + + +-- !query +SELECT explode(array(a, b)) AS null, null FROM testData +-- !query schema +struct +-- !query output +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +2 NULL +2 NULL +2 NULL +2 NULL +2 NULL +3 NULL +3 NULL +3 NULL +NULL NULL +NULL NULL +NULL NULL +NULL NULL + + +-- !query +SELECT explode(array(1, 2)) AS null, null, 'column' +-- !query schema +struct +-- !query output +1 NULL column +2 NULL column + + +-- !query +SELECT explode(map(1, 'a', 2, 'b')) +-- !query schema +struct +-- !query output +1 a +2 b + + +-- !query +SELECT explode(struct(1, 'a', 2, 'b')) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"struct(1, a, 2, b)\"", + "inputType" : "\"STRUCT\"", + "paramIndex" : "first", + "requiredType" : "(\"ARRAY\" or \"MAP\")", + "sqlExpr" : "\"explode(struct(1, a, 2, b))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 38, + "fragment" : "explode(struct(1, 'a', 2, 'b'))" + } ] +} + + +-- !query +SELECT explode(1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"1\"", + "inputType" : "\"INT\"", + "paramIndex" : "first", + "requiredType" : "(\"ARRAY\" or \"MAP\")", + "sqlExpr" : "\"explode(1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 17, + "fragment" : "explode(1)" + } ] +} + + +-- !query +SELECT explode(null) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"NULL\"", + "inputType" : "\"VOID\"", + "paramIndex" : "first", + "requiredType" : "(\"ARRAY\" or \"MAP\")", + "sqlExpr" : "\"explode(NULL)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 20, + "fragment" : "explode(null)" + } ] +} + + +-- !query +SELECT explode(cast (null as array)) +-- !query schema +struct +-- !query output + + + +-- !query +SELECT explode_outer(array(a, b)) AS elem FROM testData +-- !query schema +struct +-- !query output +1 +1 +1 +1 +1 +1 +2 +2 +2 +2 +2 +3 +3 +3 +NULL +NULL +NULL +NULL + + +-- !query +SELECT explode_outer(array(a, b)) AS elem, 'Spark' FROM testData +-- !query schema +struct +-- !query output +1 Spark +1 Spark +1 Spark +1 Spark +1 Spark +1 Spark +2 Spark +2 Spark +2 Spark +2 Spark +2 Spark +3 Spark +3 Spark +3 Spark +NULL Spark +NULL Spark +NULL Spark +NULL Spark + + +-- !query +SELECT explode_outer(array(a, b)) AS null, null FROM testData +-- !query schema +struct +-- !query output +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +2 NULL +2 NULL +2 NULL +2 NULL +2 NULL +3 NULL +3 NULL +3 NULL +NULL NULL +NULL NULL +NULL NULL +NULL NULL + + +-- !query +SELECT explode_outer(array(1, 2)) AS null, null, 'column' +-- !query schema +struct +-- !query output +1 NULL column +2 NULL column + + +-- !query +SELECT explode_outer(map(1, 'a', 2, 'b')) +-- !query schema +struct +-- !query output +1 a +2 b + + +-- !query +SELECT explode_outer(struct(1, 'a', 2, 'b')) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"struct(1, a, 2, b)\"", + "inputType" : "\"STRUCT\"", + "paramIndex" : "first", + "requiredType" : "(\"ARRAY\" or \"MAP\")", + "sqlExpr" : "\"explode(struct(1, a, 2, b))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 44, + "fragment" : "explode_outer(struct(1, 'a', 2, 'b'))" + } ] +} + + +-- !query +SELECT explode_outer(1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"1\"", + "inputType" : "\"INT\"", + "paramIndex" : "first", + "requiredType" : "(\"ARRAY\" or \"MAP\")", + "sqlExpr" : "\"explode(1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 23, + "fragment" : "explode_outer(1)" + } ] +} + + +-- !query +SELECT explode_outer(null) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"NULL\"", + "inputType" : "\"VOID\"", + "paramIndex" : "first", + "requiredType" : "(\"ARRAY\" or \"MAP\")", + "sqlExpr" : "\"explode(NULL)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 26, + "fragment" : "explode_outer(null)" + } ] +} + + +-- !query +SELECT explode_outer(cast (null as array)) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT posexplode(array(a, b)) AS elem FROM testData +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UDTF_ALIAS_NUMBER_MISMATCH", + "sqlState" : "42802", + "messageParameters" : { + "aliasesNames" : "elem", + "aliasesSize" : "2" + } +} + + +-- !query +SELECT posexplode(array(a, b)) AS (elem, elem2) FROM testData +-- !query schema +struct +-- !query output +0 1 +0 1 +0 2 +0 2 +0 3 +0 3 +0 3 +0 NULL +0 NULL +1 1 +1 1 +1 1 +1 1 +1 2 +1 2 +1 2 +1 NULL +1 NULL + + +-- !query +SELECT posexplode(array(a, b)) AS (null, null) FROM testData +-- !query schema +struct +-- !query output +0 1 +0 1 +0 2 +0 2 +0 3 +0 3 +0 3 +0 NULL +0 NULL +1 1 +1 1 +1 1 +1 1 +1 2 +1 2 +1 2 +1 NULL +1 NULL + + +-- !query +SELECT posexplode(array(1, 2)) AS (null, null, column) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UDTF_ALIAS_NUMBER_MISMATCH", + "sqlState" : "42802", + "messageParameters" : { + "aliasesNames" : "null,null,column", + "aliasesSize" : "2" + } +} + + +-- !query +SELECT posexplode(map(1, 'a', 2, 'b')) +-- !query schema +struct +-- !query output +0 1 a +1 2 b + + +-- !query +SELECT posexplode(struct(1, 'a', 2, 'b')) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"struct(1, a, 2, b)\"", + "inputType" : "\"STRUCT\"", + "paramIndex" : "first", + "requiredType" : "(\"ARRAY\" or \"MAP\")", + "sqlExpr" : "\"posexplode(struct(1, a, 2, b))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 41, + "fragment" : "posexplode(struct(1, 'a', 2, 'b'))" + } ] +} + + +-- !query +SELECT posexplode(1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"1\"", + "inputType" : "\"INT\"", + "paramIndex" : "first", + "requiredType" : "(\"ARRAY\" or \"MAP\")", + "sqlExpr" : "\"posexplode(1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 20, + "fragment" : "posexplode(1)" + } ] +} + + +-- !query +SELECT posexplode(null) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"NULL\"", + "inputType" : "\"VOID\"", + "paramIndex" : "first", + "requiredType" : "(\"ARRAY\" or \"MAP\")", + "sqlExpr" : "\"posexplode(NULL)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 23, + "fragment" : "posexplode(null)" + } ] +} + + +-- !query +SELECT posexplode(cast (null as array)) +-- !query schema +struct +-- !query output + + + +-- !query +SELECT posexplode_outer(array(a, b)) AS elem FROM testData +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UDTF_ALIAS_NUMBER_MISMATCH", + "sqlState" : "42802", + "messageParameters" : { + "aliasesNames" : "elem", + "aliasesSize" : "2" + } +} + + +-- !query +SELECT posexplode_outer(array(a, b)) AS (elem, elem2) FROM testData +-- !query schema +struct +-- !query output +0 1 +0 1 +0 2 +0 2 +0 3 +0 3 +0 3 +0 NULL +0 NULL +1 1 +1 1 +1 1 +1 1 +1 2 +1 2 +1 2 +1 NULL +1 NULL + + +-- !query +SELECT posexplode_outer(array(a, b)) AS (null, null) FROM testData +-- !query schema +struct +-- !query output +0 1 +0 1 +0 2 +0 2 +0 3 +0 3 +0 3 +0 NULL +0 NULL +1 1 +1 1 +1 1 +1 1 +1 2 +1 2 +1 2 +1 NULL +1 NULL + + +-- !query +SELECT posexplode_outer(array(1, 2)) AS (null, null, column) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UDTF_ALIAS_NUMBER_MISMATCH", + "sqlState" : "42802", + "messageParameters" : { + "aliasesNames" : "null,null,column", + "aliasesSize" : "2" + } +} + + +-- !query +SELECT posexplode_outer(map(1, 'a', 2, 'b')) +-- !query schema +struct +-- !query output +0 1 a +1 2 b + + +-- !query +SELECT posexplode_outer(struct(1, 'a', 2, 'b')) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"struct(1, a, 2, b)\"", + "inputType" : "\"STRUCT\"", + "paramIndex" : "first", + "requiredType" : "(\"ARRAY\" or \"MAP\")", + "sqlExpr" : "\"posexplode(struct(1, a, 2, b))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 47, + "fragment" : "posexplode_outer(struct(1, 'a', 2, 'b'))" + } ] +} + + +-- !query +SELECT posexplode_outer(1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"1\"", + "inputType" : "\"INT\"", + "paramIndex" : "first", + "requiredType" : "(\"ARRAY\" or \"MAP\")", + "sqlExpr" : "\"posexplode(1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 26, + "fragment" : "posexplode_outer(1)" + } ] +} + + +-- !query +SELECT posexplode_outer(null) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"NULL\"", + "inputType" : "\"VOID\"", + "paramIndex" : "first", + "requiredType" : "(\"ARRAY\" or \"MAP\")", + "sqlExpr" : "\"posexplode(NULL)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 29, + "fragment" : "posexplode_outer(null)" + } ] +} + + +-- !query +SELECT posexplode_outer(cast (null as array)) +-- !query schema +struct +-- !query output +NULL NULL + + +-- !query +SELECT inline(array(struct(1, 'a'))) +-- !query schema +struct +-- !query output +1 a + + +-- !query +SELECT inline(array(struct(null, 'a'), struct(null, 'b'))) +-- !query schema +struct +-- !query output +NULL a +NULL b + + +-- !query +SELECT inline(array(struct(a, 'a'), struct(a, 'b'))) FROM testData +-- !query schema +struct +-- !query output +1 a +1 a +1 b +1 b +2 a +2 a +2 b +2 b +3 a +3 a +3 a +3 b +3 b +3 b +NULL a +NULL a +NULL b +NULL b + + +-- !query +SELECT inline(array(struct(a, 'a'), struct(b, 'b'))) FROM testData +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.DATA_DIFF_TYPES", + "sqlState" : "42K09", + "messageParameters" : { + "dataType" : "(\"STRUCT\" or \"STRUCT\")", + "functionName" : "`array`", + "sqlExpr" : "\"array(struct(a, a), struct(b, b))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 15, + "stopIndex" : 51, + "fragment" : "array(struct(a, 'a'), struct(b, 'b'))" + } ] +} + + +-- !query +SELECT inline(1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"1\"", + "inputType" : "\"INT\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"inline(1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 16, + "fragment" : "inline(1)" + } ] +} + + +-- !query +SELECT inline(array(1, 'a')) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"array(1, a)\"", + "inputType" : "\"ARRAY\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"inline(array(1, a))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 28, + "fragment" : "inline(array(1, 'a'))" + } ] +} + + +-- !query +SELECT inline(struct(1, 'a')) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"struct(1, a)\"", + "inputType" : "\"STRUCT\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"inline(struct(1, a))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 29, + "fragment" : "inline(struct(1, 'a'))" + } ] +} + + +-- !query +SELECT inline_outer(array(struct(1, 'a'))) +-- !query schema +struct +-- !query output +1 a + + +-- !query +SELECT inline_outer(array(struct(null, 'a'), struct(null, 'b'))) +-- !query schema +struct +-- !query output +NULL a +NULL b + + +-- !query +SELECT inline_outer(array(struct(a, 'a'), struct(a, 'b'))) FROM testData +-- !query schema +struct +-- !query output +1 a +1 a +1 b +1 b +2 a +2 a +2 b +2 b +3 a +3 a +3 a +3 b +3 b +3 b +NULL a +NULL a +NULL b +NULL b + + +-- !query +SELECT inline_outer(array(struct(a, 'a'), struct(b, 'b'))) FROM testData +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.DATA_DIFF_TYPES", + "sqlState" : "42K09", + "messageParameters" : { + "dataType" : "(\"STRUCT\" or \"STRUCT\")", + "functionName" : "`array`", + "sqlExpr" : "\"array(struct(a, a), struct(b, b))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 21, + "stopIndex" : 57, + "fragment" : "array(struct(a, 'a'), struct(b, 'b'))" + } ] +} + + +-- !query +SELECT inline_outer(1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"1\"", + "inputType" : "\"INT\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"inline(1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 22, + "fragment" : "inline_outer(1)" + } ] +} + + +-- !query +SELECT inline_outer(array(1, 'a')) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"array(1, a)\"", + "inputType" : "\"ARRAY\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"inline(array(1, a))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 34, + "fragment" : "inline_outer(array(1, 'a'))" + } ] +} + + +-- !query +SELECT inline_outer(struct(1, 'a')) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"struct(1, a)\"", + "inputType" : "\"STRUCT\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"inline(struct(1, a))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 35, + "fragment" : "inline_outer(struct(1, 'a'))" + } ] +} + + +-- !query +select json_tuple('{"a": 1, "b": 2}', 'a', 'b') +-- !query schema +struct +-- !query output +1 2 + + +-- !query +select json_tuple() +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "WRONG_NUM_ARGS.WITHOUT_SUGGESTION", + "sqlState" : "42605", + "messageParameters" : { + "actualNum" : "0", + "docroot" : "https://spark.apache.org/docs/latest", + "expectedNum" : "> 1", + "functionName" : "`json_tuple`" + } +} + + +-- !query +select json_tuple('{"a": 1}') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "WRONG_NUM_ARGS.WITHOUT_SUGGESTION", + "sqlState" : "42605", + "messageParameters" : { + "actualNum" : "1", + "docroot" : "https://spark.apache.org/docs/latest", + "expectedNum" : "> 1", + "functionName" : "`json_tuple`" + } +} + + +-- !query +select json_tuple('{"a": 1}', 1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.NON_STRING_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "funcName" : "`json_tuple`", + "sqlExpr" : "\"json_tuple({\"a\": 1}, 1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 32, + "fragment" : "json_tuple('{\"a\": 1}', 1)" + } ] +} + + +-- !query +select json_tuple('{"a": 1}', null) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.NON_STRING_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "funcName" : "`json_tuple`", + "sqlExpr" : "\"json_tuple({\"a\": 1}, NULL)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 35, + "fragment" : "json_tuple('{\"a\": 1}', null)" + } ] +} + + +-- !query +select stack(1, 1, 2, 3) +-- !query schema +struct +-- !query output +1 2 3 + + +-- !query +select stack(2, 1, 1.1, 'a', 2, 2.2, 'b') +-- !query schema +struct +-- !query output +1 1.1 a +2 2.2 b + + +-- !query +select stack(2, 1, 1.1, null, 2, null, 'b') +-- !query schema +struct +-- !query output +1 1.1 NULL +2 NULL b + + +-- !query +select stack() +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "WRONG_NUM_ARGS.WITHOUT_SUGGESTION", + "sqlState" : "42605", + "messageParameters" : { + "actualNum" : "0", + "docroot" : "https://spark.apache.org/docs/latest", + "expectedNum" : "> 1", + "functionName" : "`stack`" + } +} + + +-- !query +select stack(2, explode(array(1, 2, 3))) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UNSUPPORTED_GENERATOR.NESTED_IN_EXPRESSIONS", + "sqlState" : "42K0E", + "messageParameters" : { + "expression" : "\"stack(2, explode(array(1, 2, 3)))\"" + } +} diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/group-by-alias.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/group-by-alias.sql.out index fd740c88bc5..d5ba80a8f2f 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/group-by-alias.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/group-by-alias.sql.out @@ -287,6 +287,101 @@ struct 4 3 +-- !query +SELECT 1 AS a FROM testData GROUP BY `a` +-- !query schema +struct +-- !query output +1 +1 +1 +1 + + +-- !query +SELECT ( + WITH cte AS (SELECT 1) + SELECT * FROM cte +) AS subq1 +FROM + VALUES (1) +GROUP BY + subq1 +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT ( + SELECT a FROM testData LIMIT 1 +) AS subq1 +FROM + VALUES (1) +GROUP BY + subq1 +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT 111 AS abc GROUP BY 'a', abc +-- !query schema +struct +-- !query output +111 + + +-- !query +SELECT *, 111 AS abc FROM VALUES ('a', 'b', 'c') GROUP BY col1, col2, col3, abc +-- !query schema +struct +-- !query output +a b c 111 + + +-- !query +SELECT col1 as a, col2 AS a FROM values('a','b') GROUP BY col2, a +-- !query schema +struct +-- !query output +a b + + +-- !query +SELECT 1 AS a, 2 AS a FROM VALUES (1) t (a) GROUP BY a HAVING a > 1 ORDER BY a +-- !query schema +struct +-- !query output + + + +-- !query +SELECT 1 AS a, 2 AS a FROM VALUES (1) t (col1) GROUP BY a HAVING a > 1 ORDER BY a +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "AMBIGUOUS_REFERENCE", + "sqlState" : "42704", + "messageParameters" : { + "name" : "`a`", + "referenceNames" : "[`a`, `a`]" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 66, + "stopIndex" : 66, + "fragment" : "a" + } ] +} + + -- !query set spark.sql.groupByAliases=false -- !query schema @@ -372,3 +467,26 @@ struct 1 1 1 + + +-- !query +SELECT col1 AS a FROM VALUES (NAMED_STRUCT('f1', 1)) GROUP BY a.f1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`a`.`f1`", + "proposal" : "`col1`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 63, + "stopIndex" : 66, + "fragment" : "a.f1" + } ] +} diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/group-by-all.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/group-by-all.sql.out index bf3c1a3c21b..a82366ae4d1 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/group-by-all.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/group-by-all.sql.out @@ -288,3 +288,88 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException "fragment" : "non_exist" } ] } + + +-- !query +SELECT * FROM data GROUP BY ALL +-- !query schema +struct +-- !query output +China Hangzhou Wenchen 4 14.0 +China Shanghai Shanghaiese 5 15.0 +Korea Seoul Hyukjin 6 16.0 +UK London Sean 7 17.0 +USA Berkeley Xiao 3 13.0 +USA San Francisco Matei 2 12.0 +USA San Francisco Reynold 1 11.0 + + +-- !query +SELECT 4 AS a, 5 AS b, 6 AS c, * FROM data GROUP BY ALL +-- !query schema +struct +-- !query output +4 5 6 China Hangzhou Wenchen 4 14.0 +4 5 6 China Shanghai Shanghaiese 5 15.0 +4 5 6 Korea Seoul Hyukjin 6 16.0 +4 5 6 UK London Sean 7 17.0 +4 5 6 USA Berkeley Xiao 3 13.0 +4 5 6 USA San Francisco Matei 2 12.0 +4 5 6 USA San Francisco Reynold 1 11.0 + + +-- !query +SELECT *, 4 AS a, 5 AS b, 6 AS c FROM data GROUP BY ALL +-- !query schema +struct +-- !query output +China Hangzhou Wenchen 4 14.0 4 5 6 +China Shanghai Shanghaiese 5 15.0 4 5 6 +Korea Seoul Hyukjin 6 16.0 4 5 6 +UK London Sean 7 17.0 4 5 6 +USA Berkeley Xiao 3 13.0 4 5 6 +USA San Francisco Matei 2 12.0 4 5 6 +USA San Francisco Reynold 1 11.0 4 5 6 + + +-- !query +SELECT 4 AS a, 5 AS b, *, 6 AS c FROM data GROUP BY ALL +-- !query schema +struct +-- !query output +4 5 China Hangzhou Wenchen 4 14.0 6 +4 5 China Shanghai Shanghaiese 5 15.0 6 +4 5 Korea Seoul Hyukjin 6 16.0 6 +4 5 UK London Sean 7 17.0 6 +4 5 USA Berkeley Xiao 3 13.0 6 +4 5 USA San Francisco Matei 2 12.0 6 +4 5 USA San Francisco Reynold 1 11.0 6 + + +-- !query +SELECT ( + WITH cte AS (SELECT 1) + SELECT * FROM cte +) AS subq1 +FROM + VALUES (1) +GROUP BY + ALL +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT ( + SELECT country FROM data LIMIT 1 +) AS subq1 +FROM + VALUES (1) +GROUP BY + ALL +-- !query schema +struct +-- !query output +USA diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/group-by-ordinal.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/group-by-ordinal.sql.out index 0f29c27268c..e13c4b13899 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/group-by-ordinal.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/group-by-ordinal.sql.out @@ -508,6 +508,35 @@ org.apache.spark.sql.AnalysisException } +-- !query +SELECT ( + WITH cte AS (SELECT 1) + SELECT * FROM cte +) AS subq1 +FROM + VALUES (1) +GROUP BY + 1 +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT ( + SELECT a FROM data LIMIT 1 +) AS subq1 +FROM + VALUES (1) +GROUP BY + 1 +-- !query schema +struct +-- !query output +1 + + -- !query set spark.sql.groupByOrdinal=false -- !query schema diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/group-by.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/group-by.sql.out index 8608dbef843..a86cab00250 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/group-by.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/group-by.sql.out @@ -9,6 +9,14 @@ struct<> +-- !query +CREATE TABLE t1(col1 TIMESTAMP, col2 STRING) +-- !query schema +struct<> +-- !query output + + + -- !query SELECT a, COUNT(b) FROM testData -- !query schema @@ -1170,3 +1178,101 @@ struct -- !query output 1 2 + + +-- !query +SELECT col1 FROM t1 GROUP BY ALL HAVING first(col2) = 'a' +-- !query schema +struct +-- !query output + + + +-- !query +SELECT col1 FROM t1 GROUP BY col1 HAVING EXISTS (SELECT first(t1.col2) == 0) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.CORRELATED_REFERENCE", + "sqlState" : "0A000", + "messageParameters" : { + "sqlExprs" : "\"(first(col2) = 0) AS `(first(outer(spark_catalog.default.t1.col2)) = 0)`\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 50, + "stopIndex" : 75, + "fragment" : "SELECT first(t1.col2) == 0" + } ] +} + + +-- !query +SELECT col1 FROM t1 GROUP BY ALL HAVING last(col2) = 'a' +-- !query schema +struct +-- !query output + + + +-- !query +SELECT col1 FROM t1 GROUP BY col1 HAVING EXISTS (SELECT last(t1.col2) == 0) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.CORRELATED_REFERENCE", + "sqlState" : "0A000", + "messageParameters" : { + "sqlExprs" : "\"(last(col2) = 0) AS `(last(outer(spark_catalog.default.t1.col2)) = 0)`\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 50, + "stopIndex" : 74, + "fragment" : "SELECT last(t1.col2) == 0" + } ] +} + + +-- !query +SELECT col1 FROM t1 GROUP BY ALL HAVING any_value(col2) = 'a' +-- !query schema +struct +-- !query output + + + +-- !query +SELECT col1 FROM t1 GROUP BY col1 HAVING EXISTS (SELECT any_value(t1.col2) == 0) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.CORRELATED_REFERENCE", + "sqlState" : "0A000", + "messageParameters" : { + "sqlExprs" : "\"(any_value(col2) = 0) AS `(any_value(outer(spark_catalog.default.t1.col2)) = 0)`\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 50, + "stopIndex" : 79, + "fragment" : "SELECT any_value(t1.col2) == 0" + } ] +} + + +-- !query +DROP TABLE t1 +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/grouping_set.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/grouping_set.sql.out index 5849acd094f..21e70c63535 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/grouping_set.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/grouping_set.sql.out @@ -39,6 +39,37 @@ NULL NULL 6 1 NULL NULL 9 1 +-- !query +SELECT a, b, c, d FROM grouping GROUP BY GROUPING SETS (a, b, c, d) +-- !query schema +struct +-- !query output +1 NULL NULL NULL +4 NULL NULL NULL +7 NULL NULL NULL +NULL 2 NULL NULL +NULL 5 NULL NULL +NULL 8 NULL NULL +NULL NULL 3 NULL +NULL NULL 6 NULL +NULL NULL 9 NULL +NULL NULL NULL 1 + + +-- !query +SELECT a, b FROM grouping GROUP BY GROUPING SETS (a, b, d + 1) ORDER BY `(d + 1)` +-- !query schema +struct +-- !query output +NULL 2 +1 NULL +NULL 5 +NULL 8 +4 NULL +7 NULL +NULL NULL + + -- !query SELECT c1, sum(c2) FROM (VALUES ('x', 10, 0), ('y', 20, 0)) AS t (c1, c2, c3) GROUP BY GROUPING SETS (c1) -- !query schema diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/having-and-order-by-recursive-type-name-resolution.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/having-and-order-by-recursive-type-name-resolution.sql.out new file mode 100644 index 00000000000..f685076f9f3 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/having-and-order-by-recursive-type-name-resolution.sql.out @@ -0,0 +1,429 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +SELECT 'a' AS col1 FROM VALUES (NAMED_STRUCT('a', 1)) t (col1) GROUP BY col1 ORDER BY col1.a +-- !query schema +struct +-- !query output +a + + +-- !query +SELECT 'a' AS col1 FROM VALUES (NAMED_STRUCT('a', 1)) t (col1) GROUP BY col1 HAVING col1.a > 0 +-- !query schema +struct +-- !query output +a + + +-- !query +SELECT 'a' AS col1 FROM VALUES (NAMED_STRUCT('a', 1)) t (col1) GROUP BY col1 HAVING col1.a > 0 ORDER BY col1.a +-- !query schema +struct +-- !query output +a + + +-- !query +SELECT NAMED_STRUCT('a', 1) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 ORDER BY col1.a +-- !query schema +struct> +-- !query output +{"a":1} + + +-- !query +SELECT NAMED_STRUCT('a', 1) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 HAVING col1.a > 0 +-- !query schema +struct> +-- !query output +{"a":1} + + +-- !query +SELECT NAMED_STRUCT('a', 1) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 HAVING col1.a > 0 ORDER BY col1.a +-- !query schema +struct> +-- !query output +{"a":1} + + +-- !query +SELECT NAMED_STRUCT('a', 1) AS col1 FROM VALUES (NAMED_STRUCT('a', 0)) t (col1) GROUP BY col1 ORDER BY col1.a +-- !query schema +struct> +-- !query output +{"a":1} + + +-- !query +SELECT NAMED_STRUCT('a', 1) AS col1 FROM VALUES (NAMED_STRUCT('a', 0)) t (col1) GROUP BY col1 HAVING col1.a > 0 +-- !query schema +struct> +-- !query output + + + +-- !query +SELECT NAMED_STRUCT('a', 1) AS col1 FROM VALUES (NAMED_STRUCT('a', 0)) t (col1) GROUP BY col1 HAVING col1.a > 0 ORDER BY col1.a +-- !query schema +struct> +-- !query output + + + +-- !query +SELECT 'a' AS col1 FROM VALUES (ARRAY(1)) t (col1) GROUP BY col1 ORDER BY col1[0] +-- !query schema +struct +-- !query output +a + + +-- !query +SELECT 'a' AS col1 FROM VALUES (ARRAY(1)) t (col1) GROUP BY col1 HAVING col1[0] > 0 +-- !query schema +struct +-- !query output +a + + +-- !query +SELECT 'a' AS col1 FROM VALUES (ARRAY(1)) t (col1) GROUP BY col1 HAVING col1[0] > 0 ORDER BY col1[0] +-- !query schema +struct +-- !query output +a + + +-- !query +SELECT ARRAY(1) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 ORDER BY col1[0] +-- !query schema +struct> +-- !query output +[1] + + +-- !query +SELECT ARRAY(1) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 HAVING col1[0] > 0 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_EXTRACT_BASE_FIELD_TYPE", + "sqlState" : "42000", + "messageParameters" : { + "base" : "\"tempresolvedcolumn(col1)\"", + "other" : "\"STRING\"" + } +} + + +-- !query +SELECT NAMED_STRUCT('a', NAMED_STRUCT('b', 1)) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 ORDER BY col1.a.b +-- !query schema +struct>> +-- !query output +{"a":{"b":1}} + + +-- !query +SELECT NAMED_STRUCT('a', NAMED_STRUCT('b', 1)) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 HAVING col1.a.b > 0 +-- !query schema +struct>> +-- !query output +{"a":{"b":1}} + + +-- !query +SELECT NAMED_STRUCT('a', NAMED_STRUCT('b', 1)) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 HAVING col1.a.b > 0 ORDER BY col1.a.b +-- !query schema +struct>> +-- !query output +{"a":{"b":1}} + + +-- !query +SELECT ARRAY(NAMED_STRUCT('a', 1)) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 ORDER BY col1[0].a +-- !query schema +struct>> +-- !query output +[{"a":1}] + + +-- !query +SELECT ARRAY(NAMED_STRUCT('a', 1)) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 HAVING col1[0].a > 0 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_EXTRACT_BASE_FIELD_TYPE", + "sqlState" : "42000", + "messageParameters" : { + "base" : "\"tempresolvedcolumn(col1)\"", + "other" : "\"STRING\"" + } +} + + +-- !query +SELECT 'a' AS col1 FROM VALUES (MAP('key', 1)) t (col1) GROUP BY col1 ORDER BY col1['key'] +-- !query schema +struct +-- !query output +a + + +-- !query +SELECT 'a' AS col1 FROM VALUES (MAP('key', 1)) t (col1) GROUP BY col1 HAVING col1['key'] > 0 +-- !query schema +struct +-- !query output +a + + +-- !query +SELECT 'a' AS col1 FROM VALUES (MAP('key', 1)) t (col1) GROUP BY col1 HAVING col1['key'] > 0 ORDER BY col1['key'] +-- !query schema +struct +-- !query output +a + + +-- !query +SELECT MAP('key', 1) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 ORDER BY col1['key'] +-- !query schema +struct> +-- !query output +{"key":1} + + +-- !query +SELECT MAP('key', 1) AS col1 FROM VALUES ('a') t (col1) GROUP BY col1 HAVING col1['key'] > 0 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_EXTRACT_BASE_FIELD_TYPE", + "sqlState" : "42000", + "messageParameters" : { + "base" : "\"tempresolvedcolumn(col1)\"", + "other" : "\"STRING\"" + } +} + + +-- !query +SELECT named_struct('a',1) as col, col1 +FROM values(named_struct('a',1)) +ORDER BY col1.a +-- !query schema +struct,col1:struct> +-- !query output +{"a":1} {"a":1} + + +-- !query +SELECT named_struct('a', 1) AS col1, col1 +FROM values(named_struct('a', 1)) +GROUP BY col1 +HAVING col1.a > 0 +-- !query schema +struct,col1:struct> +-- !query output +{"a":1} {"a":1} + + +-- !query +SELECT array(1, 2, 3) AS col1, col1 +FROM values(array(1, 2, 3)) +ORDER BY col1[0] +-- !query schema +struct,col1:array> +-- !query output +[1,2,3] [1,2,3] + + +-- !query +SELECT array(1, 2, 3) AS col1, col1 +FROM values(array(1, 2, 3)) +GROUP BY col1 +HAVING col1[1] > 1 +-- !query schema +struct,col1:array> +-- !query output +[1,2,3] [1,2,3] + + +-- !query +SELECT map('a', 1, 'b', 2) AS col1, col1 +FROM values(map('a', 1, 'b', 2)) +ORDER BY col1['a'] +-- !query schema +struct,col1:map> +-- !query output +{"a":1,"b":2} {"a":1,"b":2} + + +-- !query +SELECT map('a', 1, 'b', 2) AS col1, col1 +FROM values(map('a', 1, 'b', 2)) +GROUP BY col1 +HAVING col1['b'] > 1 +-- !query schema +struct,col1:map> +-- !query output +{"a":1,"b":2} {"a":1,"b":2} + + +-- !query +SELECT NAMED_STRUCT('b', 1) AS col1 FROM VALUES (NAMED_STRUCT('a', 0)) t (col1) GROUP BY col1 ORDER BY col1.a +-- !query schema +struct> +-- !query output +{"b":1} + + +-- !query +SELECT NAMED_STRUCT('b', 1) AS col1 FROM VALUES (NAMED_STRUCT('a', 0)) t (col1) GROUP BY col1 HAVING col1.a > 0 +-- !query schema +struct> +-- !query output + + + +-- !query +SELECT NAMED_STRUCT('b', 1) AS col1 FROM VALUES (NAMED_STRUCT('a', 0)) t (col1) GROUP BY col1 HAVING col1.a > 0 ORDER BY col1.a +-- !query schema +struct> +-- !query output + + + +-- !query +SELECT NAMED_STRUCT('b', 1) AS col1 FROM VALUES (NAMED_STRUCT('a', 0)) t (col1) GROUP BY col1 ORDER BY col1.b +-- !query schema +struct> +-- !query output +{"b":1} + + +-- !query +SELECT NAMED_STRUCT('b', 1) AS col1 FROM VALUES (NAMED_STRUCT('a', 0)) t (col1) GROUP BY col1 HAVING col1.b > 0 +-- !query schema +struct> +-- !query output +{"b":1} + + +-- !query +SELECT NAMED_STRUCT('b', 1) AS col1 FROM VALUES (NAMED_STRUCT('a', 0)) t (col1) GROUP BY col1 HAVING col1.b > 0 ORDER BY col1.b +-- !query schema +struct> +-- !query output +{"b":1} + + +-- !query +SELECT col1.name +FROM VALUES (NAMED_STRUCT('name', 'test', 'id', 1)) t (col1) +GROUP BY col1 +HAVING col1.id > 0 +ORDER BY col1.name +-- !query schema +struct +-- !query output +test + + +-- !query +SELECT col1.items[0] +FROM VALUES (NAMED_STRUCT('items', ARRAY(1, 2, 3))) t (col1) +GROUP BY col1 +HAVING col1.items[0] > 0 +ORDER BY col1.items[0] +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT col1.data['key'] +FROM VALUES (NAMED_STRUCT('data', MAP('key', 'value', 'num', '42'))) t (col1) +GROUP BY col1 +HAVING col1.data['num'] IS NOT NULL +ORDER BY col1.data['key'] +-- !query schema +struct +-- !query output +value + + +-- !query +SELECT col1.users[0].name +FROM VALUES ( + NAMED_STRUCT('users', ARRAY(NAMED_STRUCT('name', 'John', 'age', 30))) + ) t (col1) +GROUP BY col1 +HAVING col1.users[0].age > 25 +ORDER BY col1.users[0].name +-- !query schema +struct +-- !query output +John + + +-- !query +SELECT col1.person.address.city +FROM VALUES ( + NAMED_STRUCT('person', NAMED_STRUCT('address', NAMED_STRUCT('city', 'NYC', 'zip', 10001))) + ) t (col1) +GROUP BY col1 +HAVING col1.person.address.zip > 10000 +ORDER BY col1.person.address.city +-- !query schema +struct +-- !query output +NYC + + +-- !query +SELECT col1.matrix[0][1] +FROM VALUES ( + NAMED_STRUCT('matrix', ARRAY(ARRAY(1, 2), ARRAY(3, 4))) + ) t (col1) +GROUP BY col1 +HAVING col1.matrix[0][0] < 5 +ORDER BY col1.matrix[0][1] +-- !query schema +struct +-- !query output +2 + + +-- !query +SELECT col1.data[0].props['status'] +FROM VALUES ( + NAMED_STRUCT('data', ARRAY(NAMED_STRUCT('props', MAP('status', 'active')))) + ) t (col1) +GROUP BY col1 +HAVING col1.data[0].props['status'] = 'active' +-- !query schema +struct +-- !query output +active + + +-- !query +SELECT col1.nums[0] + col1.nums[1] AS sum_val +FROM VALUES (NAMED_STRUCT('nums', ARRAY(10, 20))) t (col1) +GROUP BY col1 +HAVING col1.nums[0] + col1.nums[1] > 25 +ORDER BY col1.nums[0] +-- !query schema +struct +-- !query output +30 diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/having.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/having.sql.out index c9d58864263..63467a76c89 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/having.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/having.sql.out @@ -152,3 +152,302 @@ struct -- !query output one 6 three 3 + + +-- !query +SELECT sum(v) FROM hav HAVING avg(try_add(v, 1)) = 1 +-- !query schema +struct +-- !query output + + + +-- !query +SELECT sum(v) FROM hav HAVING sum(try_add(v, 1)) = 1 +-- !query schema +struct +-- !query output + + + +-- !query +SELECT sum(v) FROM hav HAVING sum(ifnull(v, 1)) = 1 +-- !query schema +struct +-- !query output + + + +-- !query +SELECT sum(v) FROM hav GROUP BY ALL HAVING sum(ifnull(v, 1)) = 1 +-- !query schema +struct +-- !query output + + + +-- !query +SELECT sum(v) FROM hav GROUP BY v HAVING sum(ifnull(v, 1)) = 1 +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT v + 1 FROM hav GROUP BY ALL HAVING avg(try_add(v, 1)) = 1 +-- !query schema +struct<(v + 1):int> +-- !query output + + + +-- !query +SELECT v + 1 FROM hav GROUP BY ALL HAVING avg(try_add(v, 1) + 1) = 1 +-- !query schema +struct<(v + 1):int> +-- !query output + + + +-- !query +SELECT sum(v) FROM hav GROUP BY ifnull(v, 1) + 1 order by ifnull(v, 1) + 1 +-- !query schema +struct +-- !query output +1 +2 +3 +5 + + +-- !query +SELECT 1 AS `2`, 2 FROM VALUES (2) t (`2`) GROUP BY `2` HAVING `2` > 2 +-- !query schema +struct<2:int,2:int> +-- !query output + + + +-- !query +SELECT 2, 1 AS `2` FROM VALUES (2) t (`2`) GROUP BY `2` HAVING `2` > 2 +-- !query schema +struct<2:int,2:int> +-- !query output + + + +-- !query +SELECT 1 AS `2` FROM VALUES (2) t (`2`) GROUP BY `2` HAVING `2` > 2 +-- !query schema +struct<2:int> +-- !query output + + + +-- !query +SELECT 2 FROM VALUES (2) t (`2`) GROUP BY `2` HAVING `2` > 2 +-- !query schema +struct<2:int> +-- !query output + + + +-- !query +SELECT SUM(v) + 1 FROM hav HAVING SUM(v) + 1 +-- !query schema +struct<(sum(v) + 1):bigint> +-- !query output +12 + + +-- !query +SELECT 1 + SUM(v) FROM hav HAVING SUM(v) + 1 +-- !query schema +struct<(1 + sum(v)):bigint> +-- !query output +12 + + +-- !query +SELECT SUM(v) + 1 FROM hav HAVING 1 + SUM(v) +-- !query schema +struct<(sum(v) + 1):bigint> +-- !query output +12 + + +-- !query +SELECT MAX(v) + SUM(v) FROM hav HAVING SUM(v) + MAX(v) +-- !query schema +struct<(max(v) + sum(v)):bigint> +-- !query output +16 + + +-- !query +SELECT SUM(v) + 1 + MIN(v) FROM hav HAVING 1 + 1 + 1 + MIN(v) + 1 + SUM(v) +-- !query schema +struct<((sum(v) + 1) + min(v)):bigint> +-- !query output +13 + + +-- !query +SELECT col1 AS alias +FROM values(1) +GROUP BY col1 +HAVING ( + SELECT col1 = 1 +) +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT col1 AS alias +FROM values(named_struct('a', 1)) +GROUP BY col1 +HAVING ( + SELECT col1.a = 1 +) +-- !query schema +struct> +-- !query output +{"a":1} + + +-- !query +SELECT col1 AS alias +FROM values(array(1)) +GROUP BY col1 +HAVING ( + SELECT col1[0] = 1 +) +-- !query schema +struct> +-- !query output +[1] + + +-- !query +SELECT col1 AS alias +FROM values(map('a', 1)) +GROUP BY col1 +HAVING ( + SELECT col1[0] = 1 +) +-- !query schema +struct> +-- !query output + + + +-- !query +SELECT col1 FROM VALUES(1,2) GROUP BY col1, col2 HAVING col2 = col2 +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT col1 AS a, a AS b FROM VALUES(1,2) GROUP BY col1, col2 HAVING col2 = col2 +-- !query schema +struct +-- !query output +1 1 + + +-- !query +SELECT col1, col1 AS a FROM VALUES(1) GROUP BY col1 HAVING col1 > 0 +-- !query schema +struct +-- !query output +1 1 + + +-- !query +SELECT col1 AS a, col1 FROM VALUES(1) GROUP BY col1 HAVING col1 > 0 +-- !query schema +struct +-- !query output +1 1 + + +-- !query +SELECT make_date(col1, col2, col3) AS a, a AS b FROM VALUES(1,2,3) GROUP BY make_date(col1, col2, col3) HAVING make_date(col1, col2, col3) > '2025-01-01' +-- !query schema +struct +-- !query output + + + +-- !query +SELECT 1 AS a, 1 / a AS b, ZEROIFNULL(SUM(col1)) FROM VALUES(1) GROUP BY 1 HAVING ZEROIFNULL(SUM(col1)) > 0 +-- !query schema +struct +-- !query output +1 1.0 1 + + +-- !query +SELECT col1 AS a, SUM(col2) AS b, CASE WHEN col1 = 1 THEN 1 END AS c FROM VALUES(1,2) GROUP BY col1 HAVING CASE WHEN col1 = 1 THEN 1 END = 1 +-- !query schema +struct +-- !query output +1 2 1 + + +-- !query +SELECT col1 FROM VALUES(1,2) GROUP BY col1 HAVING MAX(col2) == (SELECT 1 WHERE MAX(col2) = 1) +-- !query schema +struct +-- !query output + + + +-- !query +SELECT col1 FROM VALUES(1,2) GROUP BY col1 HAVING (SELECT 1 WHERE MAX(col2) = 1) == MAX(col2) +-- !query schema +struct +-- !query output + + + +-- !query +SELECT col1 FROM VALUES(1,2) GROUP BY col1 HAVING (SELECT 1 WHERE MAX(col2) = 1) == (SELECT 1 WHERE MAX(col2) = 1) +-- !query schema +struct +-- !query output + + + +-- !query +SELECT col1 FROM VALUES(1,2) GROUP BY col1 HAVING bool_or(col2 = 1) AND bool_or(col2 = 1) +-- !query schema +struct +-- !query output + + + +-- !query +SELECT 1 GROUP BY COALESCE(1, 1) HAVING COALESCE(1, 1) = 1 OR COALESCE(1, 1) IS NOT NULL +-- !query schema +struct<1:int> +-- !query output +1 + + +-- !query +SELECT col1 FROM VALUES (1) t1 GROUP BY col1 HAVING ( + SELECT MAX(t2.col1) FROM VALUES (1) t2 WHERE t2.col1 == MAX(t1.col1) GROUP BY t2.col1 HAVING ( + SELECT t3.col1 FROM VALUES (1) t3 WHERE t3.col1 == MAX(t2.col1) + ) +) +-- !query schema +struct +-- !query output +1 diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/higher-order-functions.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/higher-order-functions.sql.out index 7bfc35a61e0..b16bbcda2eb 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/higher-order-functions.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/higher-order-functions.sql.out @@ -348,3 +348,837 @@ select aggregate(split('abcdefgh',''), array(array('')), (acc, x) -> array(array struct>> -- !query output [["h"]] + + +-- !query +select aggregate(array(1, 2, 3), 0, 100) as aggregate_int_literal +-- !query schema +struct +-- !query output +100 + + +-- !query +select aggregate(array(1, 2, 3), map(), map('result', 999)) as aggregate_map_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(map(result, 999), namedlambdavariable(), namedlambdavariable())\"", + "inputType" : "\"MAP\"", + "paramIndex" : "third", + "requiredType" : "\"MAP\"", + "sqlExpr" : "\"aggregate(array(1, 2, 3), map(), lambdafunction(map(result, 999), namedlambdavariable(), namedlambdavariable()), lambdafunction(namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 59, + "fragment" : "aggregate(array(1, 2, 3), map(), map('result', 999))" + } ] +} + + +-- !query +select aggregate(array(1, 2, 3), struct('init', 0), struct('final', 999)) as aggregate_struct_literal +-- !query schema +struct> +-- !query output +{"col1":"final","col2":999} + + +-- !query +select aggregate(array(1, 2, 3), array(), array('result')) as aggregate_array_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(array(result), namedlambdavariable(), namedlambdavariable())\"", + "inputType" : "\"ARRAY\"", + "paramIndex" : "third", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"aggregate(array(1, 2, 3), array(), lambdafunction(array(result), namedlambdavariable(), namedlambdavariable()), lambdafunction(namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 58, + "fragment" : "aggregate(array(1, 2, 3), array(), array('result'))" + } ] +} + + +-- !query +select array_sort(array(3, 1, 2), 1) as array_sort_int_literal +-- !query schema +struct> +-- !query output +[3,1,2] + + +-- !query +select array_sort(array(3, 1, 2), map('compare', 0)) as array_sort_map_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_RETURN_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "actualType" : "\"MAP\"", + "expectedType" : "\"INT\"", + "functionName" : "`lambdafunction`", + "sqlExpr" : "\"array_sort(array(3, 1, 2), lambdafunction(map(compare, 0), namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 52, + "fragment" : "array_sort(array(3, 1, 2), map('compare', 0))" + } ] +} + + +-- !query +select array_sort(array(3, 1, 2), struct('result', 0)) as array_sort_struct_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_RETURN_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "actualType" : "\"STRUCT\"", + "expectedType" : "\"INT\"", + "functionName" : "`lambdafunction`", + "sqlExpr" : "\"array_sort(array(3, 1, 2), lambdafunction(struct(result, 0), namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 54, + "fragment" : "array_sort(array(3, 1, 2), struct('result', 0))" + } ] +} + + +-- !query +select array_sort(array(3, 1, 2), array(0)) as array_sort_array_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_RETURN_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "actualType" : "\"ARRAY\"", + "expectedType" : "\"INT\"", + "functionName" : "`lambdafunction`", + "sqlExpr" : "\"array_sort(array(3, 1, 2), lambdafunction(array(0), namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 43, + "fragment" : "array_sort(array(3, 1, 2), array(0))" + } ] +} + + +-- !query +select exists(array(1, 2, 3), 1) as exists_int_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(1, namedlambdavariable())\"", + "inputType" : "\"INT\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"exists(array(1, 2, 3), lambdafunction(1, namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 32, + "fragment" : "exists(array(1, 2, 3), 1)" + } ] +} + + +-- !query +select exists(array(1, 2, 3), map('found', true)) as exists_map_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(map(found, true), namedlambdavariable())\"", + "inputType" : "\"MAP\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"exists(array(1, 2, 3), lambdafunction(map(found, true), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 49, + "fragment" : "exists(array(1, 2, 3), map('found', true))" + } ] +} + + +-- !query +select exists(array(1, 2, 3), struct('exists', true)) as exists_struct_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(struct(exists, true), namedlambdavariable())\"", + "inputType" : "\"STRUCT\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"exists(array(1, 2, 3), lambdafunction(struct(exists, true), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 53, + "fragment" : "exists(array(1, 2, 3), struct('exists', true))" + } ] +} + + +-- !query +select exists(array(1, 2, 3), array(true)) as exists_array_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(array(true), namedlambdavariable())\"", + "inputType" : "\"ARRAY\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"exists(array(1, 2, 3), lambdafunction(array(true), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 42, + "fragment" : "exists(array(1, 2, 3), array(true))" + } ] +} + + +-- !query +select filter(array(1, 2, 3), 1) as filter_int_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(1, namedlambdavariable())\"", + "inputType" : "\"INT\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"filter(array(1, 2, 3), lambdafunction(1, namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 32, + "fragment" : "filter(array(1, 2, 3), 1)" + } ] +} + + +-- !query +select filter(array(1, 2, 3), map('key', 'value')) as filter_map_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(map(key, value), namedlambdavariable())\"", + "inputType" : "\"MAP\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"filter(array(1, 2, 3), lambdafunction(map(key, value), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 50, + "fragment" : "filter(array(1, 2, 3), map('key', 'value'))" + } ] +} + + +-- !query +select filter(array(1, 2, 3), struct('valid', true)) as filter_struct_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(struct(valid, true), namedlambdavariable())\"", + "inputType" : "\"STRUCT\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"filter(array(1, 2, 3), lambdafunction(struct(valid, true), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 52, + "fragment" : "filter(array(1, 2, 3), struct('valid', true))" + } ] +} + + +-- !query +select filter(array(1, 2, 3), array(true, false)) as filter_array_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(array(true, false), namedlambdavariable())\"", + "inputType" : "\"ARRAY\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"filter(array(1, 2, 3), lambdafunction(array(true, false), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 49, + "fragment" : "filter(array(1, 2, 3), array(true, false))" + } ] +} + + +-- !query +select forall(array(1, 2, 3), 1) as forall_int_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(1, namedlambdavariable())\"", + "inputType" : "\"INT\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"forall(array(1, 2, 3), lambdafunction(1, namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 32, + "fragment" : "forall(array(1, 2, 3), 1)" + } ] +} + + +-- !query +select forall(array(1, 2, 3), map('all', true)) as forall_map_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(map(all, true), namedlambdavariable())\"", + "inputType" : "\"MAP\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"forall(array(1, 2, 3), lambdafunction(map(all, true), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 47, + "fragment" : "forall(array(1, 2, 3), map('all', true))" + } ] +} + + +-- !query +select forall(array(1, 2, 3), struct('all', true)) as forall_struct_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(struct(all, true), namedlambdavariable())\"", + "inputType" : "\"STRUCT\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"forall(array(1, 2, 3), lambdafunction(struct(all, true), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 50, + "fragment" : "forall(array(1, 2, 3), struct('all', true))" + } ] +} + + +-- !query +select forall(array(1, 2, 3), array(true, true)) as forall_array_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(array(true, true), namedlambdavariable())\"", + "inputType" : "\"ARRAY\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"forall(array(1, 2, 3), lambdafunction(array(true, true), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 48, + "fragment" : "forall(array(1, 2, 3), array(true, true))" + } ] +} + + +-- !query +select map_filter(map('a', 1, 'b', 2), 1) as map_filter_int_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(1, namedlambdavariable(), namedlambdavariable())\"", + "inputType" : "\"INT\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"map_filter(map(a, 1, b, 2), lambdafunction(1, namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 41, + "fragment" : "map_filter(map('a', 1, 'b', 2), 1)" + } ] +} + + +-- !query +select map_filter(map('a', 1, 'b', 2), map('keep', true)) as map_filter_map_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(map(keep, true), namedlambdavariable(), namedlambdavariable())\"", + "inputType" : "\"MAP\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"map_filter(map(a, 1, b, 2), lambdafunction(map(keep, true), namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 57, + "fragment" : "map_filter(map('a', 1, 'b', 2), map('keep', true))" + } ] +} + + +-- !query +select map_filter(map('a', 1, 'b', 2), struct('filter', true)) as map_filter_struct_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(struct(filter, true), namedlambdavariable(), namedlambdavariable())\"", + "inputType" : "\"STRUCT\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"map_filter(map(a, 1, b, 2), lambdafunction(struct(filter, true), namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 62, + "fragment" : "map_filter(map('a', 1, 'b', 2), struct('filter', true))" + } ] +} + + +-- !query +select map_filter(map('a', 1, 'b', 2), array(true)) as map_filter_array_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(array(true), namedlambdavariable(), namedlambdavariable())\"", + "inputType" : "\"ARRAY\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"map_filter(map(a, 1, b, 2), lambdafunction(array(true), namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 51, + "fragment" : "map_filter(map('a', 1, 'b', 2), array(true))" + } ] +} + + +-- !query +select map_zip_with(map('a', 1), map('a', 10), 100) as map_zipwith_int_literal +-- !query schema +struct> +-- !query output +{"a":100} + + +-- !query +select map_zip_with(map('a', 1), map('a', 10), map('merged', true)) as map_zipwith_map_literal +-- !query schema +struct>> +-- !query output +{"a":{"merged":true}} + + +-- !query +select map_zip_with(map('a', 1), map('a', 10), struct('left', 1, 'right', 10)) as map_zipwith_struct_literal +-- !query schema +struct>> +-- !query output +{"a":{"col1":"left","col2":1,"col3":"right","col4":10}} + + +-- !query +select map_zip_with(map('a', 1), map('a', 10), array('combined')) as map_zipwith_array_literal +-- !query schema +struct>> +-- !query output +{"a":["combined"]} + + +-- !query +select reduce(array(1, 2, 3), 0, 100) as reduce_int_literal +-- !query schema +struct +-- !query output +100 + + +-- !query +select reduce(array(1, 2, 3), map(), map('result', 999)) as reduce_map_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(map(result, 999), namedlambdavariable(), namedlambdavariable())\"", + "inputType" : "\"MAP\"", + "paramIndex" : "third", + "requiredType" : "\"MAP\"", + "sqlExpr" : "\"reduce(array(1, 2, 3), map(), lambdafunction(map(result, 999), namedlambdavariable(), namedlambdavariable()), lambdafunction(namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 56, + "fragment" : "reduce(array(1, 2, 3), map(), map('result', 999))" + } ] +} + + +-- !query +select reduce(array(1, 2, 3), struct('init', 0), struct('final', 999)) as reduce_struct_literal +-- !query schema +struct> +-- !query output +{"col1":"final","col2":999} + + +-- !query +select reduce(array(1, 2, 3), array(), array('result')) as reduce_array_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(array(result), namedlambdavariable(), namedlambdavariable())\"", + "inputType" : "\"ARRAY\"", + "paramIndex" : "third", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"reduce(array(1, 2, 3), array(), lambdafunction(array(result), namedlambdavariable(), namedlambdavariable()), lambdafunction(namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 55, + "fragment" : "reduce(array(1, 2, 3), array(), array('result'))" + } ] +} + + +-- !query +select transform(array(1, 2, 3), 42) as transform_int_literal +-- !query schema +struct> +-- !query output +[42,42,42] + + +-- !query +select transform(array(1, 2, 3), map('key', 'value')) as transform_map_literal +-- !query schema +struct>> +-- !query output +[{"key":"value"},{"key":"value"},{"key":"value"}] + + +-- !query +select transform(array(1, 2, 3), struct('id', 99, 'name', 'test')) as transform_struct_literal +-- !query schema +struct>> +-- !query output +[{"col1":"id","col2":99,"col3":"name","col4":"test"},{"col1":"id","col2":99,"col3":"name","col4":"test"},{"col1":"id","col2":99,"col3":"name","col4":"test"}] + + +-- !query +select transform(array(1, 2, 3), array('a', 'b')) as transform_array_literal +-- !query schema +struct>> +-- !query output +[["a","b"],["a","b"],["a","b"]] + + +-- !query +select transform_keys(map('a', 1, 'b', 2), 42) as transform_keys_int_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "DUPLICATED_MAP_KEY", + "sqlState" : "23505", + "messageParameters" : { + "key" : "42", + "mapKeyDedupPolicy" : "\"spark.sql.mapKeyDedupPolicy\"" + } +} + + +-- !query +select transform_keys(map('a', 1, 'b', 2), map('new', 'key')) as transform_keys_map_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.INVALID_MAP_KEY_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "keyType" : "\"MAP\"", + "sqlExpr" : "\"transform_keys(map(a, 1, b, 2), lambdafunction(map(new, key), namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 61, + "fragment" : "transform_keys(map('a', 1, 'b', 2), map('new', 'key'))" + } ] +} + + +-- !query +select transform_keys(map('a', 1, 'b', 2), struct('key', 'value')) as transform_keys_struct_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "DUPLICATED_MAP_KEY", + "sqlState" : "23505", + "messageParameters" : { + "key" : "[key,value]", + "mapKeyDedupPolicy" : "\"spark.sql.mapKeyDedupPolicy\"" + } +} + + +-- !query +select transform_keys(map('a', 1, 'b', 2), array('new_key')) as transform_keys_array_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "DUPLICATED_MAP_KEY", + "sqlState" : "23505", + "messageParameters" : { + "key" : "[new_key]", + "mapKeyDedupPolicy" : "\"spark.sql.mapKeyDedupPolicy\"" + } +} + + +-- !query +select transform_values(map('a', 1, 'b', 2), 999) as transform_values_int_literal +-- !query schema +struct> +-- !query output +{"a":999,"b":999} + + +-- !query +select transform_values(map('a', 1, 'b', 2), map('new', 'value')) as transform_values_map_literal +-- !query schema +struct>> +-- !query output +{"a":{"new":"value"},"b":{"new":"value"}} + + +-- !query +select transform_values(map('a', 1, 'b', 2), struct('val', 999)) as transform_values_struct_literal +-- !query schema +struct>> +-- !query output +{"a":{"col1":"val","col2":999},"b":{"col1":"val","col2":999}} + + +-- !query +select transform_values(map('a', 1, 'b', 2), array('new_value')) as transform_values_array_literal +-- !query schema +struct>> +-- !query output +{"a":["new_value"],"b":["new_value"]} + + +-- !query +select zip_with(array(1, 2, 3), array(4, 5, 6), 100) as zipwith_int_literal +-- !query schema +struct> +-- !query output +[100,100,100] + + +-- !query +select zip_with(array(1, 2, 3), array(4, 5, 6), map('merged', true)) as zipwith_map_literal +-- !query schema +struct>> +-- !query output +[{"merged":true},{"merged":true},{"merged":true}] + + +-- !query +select zip_with(array(1, 2, 3), array(4, 5, 6), struct('left', 1, 'right', 2)) as zipwith_struct_literal +-- !query schema +struct>> +-- !query output +[{"col1":"left","col2":1,"col3":"right","col4":2},{"col1":"left","col2":1,"col3":"right","col4":2},{"col1":"left","col2":1,"col3":"right","col4":2}] + + +-- !query +select zip_with(array(1, 2, 3), array(4, 5, 6), array('combined')) as zipwith_array_literal +-- !query schema +struct>> +-- !query output +[["combined"],["combined"],["combined"]] diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/hll.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/hll.sql.out index ea9dc8e8af1..908221f0e7c 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/hll.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/hll.sql.out @@ -7,6 +7,22 @@ struct<> +-- !query +DROP TABLE IF EXISTS hll_binary_test +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS hll_string_test +-- !query schema +struct<> +-- !query output + + + -- !query CREATE TABLE t1 USING JSON AS VALUES (0), (1), (2), (2), (2), (3), (4) as tab(col) -- !query schema @@ -15,6 +31,38 @@ struct<> +-- !query +CREATE TABLE hll_binary_test (bytes BINARY) USING PARQUET +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE hll_string_test (s STRING) USING PARQUET +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO hll_binary_test VALUES (X''), (CAST(' ' AS BINARY)), (X'e280'), (X'c1'), (X'c120') +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO hll_string_test VALUES (''), (' '), (CAST(X'C1' AS STRING)), (CAST(X'80' AS STRING)), ('\uFFFD'), ('Ã…'), ('Ã¥'), ('a\u030A'), ('Ã… '), ('Ã¥ '), ('a\u030A ') +-- !query schema +struct<> +-- !query output + + + -- !query SELECT hll_sketch_estimate(hll_sketch_agg(col)) AS result FROM t1 -- !query schema @@ -23,6 +71,78 @@ struct 5 +-- !query +SELECT hll_sketch_estimate(hll_sketch_agg(bytes)) FROM hll_binary_test +-- !query schema +struct +-- !query output +4 + + +-- !query +SELECT hll_sketch_estimate(hll_sketch_agg(s)) utf8_b FROM hll_string_test +-- !query schema +struct +-- !query output +10 + + +-- !query +SELECT hll_sketch_estimate(hll_sketch_agg(s COLLATE UTF8_LCASE)) utf8_lc FROM hll_string_test +-- !query schema +struct +-- !query output +7 + + +-- !query +SELECT hll_sketch_estimate(hll_sketch_agg(s COLLATE UNICODE)) unicode FROM hll_string_test +-- !query schema +struct +-- !query output +7 + + +-- !query +SELECT hll_sketch_estimate(hll_sketch_agg(s COLLATE UNICODE_CI)) unicode_ci FROM hll_string_test +-- !query schema +struct +-- !query output +6 + + +-- !query +SELECT hll_sketch_estimate(hll_sketch_agg(s COLLATE UTF8_BINARY_RTRIM)) utf8_b_rt FROM hll_string_test +-- !query schema +struct +-- !query output +6 + + +-- !query +SELECT hll_sketch_estimate(hll_sketch_agg(s COLLATE UTF8_LCASE_RTRIM)) utf8_lc_rt FROM hll_string_test +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT hll_sketch_estimate(hll_sketch_agg(s COLLATE UNICODE_RTRIM)) unicode_rt FROM hll_string_test +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT hll_sketch_estimate(hll_sketch_agg(s COLLATE UNICODE_CI_RTRIM)) unicode_ci_rt FROM hll_string_test +-- !query schema +struct +-- !query output +2 + + -- !query SELECT hll_sketch_estimate(hll_sketch_agg(col, 12)) FROM VALUES (50), (60), (60), (60), (75), (100) tab(col) @@ -136,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), @@ -267,3 +449,19 @@ DROP TABLE IF EXISTS t1 struct<> -- !query output + + +-- !query +DROP TABLE IF EXISTS hll_binary_test +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS hll_string_test +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/identifier-clause-legacy.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/identifier-clause-legacy.sql.out new file mode 100644 index 00000000000..272d9bce816 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/identifier-clause-legacy.sql.out @@ -0,0 +1,2875 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +SET hivevar:colname = 'c' +-- !query schema +struct +-- !query output +hivevar:colname 'c' + + +-- !query +SELECT IDENTIFIER(${colname} || '_1') FROM VALUES(1) AS T(c_1) +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT IDENTIFIER('c1') FROM VALUES(1) AS T(c1) +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT IDENTIFIER('t.c1') FROM VALUES(1) AS T(c1) +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT IDENTIFIER('`t`.c1') FROM VALUES(1) AS T(c1) +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT IDENTIFIER('`c 1`') FROM VALUES(1) AS T(`c 1`) +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT IDENTIFIER('``') FROM VALUES(1) AS T(``) +-- !query schema +struct<:int> +-- !query output +1 + + +-- !query +SELECT IDENTIFIER('c' || '1') FROM VALUES(1) AS T(c1) +-- !query schema +struct +-- !query output +1 + + +-- !query +CREATE SCHEMA IF NOT EXISTS s +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE s.tab(c1 INT) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +USE SCHEMA s +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO IDENTIFIER('ta' || 'b') VALUES(1) +-- !query schema +struct<> +-- !query output + + + +-- !query +DELETE FROM IDENTIFIER('ta' || 'b') WHERE 1=0 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UNSUPPORTED_FEATURE.TABLE_OPERATION", + "sqlState" : "0A000", + "messageParameters" : { + "operation" : "DELETE", + "tableName" : "`spark_catalog`.`s`.`tab`" + } +} + + +-- !query +UPDATE IDENTIFIER('ta' || 'b') SET c1 = 2 +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUnsupportedOperationException +{ + "errorClass" : "UNSUPPORTED_FEATURE.TABLE_OPERATION", + "sqlState" : "0A000", + "messageParameters" : { + "operation" : "UPDATE TABLE", + "tableName" : "`spark_catalog`.`s`.`tab`" + } +} + + +-- !query +MERGE INTO IDENTIFIER('ta' || 'b') AS t USING IDENTIFIER('ta' || 'b') AS s ON s.c1 = t.c1 + WHEN MATCHED THEN UPDATE SET c1 = 3 +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUnsupportedOperationException +{ + "errorClass" : "UNSUPPORTED_FEATURE.TABLE_OPERATION", + "sqlState" : "0A000", + "messageParameters" : { + "operation" : "MERGE INTO TABLE", + "tableName" : "`spark_catalog`.`s`.`tab`" + } +} + + +-- !query +SELECT * FROM IDENTIFIER('tab') +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT * FROM IDENTIFIER('s.tab') +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT * FROM IDENTIFIER('`s`.`tab`') +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT * FROM IDENTIFIER('t' || 'a' || 'b') +-- !query schema +struct +-- !query output +1 + + +-- !query +USE SCHEMA default +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE s.tab +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP SCHEMA s +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT IDENTIFIER('COAL' || 'ESCE')(NULL, 1) +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT IDENTIFIER('abs')(c1) FROM VALUES(-1) AS T(c1) +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT * FROM IDENTIFIER('ra' || 'nge')(0, 1) +-- !query schema +struct +-- !query output +0 + + +-- !query +CREATE TABLE IDENTIFIER('tab')(c1 INT) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS IDENTIFIER('ta' || 'b') +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE SCHEMA identifier_clauses +-- !query schema +struct<> +-- !query output + + + +-- !query +USE identifier_clauses +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE IDENTIFIER('ta' || 'b')(c1 INT) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS IDENTIFIER('identifier_clauses.' || 'tab') +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE IDENTIFIER('identifier_clauses.' || 'tab')(c1 INT) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +REPLACE TABLE IDENTIFIER('identifier_clauses.' || 'tab')(c1 INT) USING CSV +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UNSUPPORTED_FEATURE.TABLE_OPERATION", + "sqlState" : "0A000", + "messageParameters" : { + "operation" : "REPLACE TABLE", + "tableName" : "`spark_catalog`.`identifier_clauses`.`tab`" + } +} + + +-- !query +CACHE TABLE IDENTIFIER('ta' || 'b') +-- !query schema +struct<> +-- !query output + + + +-- !query +UNCACHE TABLE IDENTIFIER('ta' || 'b') +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS IDENTIFIER('ta' || 'b') +-- !query schema +struct<> +-- !query output + + + +-- !query +USE default +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP SCHEMA identifier_clauses +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE tab(c1 INT) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO tab VALUES (1) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT c1 FROM tab +-- !query schema +struct +-- !query output +1 + + +-- !query +DESCRIBE IDENTIFIER('ta' || 'b') +-- !query schema +struct +-- !query output +c1 int + + +-- !query +ANALYZE TABLE IDENTIFIER('ta' || 'b') COMPUTE STATISTICS +-- !query schema +struct<> +-- !query output + + + +-- !query +ALTER TABLE IDENTIFIER('ta' || 'b') ADD COLUMN c2 INT +-- !query schema +struct<> +-- !query output + + + +-- !query +SHOW TBLPROPERTIES IDENTIFIER('ta' || 'b') +-- !query schema +struct +-- !query output + + + +-- !query +SHOW COLUMNS FROM IDENTIFIER('ta' || 'b') +-- !query schema +struct +-- !query output +c1 +c2 + + +-- !query +COMMENT ON TABLE IDENTIFIER('ta' || 'b') IS 'hello' +-- !query schema +struct<> +-- !query output + + + +-- !query +REFRESH TABLE IDENTIFIER('ta' || 'b') +-- !query schema +struct<> +-- !query output + + + +-- !query +REPAIR TABLE IDENTIFIER('ta' || 'b') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "NOT_A_PARTITIONED_TABLE", + "sqlState" : "42809", + "messageParameters" : { + "operation" : "MSCK REPAIR TABLE", + "tableIdentWithDB" : "`spark_catalog`.`default`.`tab`" + } +} + + +-- !query +TRUNCATE TABLE IDENTIFIER('ta' || 'b') +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS tab +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE OR REPLACE VIEW IDENTIFIER('v')(c1) AS VALUES(1) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT * FROM v +-- !query schema +struct +-- !query output +1 + + +-- !query +ALTER VIEW IDENTIFIER('v') AS VALUES(2) +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP VIEW IDENTIFIER('v') +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TEMPORARY VIEW IDENTIFIER('v')(c1) AS VALUES(1) +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP VIEW IDENTIFIER('v') +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE SCHEMA IDENTIFIER('id' || 'ent') +-- !query schema +struct<> +-- !query output + + + +-- !query +ALTER SCHEMA IDENTIFIER('id' || 'ent') SET PROPERTIES (somekey = 'somevalue') +-- !query schema +struct<> +-- !query output + + + +-- !query +ALTER SCHEMA IDENTIFIER('id' || 'ent') SET LOCATION 'someloc' +-- !query schema +struct<> +-- !query output + + + +-- !query +COMMENT ON SCHEMA IDENTIFIER('id' || 'ent') IS 'some comment' +-- !query schema +struct<> +-- !query output + + + +-- !query +DESCRIBE SCHEMA IDENTIFIER('id' || 'ent') +-- !query schema +struct +-- !query output +Catalog Name spark_catalog +Comment some comment +Location [not included in comparison]/{warehouse_dir}/someloc +Namespace Name ident +Owner [not included in comparison] + + +-- !query +SHOW TABLES IN IDENTIFIER('id' || 'ent') +-- !query schema +struct +-- !query output + + + +-- !query +SHOW TABLE EXTENDED IN IDENTIFIER('id' || 'ent') LIKE 'hello' +-- !query schema +struct +-- !query output + + + +-- !query +USE IDENTIFIER('id' || 'ent') +-- !query schema +struct<> +-- !query output + + + +-- !query +SHOW CURRENT SCHEMA +-- !query schema +struct +-- !query output +spark_catalog ident + + +-- !query +USE SCHEMA IDENTIFIER('id' || 'ent') +-- !query schema +struct<> +-- !query output + + + +-- !query +USE SCHEMA default +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP SCHEMA IDENTIFIER('id' || 'ent') +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE SCHEMA ident +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE FUNCTION IDENTIFIER('ident.' || 'myDoubleAvg') AS 'test.org.apache.spark.sql.MyDoubleAvg' +-- !query schema +struct<> +-- !query output + + + +-- !query +DESCRIBE FUNCTION IDENTIFIER('ident.' || 'myDoubleAvg') +-- !query schema +struct +-- !query output +Class: test.org.apache.spark.sql.MyDoubleAvg +Function: spark_catalog.ident.mydoubleavg +Usage: N/A. + + +-- !query +REFRESH FUNCTION IDENTIFIER('ident.' || 'myDoubleAvg') +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP FUNCTION IDENTIFIER('ident.' || 'myDoubleAvg') +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP SCHEMA ident +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TEMPORARY FUNCTION IDENTIFIER('my' || 'DoubleAvg') AS 'test.org.apache.spark.sql.MyDoubleAvg' +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TEMPORARY FUNCTION IDENTIFIER('my' || 'DoubleAvg') +-- !query schema +struct<> +-- !query output + + + +-- !query +DECLARE var = 'sometable' +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE IDENTIFIER(var)(c1 INT) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +SET VAR var = 'c1' +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT IDENTIFIER(var) FROM VALUES(1) AS T(c1) +-- !query schema +struct +-- !query output +1 + + +-- !query +SET VAR var = 'some' +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IDENTIFIER(var || 'table') +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT IDENTIFIER('c 1') FROM VALUES(1) AS T(`c 1`) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'1'", + "hint" : ": extra input '1'" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 24, + "fragment" : "IDENTIFIER('c 1')" + } ] +} + + +-- !query +SELECT IDENTIFIER('') FROM VALUES(1) AS T(``) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_EMPTY_STATEMENT", + "sqlState" : "42617", + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 21, + "fragment" : "IDENTIFIER('')" + } ] +} + + +-- !query +VALUES(IDENTIFIER(CAST(NULL AS STRING))) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "NOT_A_CONSTANT_STRING.NULL", + "sqlState" : "42601", + "messageParameters" : { + "expr" : "CAST(NULL AS STRING)", + "name" : "IDENTIFIER" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 19, + "stopIndex" : 38, + "fragment" : "CAST(NULL AS STRING)" + } ] +} + + +-- !query +VALUES(IDENTIFIER(1)) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "NOT_A_CONSTANT_STRING.WRONG_TYPE", + "sqlState" : "42601", + "messageParameters" : { + "dataType" : "int", + "expr" : "1", + "name" : "IDENTIFIER" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 19, + "stopIndex" : 19, + "fragment" : "1" + } ] +} + + +-- !query +VALUES(IDENTIFIER(SUBSTR('HELLO', 1, RAND() + 1))) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "NOT_A_CONSTANT_STRING.NOT_CONSTANT", + "sqlState" : "42601", + "messageParameters" : { + "expr" : "substr('HELLO', 1, CAST((rand() + CAST(1 AS DOUBLE)) AS INT))", + "name" : "IDENTIFIER" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 19, + "stopIndex" : 48, + "fragment" : "SUBSTR('HELLO', 1, RAND() + 1)" + } ] +} + + +-- !query +SELECT `IDENTIFIER`('abs')(c1) FROM VALUES(-1) AS T(c1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UNRESOLVED_ROUTINE", + "sqlState" : "42883", + "messageParameters" : { + "routineName" : "`IDENTIFIER`", + "searchPath" : "[`system`.`builtin`, `system`.`session`, `spark_catalog`.`default`]" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 26, + "fragment" : "`IDENTIFIER`('abs')" + } ] +} + + +-- !query +CREATE TABLE t(col1 INT) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT * FROM IDENTIFIER((SELECT 't')) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "NOT_A_CONSTANT_STRING.NOT_CONSTANT", + "sqlState" : "42601", + "messageParameters" : { + "expr" : "scalarsubquery()", + "name" : "IDENTIFIER" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 26, + "stopIndex" : 37, + "fragment" : "(SELECT 't')" + } ] +} + + +-- !query +SELECT * FROM (SELECT IDENTIFIER((SELECT 'col1')) FROM IDENTIFIER((SELECT 't'))) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "NOT_A_CONSTANT_STRING.NOT_CONSTANT", + "sqlState" : "42601", + "messageParameters" : { + "expr" : "scalarsubquery()", + "name" : "IDENTIFIER" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 67, + "stopIndex" : 78, + "fragment" : "(SELECT 't')" + } ] +} + + +-- !query +SELECT IDENTIFIER((SELECT 'col1')) FROM VALUES(1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "NOT_A_CONSTANT_STRING.NOT_CONSTANT", + "sqlState" : "42601", + "messageParameters" : { + "expr" : "scalarsubquery()", + "name" : "IDENTIFIER" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 19, + "stopIndex" : 33, + "fragment" : "(SELECT 'col1')" + } ] +} + + +-- !query +SELECT col1, IDENTIFIER((SELECT col1)) FROM VALUES(1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "NOT_A_CONSTANT_STRING.NOT_CONSTANT", + "sqlState" : "42601", + "messageParameters" : { + "expr" : "scalarsubquery(col1)", + "name" : "IDENTIFIER" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 25, + "stopIndex" : 37, + "fragment" : "(SELECT col1)" + } ] +} + + +-- !query +SELECT IDENTIFIER((SELECT 'col1', 'col2')) FROM VALUES(1,2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "UNSUPPORTED_TYPED_LITERAL", + "sqlState" : "0A000", + "messageParameters" : { + "supportedTypes" : "\"DATE\", \"TIMESTAMP_NTZ\", \"TIMESTAMP_LTZ\", \"TIMESTAMP\", \"INTERVAL\", \"X\", \"TIME\"", + "unsupportedType" : "\"SELECT\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 20, + "stopIndex" : 32, + "fragment" : "SELECT 'col1'" + } ] +} + + +-- !query +DROP TABLE t +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE IDENTIFIER(1)(c1 INT) USING csv +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "NOT_A_CONSTANT_STRING.WRONG_TYPE", + "sqlState" : "42601", + "messageParameters" : { + "dataType" : "int", + "expr" : "1", + "name" : "IDENTIFIER" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 25, + "stopIndex" : 25, + "fragment" : "1" + } ] +} + + +-- !query +CREATE TABLE IDENTIFIER('a.b.c')(c1 INT) USING csv +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "REQUIRES_SINGLE_PART_NAMESPACE", + "sqlState" : "42K05", + "messageParameters" : { + "namespace" : "`a`.`b`", + "sessionCatalog" : "spark_catalog" + } +} + + +-- !query +CREATE VIEW IDENTIFIER('a.b.c')(c1) AS VALUES(1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "REQUIRES_SINGLE_PART_NAMESPACE", + "sqlState" : "42K05", + "messageParameters" : { + "namespace" : "`a`.`b`", + "sessionCatalog" : "spark_catalog" + } +} + + +-- !query +DROP TABLE IDENTIFIER('a.b.c') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "REQUIRES_SINGLE_PART_NAMESPACE", + "sqlState" : "42K05", + "messageParameters" : { + "namespace" : "`a`.`b`", + "sessionCatalog" : "spark_catalog" + } +} + + +-- !query +DROP VIEW IDENTIFIER('a.b.c') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "REQUIRES_SINGLE_PART_NAMESPACE", + "sqlState" : "42K05", + "messageParameters" : { + "namespace" : "`a`.`b`", + "sessionCatalog" : "spark_catalog" + } +} + + +-- !query +COMMENT ON TABLE IDENTIFIER('a.b.c.d') IS 'hello' +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "REQUIRES_SINGLE_PART_NAMESPACE", + "sqlState" : "42K05", + "messageParameters" : { + "namespace" : "`a`.`b`.`c`", + "sessionCatalog" : "spark_catalog" + } +} + + +-- !query +VALUES(IDENTIFIER(1)()) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "NOT_A_CONSTANT_STRING.WRONG_TYPE", + "sqlState" : "42601", + "messageParameters" : { + "dataType" : "int", + "expr" : "1", + "name" : "IDENTIFIER" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 19, + "stopIndex" : 19, + "fragment" : "1" + } ] +} + + +-- !query +VALUES(IDENTIFIER('a.b.c.d')()) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "IDENTIFIER_TOO_MANY_NAME_PARTS", + "sqlState" : "42601", + "messageParameters" : { + "identifier" : "`a`.`b`.`c`.`d`", + "limit" : "2" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 30, + "fragment" : "IDENTIFIER('a.b.c.d')()" + } ] +} + + +-- !query +CREATE TEMPORARY FUNCTION IDENTIFIER('default.my' || 'DoubleAvg') AS 'test.org.apache.spark.sql.MyDoubleAvg' +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "INVALID_SQL_SYNTAX.CREATE_TEMP_FUNC_WITH_DATABASE", + "sqlState" : "42000", + "messageParameters" : { + "database" : "`default`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 108, + "fragment" : "CREATE TEMPORARY FUNCTION IDENTIFIER('default.my' || 'DoubleAvg') AS 'test.org.apache.spark.sql.MyDoubleAvg'" + } ] +} + + +-- !query +DROP TEMPORARY FUNCTION IDENTIFIER('default.my' || 'DoubleAvg') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "INVALID_SQL_SYNTAX.MULTI_PART_NAME", + "sqlState" : "42000", + "messageParameters" : { + "name" : "`default`.`myDoubleAvg`", + "statement" : "DROP TEMPORARY FUNCTION" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 63, + "fragment" : "DROP TEMPORARY FUNCTION IDENTIFIER('default.my' || 'DoubleAvg')" + } ] +} + + +-- !query +CREATE TEMPORARY VIEW IDENTIFIER('default.v')(c1) AS VALUES(1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "TEMP_VIEW_NAME_TOO_MANY_NAME_PARTS", + "sqlState" : "428EK", + "messageParameters" : { + "actualName" : "`default`.`v`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 62, + "fragment" : "CREATE TEMPORARY VIEW IDENTIFIER('default.v')(c1) AS VALUES(1)" + } ] +} + + +-- !query +create temporary view identifier('v1') as (select my_col from (values (1), (2), (1) as (my_col)) group by 1) +-- !query schema +struct<> +-- !query output + + + +-- !query +cache table identifier('t1') as (select my_col from (values (1), (2), (1) as (my_col)) group by 1) +-- !query schema +struct<> +-- !query output + + + +-- !query +create table identifier('t2') using csv as (select my_col from (values (1), (2), (1) as (my_col)) group by 1) +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into identifier('t2') select my_col from (values (3) as (my_col)) group by 1 +-- !query schema +struct<> +-- !query output + + + +-- !query +drop view v1 +-- !query schema +struct<> +-- !query output + + + +-- !query +drop table t1 +-- !query schema +struct<> +-- !query output + + + +-- !query +drop table t2 +-- !query schema +struct<> +-- !query output + + + +-- !query +DECLARE agg = 'max' +-- !query schema +struct<> +-- !query output + + + +-- !query +DECLARE col = 'c1' +-- !query schema +struct<> +-- !query output + + + +-- !query +DECLARE tab = 'T' +-- !query schema +struct<> +-- !query output + + + +-- !query +WITH S(c1, c2) AS (VALUES(1, 2), (2, 3)), + T(c1, c2) AS (VALUES ('a', 'b'), ('c', 'd')) +SELECT IDENTIFIER(agg)(IDENTIFIER(col)) FROM IDENTIFIER(tab) +-- !query schema +struct +-- !query output +c + + +-- !query +WITH S(c1, c2) AS (VALUES(1, 2), (2, 3)), + T(c1, c2) AS (VALUES ('a', 'b'), ('c', 'd')) +SELECT IDENTIFIER('max')(IDENTIFIER('c1')) FROM IDENTIFIER('T') +-- !query schema +struct +-- !query output +c + + +-- !query +WITH ABC(c1, c2) AS (VALUES(1, 2), (2, 3)) +SELECT IDENTIFIER('max')(IDENTIFIER('c1')) FROM IDENTIFIER('A' || 'BC') +-- !query schema +struct +-- !query output +2 + + +-- !query +SELECT row_number() OVER IDENTIFIER('x.win') FROM VALUES(1) AS T(c1) WINDOW win AS (ORDER BY c1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "''x.win''", + "hint" : "" + } +} + + +-- !query +SELECT T1.c1 FROM VALUES(1) AS T1(c1) JOIN VALUES(1) AS T2(c1) USING (IDENTIFIER('c1')) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +SELECT IDENTIFIER('t').c1 FROM VALUES(1) AS T(c1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`t`", + "proposal" : "`c1`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 22, + "fragment" : "IDENTIFIER('t')" + } ] +} + + +-- !query +SELECT map('a', 1).IDENTIFIER('a') FROM VALUES(1) AS T(c1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "''a''", + "hint" : "" + } +} + + +-- !query +SELECT named_struct('a', 1).IDENTIFIER('a') FROM VALUES(1) AS T(c1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "''a''", + "hint" : "" + } +} + + +-- !query +SELECT * FROM s.IDENTIFIER('tab') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +SELECT * FROM IDENTIFIER('s').IDENTIFIER('tab') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'IDENTIFIER'", + "hint" : "" + } +} + + +-- !query +SELECT * FROM IDENTIFIER('s').tab +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'IDENTIFIER'", + "hint" : "" + } +} + + +-- !query +SELECT row_number() OVER IDENTIFIER('win') FROM VALUES(1) AS T(c1) WINDOW win AS (ORDER BY c1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "''win''", + "hint" : "" + } +} + + +-- !query +SELECT row_number() OVER win FROM VALUES(1) AS T(c1) WINDOW IDENTIFIER('win') AS (ORDER BY c1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : ": missing 'AS'" + } +} + + +-- !query +SELECT 1 AS IDENTIFIER('col1') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +SELECT my_table.* FROM VALUES (1, 2) AS IDENTIFIER('my_table')(IDENTIFIER('c1'), IDENTIFIER('c2')) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "''my_table''", + "hint" : "" + } +} + + +-- !query +WITH identifier('v')(identifier('c1')) AS (VALUES(1)) (SELECT c1 FROM v) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "''v''", + "hint" : "" + } +} + + +-- !query +CREATE OR REPLACE VIEW v(IDENTIFIER('c1')) AS VALUES(1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +SELECT c1 FROM v +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "TABLE_OR_VIEW_NOT_FOUND", + "sqlState" : "42P01", + "messageParameters" : { + "relationName" : "`v`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 16, + "stopIndex" : 16, + "fragment" : "v" + } ] +} + + +-- !query +DROP VIEW IF EXISTS v +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE tab(IDENTIFIER('c1') INT) USING CSV +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +INSERT INTO tab(IDENTIFIER('c1')) VALUES(1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : ": missing ')'" + } +} + + +-- !query +SELECT c1 FROM tab +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "TABLE_OR_VIEW_NOT_FOUND", + "sqlState" : "42P01", + "messageParameters" : { + "relationName" : "`tab`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 16, + "stopIndex" : 18, + "fragment" : "tab" + } ] +} + + +-- !query +ALTER TABLE IDENTIFIER('tab') RENAME COLUMN IDENTIFIER('c1') TO IDENTIFIER('col1') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +SELECT col1 FROM tab +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "TABLE_OR_VIEW_NOT_FOUND", + "sqlState" : "42P01", + "messageParameters" : { + "relationName" : "`tab`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 18, + "stopIndex" : 20, + "fragment" : "tab" + } ] +} + + +-- !query +ALTER TABLE IDENTIFIER('tab') ADD COLUMN IDENTIFIER('c2') INT +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +SELECT c2 FROM tab +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "TABLE_OR_VIEW_NOT_FOUND", + "sqlState" : "42P01", + "messageParameters" : { + "relationName" : "`tab`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 16, + "stopIndex" : 18, + "fragment" : "tab" + } ] +} + + +-- !query +ALTER TABLE IDENTIFIER('tab') DROP COLUMN IDENTIFIER('c2') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +ALTER TABLE IDENTIFIER('tab') RENAME TO IDENTIFIER('tab_renamed') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +SELECT * FROM tab_renamed +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "TABLE_OR_VIEW_NOT_FOUND", + "sqlState" : "42P01", + "messageParameters" : { + "relationName" : "`tab_renamed`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 15, + "stopIndex" : 25, + "fragment" : "tab_renamed" + } ] +} + + +-- !query +DROP TABLE IF EXISTS tab_renamed +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS tab +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE test_col_with_dot(IDENTIFIER('`col.with.dot`') INT) USING CSV +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +DROP TABLE IF EXISTS test_col_with_dot +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT * FROM VALUES (1, 2) AS IDENTIFIER('schema.table')(c1, c2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "''schema.table''", + "hint" : "" + } +} + + +-- !query +SELECT 1 AS IDENTIFIER('col1.col2') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +CREATE SCHEMA identifier_clause_test_schema +-- !query schema +struct<> +-- !query output + + + +-- !query +USE identifier_clause_test_schema +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE test_show(c1 INT, c2 STRING) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +SHOW VIEWS IN IDENTIFIER('identifier_clause_test_schema') +-- !query schema +struct +-- !query output + + + +-- !query +SHOW PARTITIONS IDENTIFIER('test_show') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_PARTITION_OPERATION.PARTITION_SCHEMA_IS_EMPTY", + "sqlState" : "42601", + "messageParameters" : { + "name" : "`spark_catalog`.`identifier_clause_test_schema`.`test_show`" + } +} + + +-- !query +SHOW CREATE TABLE IDENTIFIER('test_show') +-- !query schema +struct +-- !query output +CREATE TABLE spark_catalog.identifier_clause_test_schema.test_show ( + c1 INT, + c2 STRING) +USING CSV + + +-- !query +DROP TABLE test_show +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE test_desc(c1 INT) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +DESCRIBE TABLE IDENTIFIER('test_desc') +-- !query schema +struct +-- !query output +c1 int + + +-- !query +DESCRIBE FORMATTED IDENTIFIER('test_desc') +-- !query schema +struct +-- !query output +c1 int + +# Detailed Table Information +Catalog spark_catalog +Database identifier_clause_test_schema +Table test_desc +Created Time [not included in comparison] +Last Access [not included in comparison] +Created By [not included in comparison] +Type MANAGED +Provider CSV +Location [not included in comparison]/{warehouse_dir}/identifier_clause_test_schema.db/test_desc + + +-- !query +DESCRIBE EXTENDED IDENTIFIER('test_desc') +-- !query schema +struct +-- !query output +c1 int + +# Detailed Table Information +Catalog spark_catalog +Database identifier_clause_test_schema +Table test_desc +Created Time [not included in comparison] +Last Access [not included in comparison] +Created By [not included in comparison] +Type MANAGED +Provider CSV +Location [not included in comparison]/{warehouse_dir}/identifier_clause_test_schema.db/test_desc + + +-- !query +DESC IDENTIFIER('test_desc') +-- !query schema +struct +-- !query output +c1 int + + +-- !query +DROP TABLE test_desc +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE test_comment(c1 INT, c2 STRING) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +COMMENT ON TABLE IDENTIFIER('test_comment') IS 'table comment' +-- !query schema +struct<> +-- !query output + + + +-- !query +ALTER TABLE test_comment ALTER COLUMN IDENTIFIER('c1') COMMENT 'column comment' +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +DROP TABLE test_comment +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE identifier_clause_test_schema.test_table(c1 INT) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +ANALYZE TABLE IDENTIFIER('identifier_clause_test_schema.test_table') COMPUTE STATISTICS +-- !query schema +struct<> +-- !query output + + + +-- !query +REFRESH TABLE IDENTIFIER('identifier_clause_test_schema.test_table') +-- !query schema +struct<> +-- !query output + + + +-- !query +DESCRIBE IDENTIFIER('identifier_clause_test_schema.test_table') +-- !query schema +struct +-- !query output +c1 int + + +-- !query +SHOW COLUMNS FROM IDENTIFIER('identifier_clause_test_schema.test_table') +-- !query schema +struct +-- !query output +c1 + + +-- !query +DROP TABLE IDENTIFIER('identifier_clause_test_schema.test_table') +-- !query schema +struct<> +-- !query output + + + +-- !query +DECLARE IDENTIFIER('my_var') = 'value' +-- !query schema +struct<> +-- !query output + + + +-- !query +SET VAR IDENTIFIER('my_var') = 'new_value' +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : ": missing EQ" + } +} + + +-- !query +SELECT IDENTIFIER('my_var') +-- !query schema +struct +-- !query output +value + + +-- !query +DROP TEMPORARY VARIABLE IDENTIFIER('my_var') +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TEMPORARY FUNCTION test_udf(IDENTIFIER('param1') INT, IDENTIFIER('param2') STRING) +RETURNS INT +RETURN IDENTIFIER('param1') + length(IDENTIFIER('param2')) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +SELECT test_udf(5, 'hello') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UNRESOLVED_ROUTINE", + "sqlState" : "42883", + "messageParameters" : { + "routineName" : "`test_udf`", + "searchPath" : "[`system`.`builtin`, `system`.`session`, `spark_catalog`.`identifier_clause_test_schema`]" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 27, + "fragment" : "test_udf(5, 'hello')" + } ] +} + + +-- !query +DROP TEMPORARY FUNCTION test_udf +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.analysis.NoSuchTempFunctionException +{ + "errorClass" : "ROUTINE_NOT_FOUND", + "sqlState" : "42883", + "messageParameters" : { + "routineName" : "`test_udf`" + } +} + + +-- !query +CREATE TEMPORARY FUNCTION test_table_udf(IDENTIFIER('input_val') INT) +RETURNS TABLE(IDENTIFIER('col1') INT, IDENTIFIER('col2') STRING) +RETURN SELECT IDENTIFIER('input_val'), 'result' +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +SELECT * FROM test_table_udf(42) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UNRESOLVABLE_TABLE_VALUED_FUNCTION", + "sqlState" : "42883", + "messageParameters" : { + "name" : "`test_table_udf`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 15, + "stopIndex" : 32, + "fragment" : "test_table_udf(42)" + } ] +} + + +-- !query +DROP TEMPORARY FUNCTION test_table_udf +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.analysis.NoSuchTempFunctionException +{ + "errorClass" : "ROUTINE_NOT_FOUND", + "sqlState" : "42883", + "messageParameters" : { + "routineName" : "`test_table_udf`" + } +} + + +-- !query +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(:tab \'b\').c1 FROM VALUES(1) AS tab(c1)' USING 'ta' AS tab +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_EXTRACT_BASE_FIELD_TYPE", + "sqlState" : "42000", + "messageParameters" : { + "base" : "\"variablereference(system.session.tab='T')\"", + "other" : "\"STRING\"" + } +} + + +-- !query +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(:col1 ''.c2'') FROM VALUES(named_struct(''c2'', 42)) AS T(c1)' + USING 'c1' AS col1 +-- !query schema +struct +-- !query output +42 + + +-- !query +CREATE TABLE integration_test(c1 INT, c2 STRING) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO integration_test VALUES (1, 'a'), (2, 'b') +-- !query schema +struct<> +-- !query output + + + +-- !query +EXECUTE IMMEDIATE 'SELECT * FROM IDENTIFIER(:schema ''.'' :table) ORDER BY ALL' + USING 'identifier_clause_test_schema' AS schema, 'integration_test' AS table +-- !query schema +struct +-- !query output +1 a +2 b + + +-- !query +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(:prefix ''1''), IDENTIFIER(:prefix ''2'') FROM integration_test ORDER BY ALL' + USING 'c' AS prefix +-- !query schema +struct +-- !query output +1 a +2 b + + +-- !query +EXECUTE IMMEDIATE 'SELECT * FROM integration_test WHERE IDENTIFIER(:col) = :val' + USING 'c1' AS col, 1 AS val +-- !query schema +struct +-- !query output +1 a + + +-- !query +CREATE TABLE integration_test2(c1 INT, c3 STRING) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO integration_test2 VALUES (1, 'x'), (2, 'y') +-- !query schema +struct<> +-- !query output + + + +-- !query +EXECUTE IMMEDIATE 'SELECT t1.*, t2.* FROM IDENTIFIER(:t1) t1 JOIN IDENTIFIER(:t2) t2 USING (IDENTIFIER(:col)) ORDER BY ALL' + USING 'integration_test' AS t1, 'integration_test2' AS t2, 'c1' AS col +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + }, + "queryContext" : [ { + "objectType" : "EXECUTE IMMEDIATE", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 103, + "fragment" : "SELECT t1.*, t2.* FROM IDENTIFIER(:t1) t1 JOIN IDENTIFIER(:t2) t2 USING (IDENTIFIER(:col)) ORDER BY ALL" + } ] +} + + +-- !query +EXECUTE IMMEDIATE + 'SELECT IDENTIFIER(:col1), IDENTIFIER(:col2), row_number() OVER (PARTITION BY IDENTIFIER(:part) ORDER BY IDENTIFIER(:ord)) as rn FROM integration_test' + USING 'c1' AS col1, 'c2' AS col2, 'c2' AS part, 'c1' AS ord +-- !query schema +struct +-- !query output +1 a 1 +2 b 1 + + +-- !query +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(:prefix ''2''), IDENTIFIER(:agg)(IDENTIFIER(:col)) FROM integration_test GROUP BY IDENTIFIER(:prefix ''2'') ORDER BY ALL' + USING 'c' AS prefix, 'count' AS agg, 'c1' AS col +-- !query schema +struct +-- !query output +a 1 +b 1 + + +-- !query +EXECUTE IMMEDIATE 'SELECT * FROM integration_test ORDER BY IDENTIFIER(:col1) DESC, IDENTIFIER(:col2)' + USING 'c1' AS col1, 'c2' AS col2 +-- !query schema +struct +-- !query output +2 b +1 a + + +-- !query +EXECUTE IMMEDIATE 'INSERT INTO integration_test(IDENTIFIER(:col1), IDENTIFIER(:col2)) VALUES (:val1, :val2)' + USING 'c1' AS col1, 'c2' AS col2, 3 AS val1, 'c' AS val2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : ": missing ')'" + }, + "queryContext" : [ { + "objectType" : "EXECUTE IMMEDIATE", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 88, + "fragment" : "INSERT INTO integration_test(IDENTIFIER(:col1), IDENTIFIER(:col2)) VALUES (:val1, :val2)" + } ] +} + + +-- !query +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(concat(:schema, ''.'', :table, ''.c1'')) FROM VALUES(named_struct(''c1'', 100)) AS IDENTIFIER(:alias)(IDENTIFIER(:schema ''.'' :table))' + USING 'identifier_clause_test_schema' AS schema, 'my_table' AS table, 't' AS alias +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "':'", + "hint" : ": extra input ':'" + }, + "queryContext" : [ { + "objectType" : "EXECUTE IMMEDIATE", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 145, + "fragment" : "SELECT IDENTIFIER(concat(:schema, '.', :table, '.c1')) FROM VALUES(named_struct('c1', 100)) AS IDENTIFIER(:alias)(IDENTIFIER(:schema '.' :table))" + } ] +} + + +-- !query +EXECUTE IMMEDIATE 'WITH IDENTIFIER(:cte_name)(c1) AS (VALUES(1)) SELECT c1 FROM IDENTIFIER(:cte_name)' + USING 'my_cte' AS cte_name +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "':'", + "hint" : "" + }, + "queryContext" : [ { + "objectType" : "EXECUTE IMMEDIATE", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 82, + "fragment" : "WITH IDENTIFIER(:cte_name)(c1) AS (VALUES(1)) SELECT c1 FROM IDENTIFIER(:cte_name)" + } ] +} + + +-- !query +EXECUTE IMMEDIATE 'CREATE OR REPLACE TEMPORARY VIEW IDENTIFIER(:view_name)(IDENTIFIER(:col_name)) AS VALUES(1)' + USING 'test_view' AS view_name, 'test_col' AS col_name +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + }, + "queryContext" : [ { + "objectType" : "EXECUTE IMMEDIATE", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 91, + "fragment" : "CREATE OR REPLACE TEMPORARY VIEW IDENTIFIER(:view_name)(IDENTIFIER(:col_name)) AS VALUES(1)" + } ] +} + + +-- !query +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(:col) FROM IDENTIFIER(:view)' + USING 'test_col' AS col, 'test_view' AS view +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "TABLE_OR_VIEW_NOT_FOUND", + "sqlState" : "42P01", + "messageParameters" : { + "relationName" : "`test_view`" + }, + "queryContext" : [ { + "objectType" : "EXECUTE IMMEDIATE", + "objectName" : "", + "startIndex" : 30, + "stopIndex" : 46, + "fragment" : "IDENTIFIER(:view)" + } ] +} + + +-- !query +DROP VIEW test_view +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.analysis.NoSuchTableException +{ + "errorClass" : "TABLE_OR_VIEW_NOT_FOUND", + "sqlState" : "42P01", + "messageParameters" : { + "relationName" : "`spark_catalog`.`identifier_clause_test_schema`.`test_view`" + } +} + + +-- !query +EXECUTE IMMEDIATE 'ALTER TABLE IDENTIFIER(:tab) ADD COLUMN IDENTIFIER(:new_col) INT' + USING 'integration_test' AS tab, 'c4' AS new_col +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + }, + "queryContext" : [ { + "objectType" : "EXECUTE IMMEDIATE", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 64, + "fragment" : "ALTER TABLE IDENTIFIER(:tab) ADD COLUMN IDENTIFIER(:new_col) INT" + } ] +} + + +-- !query +EXECUTE IMMEDIATE 'ALTER TABLE IDENTIFIER(:tab) RENAME COLUMN IDENTIFIER(:old_col) TO IDENTIFIER(:new_col)' + USING 'integration_test' AS tab, 'c4' AS old_col, 'c5' AS new_col +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + }, + "queryContext" : [ { + "objectType" : "EXECUTE IMMEDIATE", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 87, + "fragment" : "ALTER TABLE IDENTIFIER(:tab) RENAME COLUMN IDENTIFIER(:old_col) TO IDENTIFIER(:new_col)" + } ] +} + + +-- !query +EXECUTE IMMEDIATE 'SELECT map(:key, :val).IDENTIFIER(:key) AS result' + USING 'mykey' AS key, 42 AS val +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "':'", + "hint" : "" + }, + "queryContext" : [ { + "objectType" : "EXECUTE IMMEDIATE", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 49, + "fragment" : "SELECT map(:key, :val).IDENTIFIER(:key) AS result" + } ] +} + + +-- !query +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(:alias ''.c1'') FROM integration_test AS IDENTIFIER(:alias) ORDER BY ALL' + USING 't' AS alias +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "':'", + "hint" : ": extra input ':'" + }, + "queryContext" : [ { + "objectType" : "EXECUTE IMMEDIATE", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 88, + "fragment" : "SELECT IDENTIFIER(:alias '.c1') FROM integration_test AS IDENTIFIER(:alias) ORDER BY ALL" + } ] +} + + +-- !query +EXECUTE IMMEDIATE + 'SELECT IDENTIFIER(:col1), IDENTIFIER(:p ''2'') FROM IDENTIFIER(:schema ''.'' :tab) WHERE IDENTIFIER(:col1) > 0 ORDER BY IDENTIFIER(:p ''1'')' + USING 'c1' AS col1, 'c' AS p, 'identifier_clause_test_schema' AS schema, 'integration_test' AS tab +-- !query schema +struct +-- !query output +1 a +2 b + + +-- !query +EXECUTE IMMEDIATE 'SELECT * FROM IDENTIFIER(:schema ''.'' :table) WHERE IDENTIFIER(concat(:tab_alias, ''.c1'')) > 0 ORDER BY ALL' + USING 'identifier_clause_test_schema' AS schema, 'integration_test' AS table, 'integration_test' AS tab_alias +-- !query schema +struct +-- !query output +1 a +2 b + + +-- !query +EXECUTE IMMEDIATE 'SELECT 1 AS IDENTIFIER(:schema ''.'' :col)' + USING 'identifier_clause_test_schema' AS schema, 'col1' AS col +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + }, + "queryContext" : [ { + "objectType" : "EXECUTE IMMEDIATE", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 40, + "fragment" : "SELECT 1 AS IDENTIFIER(:schema '.' :col)" + } ] +} + + +-- !query +DROP TABLE integration_test +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE integration_test2 +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE lateral_test(arr ARRAY) USING PARQUET +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO lateral_test VALUES (array(1, 2, 3)) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT * FROM lateral_test LATERAL VIEW explode(arr) IDENTIFIER('tbl') AS IDENTIFIER('col') ORDER BY ALL +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +SELECT * FROM lateral_test LATERAL VIEW OUTER explode(arr) IDENTIFIER('my_table') AS IDENTIFIER('my_col') ORDER BY ALL +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +DROP TABLE lateral_test +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE unpivot_test(id INT, a INT, b INT, c INT) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO unpivot_test VALUES (1, 10, 20, 30) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT * FROM unpivot_test UNPIVOT (val FOR col IN (a AS IDENTIFIER('col_a'), b AS IDENTIFIER('col_b'))) ORDER BY ALL +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +SELECT * FROM unpivot_test UNPIVOT ((v1, v2) FOR col IN ((a, b) AS IDENTIFIER('cols_ab'), (b, c) AS IDENTIFIER('cols_bc'))) ORDER BY ALL +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +DROP TABLE unpivot_test +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT :IDENTIFIER('param1') FROM VALUES(1) AS T(c1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "''param1''", + "hint" : "" + } +} + + +-- !query +CREATE TABLE hint_test(c1 INT, c2 INT) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO hint_test VALUES (1, 2), (3, 4) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT /*+ IDENTIFIER('BROADCAST')(hint_test) */ * FROM hint_test +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +SELECT /*+ IDENTIFIER('MERGE')(hint_test) */ * FROM hint_test +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +DROP TABLE hint_test +-- !query schema +struct<> +-- !query output + + + +-- !query +SHOW IDENTIFIER('USER') FUNCTIONS +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +SELECT EXTRACT(IDENTIFIER('YEAR') FROM DATE'2024-01-15') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +SELECT TIMESTAMPADD(IDENTIFIER('YEAR'), 1, DATE'2024-01-15') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UNRESOLVED_ROUTINE", + "sqlState" : "42883", + "messageParameters" : { + "routineName" : "`TIMESTAMPADD`", + "searchPath" : "[`system`.`builtin`, `system`.`session`, `spark_catalog`.`identifier_clause_test_schema`]" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 60, + "fragment" : "TIMESTAMPADD(IDENTIFIER('YEAR'), 1, DATE'2024-01-15')" + } ] +} + + +-- !query +DROP SCHEMA identifier_clause_test_schema +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/identifier-clause.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/identifier-clause.sql.out index 596745b4ba5..b398c07b14e 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/identifier-clause.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/identifier-clause.sql.out @@ -118,9 +118,11 @@ struct<> -- !query output org.apache.spark.SparkUnsupportedOperationException { - "errorClass" : "_LEGACY_ERROR_TEMP_2096", + "errorClass" : "UNSUPPORTED_FEATURE.TABLE_OPERATION", + "sqlState" : "0A000", "messageParameters" : { - "ddl" : "UPDATE TABLE" + "operation" : "UPDATE TABLE", + "tableName" : "`spark_catalog`.`s`.`tab`" } } @@ -133,9 +135,11 @@ struct<> -- !query output org.apache.spark.SparkUnsupportedOperationException { - "errorClass" : "_LEGACY_ERROR_TEMP_2096", + "errorClass" : "UNSUPPORTED_FEATURE.TABLE_OPERATION", + "sqlState" : "0A000", "messageParameters" : { - "ddl" : "MERGE INTO TABLE" + "operation" : "MERGE INTO TABLE", + "tableName" : "`spark_catalog`.`s`.`tab`" } } @@ -842,6 +846,137 @@ org.apache.spark.sql.AnalysisException } +-- !query +CREATE TABLE t(col1 INT) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT * FROM IDENTIFIER((SELECT 't')) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "NOT_A_CONSTANT_STRING.NOT_CONSTANT", + "sqlState" : "42601", + "messageParameters" : { + "expr" : "scalarsubquery()", + "name" : "IDENTIFIER" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 26, + "stopIndex" : 37, + "fragment" : "(SELECT 't')" + } ] +} + + +-- !query +SELECT * FROM (SELECT IDENTIFIER((SELECT 'col1')) FROM IDENTIFIER((SELECT 't'))) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "NOT_A_CONSTANT_STRING.NOT_CONSTANT", + "sqlState" : "42601", + "messageParameters" : { + "expr" : "scalarsubquery()", + "name" : "IDENTIFIER" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 67, + "stopIndex" : 78, + "fragment" : "(SELECT 't')" + } ] +} + + +-- !query +SELECT IDENTIFIER((SELECT 'col1')) FROM VALUES(1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "NOT_A_CONSTANT_STRING.NOT_CONSTANT", + "sqlState" : "42601", + "messageParameters" : { + "expr" : "scalarsubquery()", + "name" : "IDENTIFIER" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 19, + "stopIndex" : 33, + "fragment" : "(SELECT 'col1')" + } ] +} + + +-- !query +SELECT col1, IDENTIFIER((SELECT col1)) FROM VALUES(1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "NOT_A_CONSTANT_STRING.NOT_CONSTANT", + "sqlState" : "42601", + "messageParameters" : { + "expr" : "scalarsubquery(col1)", + "name" : "IDENTIFIER" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 25, + "stopIndex" : 37, + "fragment" : "(SELECT col1)" + } ] +} + + +-- !query +SELECT IDENTIFIER((SELECT 'col1', 'col2')) FROM VALUES(1,2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "UNSUPPORTED_TYPED_LITERAL", + "sqlState" : "0A000", + "messageParameters" : { + "supportedTypes" : "\"DATE\", \"TIMESTAMP_NTZ\", \"TIMESTAMP_LTZ\", \"TIMESTAMP\", \"INTERVAL\", \"X\", \"TIME\"", + "unsupportedType" : "\"SELECT\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 20, + "stopIndex" : 32, + "fragment" : "SELECT 'col1'" + } ] +} + + +-- !query +DROP TABLE t +-- !query schema +struct<> +-- !query output + + + -- !query CREATE TABLE IDENTIFIER(1)(c1 INT) USING csv -- !query schema @@ -980,7 +1115,8 @@ org.apache.spark.sql.AnalysisException "errorClass" : "IDENTIFIER_TOO_MANY_NAME_PARTS", "sqlState" : "42601", "messageParameters" : { - "identifier" : "`a`.`b`.`c`.`d`" + "identifier" : "`a`.`b`.`c`.`d`", + "limit" : "2" }, "queryContext" : [ { "objectType" : "", @@ -1175,29 +1311,28 @@ struct<> -- !query output org.apache.spark.sql.catalyst.parser.ParseException { - "errorClass" : "PARSE_SYNTAX_ERROR", + "errorClass" : "IDENTIFIER_TOO_MANY_NAME_PARTS", "sqlState" : "42601", "messageParameters" : { - "error" : "''x.win''", - "hint" : "" - } + "identifier" : "`x`.`win`", + "limit" : "1" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 26, + "stopIndex" : 44, + "fragment" : "IDENTIFIER('x.win')" + } ] } -- !query SELECT T1.c1 FROM VALUES(1) AS T1(c1) JOIN VALUES(1) AS T2(c1) USING (IDENTIFIER('c1')) -- !query schema -struct<> +struct -- !query output -org.apache.spark.sql.catalyst.parser.ParseException -{ - "errorClass" : "PARSE_SYNTAX_ERROR", - "sqlState" : "42601", - "messageParameters" : { - "error" : "'('", - "hint" : "" - } -} +1 -- !query @@ -1226,33 +1361,17 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException -- !query SELECT map('a', 1).IDENTIFIER('a') FROM VALUES(1) AS T(c1) -- !query schema -struct<> +struct -- !query output -org.apache.spark.sql.catalyst.parser.ParseException -{ - "errorClass" : "PARSE_SYNTAX_ERROR", - "sqlState" : "42601", - "messageParameters" : { - "error" : "''a''", - "hint" : "" - } -} +1 -- !query SELECT named_struct('a', 1).IDENTIFIER('a') FROM VALUES(1) AS T(c1) -- !query schema -struct<> +struct -- !query output -org.apache.spark.sql.catalyst.parser.ParseException -{ - "errorClass" : "PARSE_SYNTAX_ERROR", - "sqlState" : "42601", - "messageParameters" : { - "error" : "''a''", - "hint" : "" - } -} +1 -- !query @@ -1260,12 +1379,12 @@ SELECT * FROM s.IDENTIFIER('tab') -- !query schema struct<> -- !query output -org.apache.spark.sql.catalyst.parser.ParseException +org.apache.spark.sql.catalyst.ExtendedAnalysisException { - "errorClass" : "INVALID_SQL_SYNTAX.INVALID_TABLE_VALUED_FUNC_NAME", - "sqlState" : "42000", + "errorClass" : "TABLE_OR_VIEW_NOT_FOUND", + "sqlState" : "42P01", "messageParameters" : { - "funcName" : "`s`.`IDENTIFIER`" + "relationName" : "`s`.`tab`" }, "queryContext" : [ { "objectType" : "", @@ -1282,14 +1401,20 @@ SELECT * FROM IDENTIFIER('s').IDENTIFIER('tab') -- !query schema struct<> -- !query output -org.apache.spark.sql.catalyst.parser.ParseException +org.apache.spark.sql.catalyst.ExtendedAnalysisException { - "errorClass" : "PARSE_SYNTAX_ERROR", - "sqlState" : "42601", + "errorClass" : "TABLE_OR_VIEW_NOT_FOUND", + "sqlState" : "42P01", "messageParameters" : { - "error" : "'.'", - "hint" : "" - } + "relationName" : "`s`.`tab`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 15, + "stopIndex" : 47, + "fragment" : "IDENTIFIER('s').IDENTIFIER('tab')" + } ] } @@ -1298,95 +1423,85 @@ SELECT * FROM IDENTIFIER('s').tab -- !query schema struct<> -- !query output -org.apache.spark.sql.catalyst.parser.ParseException +org.apache.spark.sql.catalyst.ExtendedAnalysisException { - "errorClass" : "PARSE_SYNTAX_ERROR", - "sqlState" : "42601", + "errorClass" : "TABLE_OR_VIEW_NOT_FOUND", + "sqlState" : "42P01", "messageParameters" : { - "error" : "'.'", - "hint" : "" - } + "relationName" : "`s`.`tab`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 15, + "stopIndex" : 33, + "fragment" : "IDENTIFIER('s').tab" + } ] } -- !query SELECT row_number() OVER IDENTIFIER('win') FROM VALUES(1) AS T(c1) WINDOW win AS (ORDER BY c1) -- !query schema -struct<> +struct -- !query output -org.apache.spark.sql.catalyst.parser.ParseException -{ - "errorClass" : "PARSE_SYNTAX_ERROR", - "sqlState" : "42601", - "messageParameters" : { - "error" : "''win''", - "hint" : "" - } -} +1 -- !query SELECT row_number() OVER win FROM VALUES(1) AS T(c1) WINDOW IDENTIFIER('win') AS (ORDER BY c1) -- !query schema -struct<> +struct -- !query output -org.apache.spark.sql.catalyst.parser.ParseException -{ - "errorClass" : "PARSE_SYNTAX_ERROR", - "sqlState" : "42601", - "messageParameters" : { - "error" : "'WINDOW'", - "hint" : "" - } -} +1 + + +-- !query +SELECT 1 AS IDENTIFIER('col1') +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT my_table.* FROM VALUES (1, 2) AS IDENTIFIER('my_table')(IDENTIFIER('c1'), IDENTIFIER('c2')) +-- !query schema +struct +-- !query output +1 2 -- !query WITH identifier('v')(identifier('c1')) AS (VALUES(1)) (SELECT c1 FROM v) -- !query schema -struct<> +struct -- !query output -org.apache.spark.sql.catalyst.parser.ParseException -{ - "errorClass" : "PARSE_SYNTAX_ERROR", - "sqlState" : "42601", - "messageParameters" : { - "error" : "''v''", - "hint" : "" - } -} +1 -- !query -INSERT INTO tab(IDENTIFIER('c1')) VALUES(1) +CREATE OR REPLACE VIEW v(IDENTIFIER('c1')) AS VALUES(1) -- !query schema struct<> -- !query output -org.apache.spark.sql.catalyst.parser.ParseException -{ - "errorClass" : "PARSE_SYNTAX_ERROR", - "sqlState" : "42601", - "messageParameters" : { - "error" : "'('", - "hint" : ": missing ')'" - } -} + -- !query -CREATE OR REPLACE VIEW v(IDENTIFIER('c1')) AS VALUES(1) +SELECT c1 FROM v +-- !query schema +struct +-- !query output +1 + + +-- !query +DROP VIEW IF EXISTS v -- !query schema struct<> -- !query output -org.apache.spark.sql.catalyst.parser.ParseException -{ - "errorClass" : "PARSE_SYNTAX_ERROR", - "sqlState" : "42601", - "messageParameters" : { - "error" : "'('", - "hint" : "" - } -} + -- !query @@ -1394,12 +1509,1023 @@ CREATE TABLE tab(IDENTIFIER('c1') INT) USING CSV -- !query schema struct<> -- !query output -org.apache.spark.sql.catalyst.parser.ParseException -{ - "errorClass" : "PARSE_SYNTAX_ERROR", - "sqlState" : "42601", + + + +-- !query +INSERT INTO tab(IDENTIFIER('c1')) VALUES(1) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT c1 FROM tab +-- !query schema +struct +-- !query output +1 + + +-- !query +ALTER TABLE IDENTIFIER('tab') RENAME COLUMN IDENTIFIER('c1') TO IDENTIFIER('col1') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UNSUPPORTED_FEATURE.TABLE_OPERATION", + "sqlState" : "0A000", + "messageParameters" : { + "operation" : "RENAME COLUMN", + "tableName" : "`spark_catalog`.`default`.`tab`" + } +} + + +-- !query +SELECT col1 FROM tab +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col1`", + "proposal" : "`c1`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 11, + "fragment" : "col1" + } ] +} + + +-- !query +ALTER TABLE IDENTIFIER('tab') ADD COLUMN IDENTIFIER('c2') INT +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT c2 FROM tab +-- !query schema +struct +-- !query output +NULL + + +-- !query +ALTER TABLE IDENTIFIER('tab') DROP COLUMN IDENTIFIER('c2') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UNSUPPORTED_FEATURE.TABLE_OPERATION", + "sqlState" : "0A000", + "messageParameters" : { + "operation" : "DROP COLUMN", + "tableName" : "`spark_catalog`.`default`.`tab`" + } +} + + +-- !query +ALTER TABLE IDENTIFIER('tab') RENAME TO IDENTIFIER('tab_renamed') +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT * FROM tab_renamed +-- !query schema +struct +-- !query output +1 NULL + + +-- !query +DROP TABLE IF EXISTS tab_renamed +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS tab +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE test_col_with_dot(IDENTIFIER('`col.with.dot`') INT) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS test_col_with_dot +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT * FROM VALUES (1, 2) AS IDENTIFIER('schema.table')(c1, c2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "IDENTIFIER_TOO_MANY_NAME_PARTS", + "sqlState" : "42601", + "messageParameters" : { + "identifier" : "`schema`.`table`", + "limit" : "1" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 15, + "stopIndex" : 65, + "fragment" : "VALUES (1, 2) AS IDENTIFIER('schema.table')(c1, c2)" + } ] +} + + +-- !query +SELECT 1 AS IDENTIFIER('col1.col2') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "IDENTIFIER_TOO_MANY_NAME_PARTS", + "sqlState" : "42601", + "messageParameters" : { + "identifier" : "`col1`.`col2`", + "limit" : "1" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 35, + "fragment" : "1 AS IDENTIFIER('col1.col2')" + } ] +} + + +-- !query +CREATE SCHEMA identifier_clause_test_schema +-- !query schema +struct<> +-- !query output + + + +-- !query +USE identifier_clause_test_schema +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE test_show(c1 INT, c2 STRING) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +SHOW VIEWS IN IDENTIFIER('identifier_clause_test_schema') +-- !query schema +struct +-- !query output + + + +-- !query +SHOW PARTITIONS IDENTIFIER('test_show') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_PARTITION_OPERATION.PARTITION_SCHEMA_IS_EMPTY", + "sqlState" : "42601", + "messageParameters" : { + "name" : "`spark_catalog`.`identifier_clause_test_schema`.`test_show`" + } +} + + +-- !query +SHOW CREATE TABLE IDENTIFIER('test_show') +-- !query schema +struct +-- !query output +CREATE TABLE spark_catalog.identifier_clause_test_schema.test_show ( + c1 INT, + c2 STRING) +USING CSV + + +-- !query +DROP TABLE test_show +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE test_desc(c1 INT) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +DESCRIBE TABLE IDENTIFIER('test_desc') +-- !query schema +struct +-- !query output +c1 int + + +-- !query +DESCRIBE FORMATTED IDENTIFIER('test_desc') +-- !query schema +struct +-- !query output +c1 int + +# Detailed Table Information +Catalog spark_catalog +Database identifier_clause_test_schema +Table test_desc +Created Time [not included in comparison] +Last Access [not included in comparison] +Created By [not included in comparison] +Type MANAGED +Provider CSV +Location [not included in comparison]/{warehouse_dir}/identifier_clause_test_schema.db/test_desc + + +-- !query +DESCRIBE EXTENDED IDENTIFIER('test_desc') +-- !query schema +struct +-- !query output +c1 int + +# Detailed Table Information +Catalog spark_catalog +Database identifier_clause_test_schema +Table test_desc +Created Time [not included in comparison] +Last Access [not included in comparison] +Created By [not included in comparison] +Type MANAGED +Provider CSV +Location [not included in comparison]/{warehouse_dir}/identifier_clause_test_schema.db/test_desc + + +-- !query +DESC IDENTIFIER('test_desc') +-- !query schema +struct +-- !query output +c1 int + + +-- !query +DROP TABLE test_desc +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE test_comment(c1 INT, c2 STRING) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +COMMENT ON TABLE IDENTIFIER('test_comment') IS 'table comment' +-- !query schema +struct<> +-- !query output + + + +-- !query +ALTER TABLE test_comment ALTER COLUMN IDENTIFIER('c1') COMMENT 'column comment' +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE test_comment +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE identifier_clause_test_schema.test_table(c1 INT) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +ANALYZE TABLE IDENTIFIER('identifier_clause_test_schema.test_table') COMPUTE STATISTICS +-- !query schema +struct<> +-- !query output + + + +-- !query +REFRESH TABLE IDENTIFIER('identifier_clause_test_schema.test_table') +-- !query schema +struct<> +-- !query output + + + +-- !query +DESCRIBE IDENTIFIER('identifier_clause_test_schema.test_table') +-- !query schema +struct +-- !query output +c1 int + + +-- !query +SHOW COLUMNS FROM IDENTIFIER('identifier_clause_test_schema.test_table') +-- !query schema +struct +-- !query output +c1 + + +-- !query +DROP TABLE IDENTIFIER('identifier_clause_test_schema.test_table') +-- !query schema +struct<> +-- !query output + + + +-- !query +DECLARE IDENTIFIER('my_var') = 'value' +-- !query schema +struct<> +-- !query output + + + +-- !query +SET VAR IDENTIFIER('my_var') = 'new_value' +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT IDENTIFIER('my_var') +-- !query schema +struct +-- !query output +new_value + + +-- !query +DROP TEMPORARY VARIABLE IDENTIFIER('my_var') +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TEMPORARY FUNCTION test_udf(IDENTIFIER('param1') INT, IDENTIFIER('param2') STRING) +RETURNS INT +RETURN IDENTIFIER('param1') + length(IDENTIFIER('param2')) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT test_udf(5, 'hello') +-- !query schema +struct +-- !query output +10 + + +-- !query +DROP TEMPORARY FUNCTION test_udf +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TEMPORARY FUNCTION test_table_udf(IDENTIFIER('input_val') INT) +RETURNS TABLE(IDENTIFIER('col1') INT, IDENTIFIER('col2') STRING) +RETURN SELECT IDENTIFIER('input_val'), 'result' +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT * FROM test_table_udf(42) +-- !query schema +struct +-- !query output +42 result + + +-- !query +DROP TEMPORARY FUNCTION test_table_udf +-- !query schema +struct<> +-- !query output + + + +-- !query +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(:tab \'b\').c1 FROM VALUES(1) AS tab(c1)' USING 'ta' AS tab +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_EXTRACT_BASE_FIELD_TYPE", + "sqlState" : "42000", + "messageParameters" : { + "base" : "\"variablereference(system.session.tab='T')\"", + "other" : "\"STRING\"" + } +} + + +-- !query +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(:col1 ''.c2'') FROM VALUES(named_struct(''c2'', 42)) AS T(c1)' + USING 'c1' AS col1 +-- !query schema +struct +-- !query output +42 + + +-- !query +CREATE TABLE integration_test(c1 INT, c2 STRING) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO integration_test VALUES (1, 'a'), (2, 'b') +-- !query schema +struct<> +-- !query output + + + +-- !query +EXECUTE IMMEDIATE 'SELECT * FROM IDENTIFIER(:schema ''.'' :table) ORDER BY ALL' + USING 'identifier_clause_test_schema' AS schema, 'integration_test' AS table +-- !query schema +struct +-- !query output +1 a +2 b + + +-- !query +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(:prefix ''1''), IDENTIFIER(:prefix ''2'') FROM integration_test ORDER BY ALL' + USING 'c' AS prefix +-- !query schema +struct +-- !query output +1 a +2 b + + +-- !query +EXECUTE IMMEDIATE 'SELECT * FROM integration_test WHERE IDENTIFIER(:col) = :val' + USING 'c1' AS col, 1 AS val +-- !query schema +struct +-- !query output +1 a + + +-- !query +CREATE TABLE integration_test2(c1 INT, c3 STRING) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO integration_test2 VALUES (1, 'x'), (2, 'y') +-- !query schema +struct<> +-- !query output + + + +-- !query +EXECUTE IMMEDIATE 'SELECT t1.*, t2.* FROM IDENTIFIER(:t1) t1 JOIN IDENTIFIER(:t2) t2 USING (IDENTIFIER(:col)) ORDER BY ALL' + USING 'integration_test' AS t1, 'integration_test2' AS t2, 'c1' AS col +-- !query schema +struct +-- !query output +1 a 1 x +2 b 2 y + + +-- !query +EXECUTE IMMEDIATE + 'SELECT IDENTIFIER(:col1), IDENTIFIER(:col2), row_number() OVER (PARTITION BY IDENTIFIER(:part) ORDER BY IDENTIFIER(:ord)) as rn FROM integration_test' + USING 'c1' AS col1, 'c2' AS col2, 'c2' AS part, 'c1' AS ord +-- !query schema +struct +-- !query output +1 a 1 +2 b 1 + + +-- !query +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(:prefix ''2''), IDENTIFIER(:agg)(IDENTIFIER(:col)) FROM integration_test GROUP BY IDENTIFIER(:prefix ''2'') ORDER BY ALL' + USING 'c' AS prefix, 'count' AS agg, 'c1' AS col +-- !query schema +struct +-- !query output +a 1 +b 1 + + +-- !query +EXECUTE IMMEDIATE 'SELECT * FROM integration_test ORDER BY IDENTIFIER(:col1) DESC, IDENTIFIER(:col2)' + USING 'c1' AS col1, 'c2' AS col2 +-- !query schema +struct +-- !query output +2 b +1 a + + +-- !query +EXECUTE IMMEDIATE 'INSERT INTO integration_test(IDENTIFIER(:col1), IDENTIFIER(:col2)) VALUES (:val1, :val2)' + USING 'c1' AS col1, 'c2' AS col2, 3 AS val1, 'c' AS val2 +-- !query schema +struct<> +-- !query output + + + +-- !query +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(concat(:schema, ''.'', :table, ''.c1'')) FROM VALUES(named_struct(''c1'', 100)) AS IDENTIFIER(:alias)(IDENTIFIER(:schema ''.'' :table))' + USING 'identifier_clause_test_schema' AS schema, 'my_table' AS table, 't' AS alias +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "IDENTIFIER_TOO_MANY_NAME_PARTS", + "sqlState" : "42601", + "messageParameters" : { + "identifier" : "`identifier_clause_test_schema`.`my_table`", + "limit" : "1" + }, + "queryContext" : [ { + "objectType" : "EXECUTE IMMEDIATE", + "objectName" : "", + "startIndex" : 115, + "stopIndex" : 144, + "fragment" : "IDENTIFIER(:schema '.' :table)" + } ] +} + + +-- !query +EXECUTE IMMEDIATE 'WITH IDENTIFIER(:cte_name)(c1) AS (VALUES(1)) SELECT c1 FROM IDENTIFIER(:cte_name)' + USING 'my_cte' AS cte_name +-- !query schema +struct +-- !query output +1 + + +-- !query +EXECUTE IMMEDIATE 'CREATE OR REPLACE TEMPORARY VIEW IDENTIFIER(:view_name)(IDENTIFIER(:col_name)) AS VALUES(1)' + USING 'test_view' AS view_name, 'test_col' AS col_name +-- !query schema +struct<> +-- !query output + + + +-- !query +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(:col) FROM IDENTIFIER(:view)' + USING 'test_col' AS col, 'test_view' AS view +-- !query schema +struct +-- !query output +1 + + +-- !query +DROP VIEW test_view +-- !query schema +struct<> +-- !query output + + + +-- !query +EXECUTE IMMEDIATE 'ALTER TABLE IDENTIFIER(:tab) ADD COLUMN IDENTIFIER(:new_col) INT' + USING 'integration_test' AS tab, 'c4' AS new_col +-- !query schema +struct<> +-- !query output + + + +-- !query +EXECUTE IMMEDIATE 'ALTER TABLE IDENTIFIER(:tab) RENAME COLUMN IDENTIFIER(:old_col) TO IDENTIFIER(:new_col)' + USING 'integration_test' AS tab, 'c4' AS old_col, 'c5' AS new_col +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UNSUPPORTED_FEATURE.TABLE_OPERATION", + "sqlState" : "0A000", + "messageParameters" : { + "operation" : "RENAME COLUMN", + "tableName" : "`spark_catalog`.`identifier_clause_test_schema`.`integration_test`" + } +} + + +-- !query +EXECUTE IMMEDIATE 'SELECT map(:key, :val).IDENTIFIER(:key) AS result' + USING 'mykey' AS key, 42 AS val +-- !query schema +struct +-- !query output +42 + + +-- !query +EXECUTE IMMEDIATE 'SELECT IDENTIFIER(:alias ''.c1'') FROM integration_test AS IDENTIFIER(:alias) ORDER BY ALL' + USING 't' AS alias +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`t`.`c1`", + "proposal" : "`IDENTIFIER('t')`.`c1`, `IDENTIFIER('t')`.`c2`, `IDENTIFIER('t')`.`c4`" + }, + "queryContext" : [ { + "objectType" : "EXECUTE IMMEDIATE", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 31, + "fragment" : "IDENTIFIER(:alias '.c1')" + } ] +} + + +-- !query +EXECUTE IMMEDIATE + 'SELECT IDENTIFIER(:col1), IDENTIFIER(:p ''2'') FROM IDENTIFIER(:schema ''.'' :tab) WHERE IDENTIFIER(:col1) > 0 ORDER BY IDENTIFIER(:p ''1'')' + USING 'c1' AS col1, 'c' AS p, 'identifier_clause_test_schema' AS schema, 'integration_test' AS tab +-- !query schema +struct +-- !query output +1 a +2 b +3 c + + +-- !query +EXECUTE IMMEDIATE 'SELECT * FROM IDENTIFIER(:schema ''.'' :table) WHERE IDENTIFIER(concat(:tab_alias, ''.c1'')) > 0 ORDER BY ALL' + USING 'identifier_clause_test_schema' AS schema, 'integration_test' AS table, 'integration_test' AS tab_alias +-- !query schema +struct +-- !query output +1 a NULL +2 b NULL +3 c NULL + + +-- !query +EXECUTE IMMEDIATE 'SELECT 1 AS IDENTIFIER(:schema ''.'' :col)' + USING 'identifier_clause_test_schema' AS schema, 'col1' AS col +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "IDENTIFIER_TOO_MANY_NAME_PARTS", + "sqlState" : "42601", + "messageParameters" : { + "identifier" : "`identifier_clause_test_schema`.`col1`", + "limit" : "1" + }, + "queryContext" : [ { + "objectType" : "EXECUTE IMMEDIATE", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 40, + "fragment" : "1 AS IDENTIFIER(:schema '.' :col)" + } ] +} + + +-- !query +DROP TABLE integration_test +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE integration_test2 +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE lateral_test(arr ARRAY) USING PARQUET +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO lateral_test VALUES (array(1, 2, 3)) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT * FROM lateral_test LATERAL VIEW explode(arr) IDENTIFIER('tbl') AS IDENTIFIER('col') ORDER BY ALL +-- !query schema +struct,col:int> +-- !query output +[1,2,3] 1 +[1,2,3] 2 +[1,2,3] 3 + + +-- !query +SELECT * FROM lateral_test LATERAL VIEW OUTER explode(arr) IDENTIFIER('my_table') AS IDENTIFIER('my_col') ORDER BY ALL +-- !query schema +struct,my_col:int> +-- !query output +[1,2,3] 1 +[1,2,3] 2 +[1,2,3] 3 + + +-- !query +DROP TABLE lateral_test +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE unpivot_test(id INT, a INT, b INT, c INT) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO unpivot_test VALUES (1, 10, 20, 30) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT * FROM unpivot_test UNPIVOT (val FOR col IN (a AS IDENTIFIER('col_a'), b AS IDENTIFIER('col_b'))) ORDER BY ALL +-- !query schema +struct +-- !query output +1 30 col_a 10 +1 30 col_b 20 + + +-- !query +SELECT * FROM unpivot_test UNPIVOT ((v1, v2) FOR col IN ((a, b) AS IDENTIFIER('cols_ab'), (b, c) AS IDENTIFIER('cols_bc'))) ORDER BY ALL +-- !query schema +struct +-- !query output +1 cols_ab 10 20 +1 cols_bc 20 30 + + +-- !query +DROP TABLE unpivot_test +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT :IDENTIFIER('param1') FROM VALUES(1) AS T(c1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "''param1''", + "hint" : "" + } +} + + +-- !query +CREATE TABLE hint_test(c1 INT, c2 INT) USING CSV +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO hint_test VALUES (1, 2), (3, 4) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT /*+ IDENTIFIER('BROADCAST')(hint_test) */ * FROM hint_test +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +SELECT /*+ IDENTIFIER('MERGE')(hint_test) */ * FROM hint_test +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + } +} + + +-- !query +DROP TABLE hint_test +-- !query schema +struct<> +-- !query output + + + +-- !query +SHOW IDENTIFIER('USER') FUNCTIONS +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", "messageParameters" : { "error" : "'('", "hint" : "" } } + + +-- !query +SELECT EXTRACT(IDENTIFIER('YEAR') FROM DATE'2024-01-15') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'FROM'", + "hint" : ": missing ')'" + } +} + + +-- !query +SELECT TIMESTAMPADD(IDENTIFIER('YEAR'), 1, DATE'2024-01-15') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UNRESOLVED_ROUTINE", + "sqlState" : "42883", + "messageParameters" : { + "routineName" : "`TIMESTAMPADD`", + "searchPath" : "[`system`.`builtin`, `system`.`session`, `spark_catalog`.`identifier_clause_test_schema`]" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 60, + "fragment" : "TIMESTAMPADD(IDENTIFIER('YEAR'), 1, DATE'2024-01-15')" + } ] +} + + +-- !query +DROP SCHEMA identifier_clause_test_schema +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/interval.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/interval.sql.out index c32ecc19448..79fce5906df 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/interval.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/interval.sql.out @@ -75,8 +75,11 @@ select interval 2147483647 day * 2 -- !query schema struct<> -- !query output -java.lang.ArithmeticException -long overflow +org.apache.spark.SparkArithmeticException +{ + "errorClass" : "INTERVAL_ARITHMETIC_OVERFLOW.WITHOUT_SUGGESTION", + "sqlState" : "22015" +} -- !query @@ -84,8 +87,11 @@ select interval 2147483647 day / 0.5 -- !query schema struct<> -- !query output -java.lang.ArithmeticException -long overflow +org.apache.spark.SparkArithmeticException +{ + "errorClass" : "INTERVAL_ARITHMETIC_OVERFLOW.WITHOUT_SUGGESTION", + "sqlState" : "22015" +} -- !query @@ -3897,3 +3903,15 @@ SELECT width_bucket(INTERVAL '-59' MINUTE, INTERVAL -'1 01' DAY TO HOUR, INTERVA struct -- !query output 5 + + +-- !query +SELECT interval 106751991 day 4 hour 0 minute 54.776 second +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkArithmeticException +{ + "errorClass" : "INTERVAL_ARITHMETIC_OVERFLOW.WITHOUT_SUGGESTION", + "sqlState" : "22015" +} diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/join-resolution-edge-cases.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/join-resolution-edge-cases.sql.out new file mode 100644 index 00000000000..da55e1c1cf5 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/join-resolution-edge-cases.sql.out @@ -0,0 +1,168 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +CREATE TABLE t1(col1 INT, col2 STRING) +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE t2(col1 INT, col2 STRING) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT * FROM t2 as t2_1 LEFT JOIN t2 as t2_2 ON t2_1.col1 = t2_2.col1 + NATURAL JOIN t2 as t2_3 +-- !query schema +struct +-- !query output + + + +-- !query +SELECT * FROM t2 as t2_1 RIGHT JOIN t2 as t2_2 ON t2_1.col1 = t2_2.col1 + NATURAL JOIN t2 as t2_3 +-- !query schema +struct +-- !query output + + + +-- !query +SELECT * FROM t2 as t2_1 CROSS JOIN t2 as t2_2 ON t2_1.col1 = t2_2.col1 + NATURAL JOIN t2 as t2_3 +-- !query schema +struct +-- !query output + + + +-- !query +SELECT * FROM t2 as t2_1 INNER JOIN t2 as t2_2 ON t2_1.col1 = t2_2.col1 + NATURAL JOIN t2 as t2_3 +-- !query schema +struct +-- !query output + + + +-- !query +SELECT col2 AS alias FROM t1 as t1_1 LEFT ANTI JOIN t1 as t1_2 ON t1_1.col1 = t1_2.col1 ORDER BY col2 +-- !query schema +struct +-- !query output + + + +-- !query +SELECT col2 AS alias FROM t1 as t1_1 LEFT SEMI JOIN t1 as t1_2 ON t1_1.col1 = t1_2.col1 ORDER BY col2 +-- !query schema +struct +-- !query output + + + +-- !query +SELECT col1 FROM t1 as t1_1 LEFT SEMI JOIN t1 as t1_2 ORDER BY col2 +-- !query schema +struct +-- !query output + + + +-- !query +SELECT col1 FROM t1 as t1_1 LEFT SEMI JOIN t1 as t1_2 GROUP BY ALL HAVING MIN(col2) > 1 +-- !query schema +struct +-- !query output + + + +-- !query +SELECT 1 FROM t2 NATURAL JOIN t1 JOIN t2 ON t2.col1 = t1.col1 WHERE t2.col2 = 1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "AMBIGUOUS_REFERENCE", + "sqlState" : "42704", + "messageParameters" : { + "name" : "`t2`.`col1`", + "referenceNames" : "[`spark_catalog`.`default`.`t2`.`col1`, `spark_catalog`.`default`.`t2`.`col1`]" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 45, + "stopIndex" : 51, + "fragment" : "t2.col1" + } ] +} + + +-- !query +SELECT 1 FROM t2 NATURAL JOIN t1 JOIN t2 ON t2.col1 = t1.col1 GROUP BY t2.col2 HAVING t2.col2 = 1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "AMBIGUOUS_REFERENCE", + "sqlState" : "42704", + "messageParameters" : { + "name" : "`t2`.`col1`", + "referenceNames" : "[`spark_catalog`.`default`.`t2`.`col1`, `spark_catalog`.`default`.`t2`.`col1`]" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 45, + "stopIndex" : 51, + "fragment" : "t2.col1" + } ] +} + + +-- !query +SELECT 1 FROM t2 NATURAL JOIN t1 JOIN t2 ON t2.col1 = t1.col1 ORDER BY t2.col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "AMBIGUOUS_REFERENCE", + "sqlState" : "42704", + "messageParameters" : { + "name" : "`t2`.`col1`", + "referenceNames" : "[`spark_catalog`.`default`.`t2`.`col1`, `spark_catalog`.`default`.`t2`.`col1`]" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 45, + "stopIndex" : 51, + "fragment" : "t2.col1" + } ] +} + + +-- !query +DROP TABLE t1 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE t2 +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/keywords-enforced.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/keywords-enforced.sql.out index dbb4a9a14b5..b8443e417ca 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/keywords-enforced.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/keywords-enforced.sql.out @@ -92,6 +92,7 @@ DECLARE false DEFAULT false DEFINED false DEFINER false +DELAY false DELETE false DELIMITED false DESC false @@ -109,6 +110,7 @@ DROP false ELSE true ELSEIF false END true +ENFORCED false ESCAPE true ESCAPED false EVOLUTION false @@ -131,6 +133,7 @@ FILEFORMAT false FILTER true FIRST false FLOAT false +FLOW false FOLLOWING false FOR true FOREIGN true @@ -142,6 +145,8 @@ FULL true FUNCTION false FUNCTIONS false GENERATED false +GEOGRAPHY false +GEOMETRY false GLOBAL false GRANT true GROUP true @@ -178,6 +183,7 @@ ITEMS false ITERATE false JOIN true JSON false +KEY false KEYS false LANGUAGE false LAST false @@ -186,6 +192,7 @@ LAZY false LEADING true LEAVE false LEFT true +LEVEL false LIKE false LIMIT false LINES false @@ -201,6 +208,8 @@ LOOP false MACRO false MAP false MATCHED false +MATERIALIZED false +MAX false MERGE false MICROSECOND false MICROSECONDS false @@ -221,6 +230,7 @@ NANOSECONDS false NATURAL true NO false NONE false +NORELY false NOT true NULL true NULLS false @@ -250,6 +260,8 @@ POSITION false PRECEDING false PRIMARY true PRINCIPALS false +PROCEDURE false +PROCEDURES false PROPERTIES false PURGE false QUARTER false @@ -260,10 +272,12 @@ REAL false RECORDREADER false RECORDWRITER false RECOVER false +RECURSION false RECURSIVE true REDUCE false REFERENCES true REFRESH false +RELY false RENAME false REPAIR false REPEAT false @@ -312,6 +326,8 @@ START false STATISTICS false STORED false STRATIFY false +STREAM false +STREAMING false STRING false STRUCT false SUBSTR false @@ -369,6 +385,7 @@ VERSION false VIEW false VIEWS false VOID false +WATERMARK false WEEK false WEEKS false WHEN true @@ -377,6 +394,7 @@ WHILE false WINDOW false WITH true WITHIN true +WITHOUT false X false YEAR false YEARS false diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/keywords.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/keywords.sql.out index fb4c72a88ca..00baa0c7e72 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/keywords.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/keywords.sql.out @@ -92,6 +92,7 @@ DECLARE false DEFAULT false DEFINED false DEFINER false +DELAY false DELETE false DELIMITED false DESC false @@ -109,6 +110,7 @@ DROP false ELSE false ELSEIF false END false +ENFORCED false ESCAPE false ESCAPED false EVOLUTION false @@ -131,6 +133,7 @@ FILEFORMAT false FILTER false FIRST false FLOAT false +FLOW false FOLLOWING false FOR false FOREIGN false @@ -142,6 +145,8 @@ FULL false FUNCTION false FUNCTIONS false GENERATED false +GEOGRAPHY false +GEOMETRY false GLOBAL false GRANT false GROUP false @@ -178,6 +183,7 @@ ITEMS false ITERATE false JOIN false JSON false +KEY false KEYS false LANGUAGE false LAST false @@ -186,6 +192,7 @@ LAZY false LEADING false LEAVE false LEFT false +LEVEL false LIKE false LIMIT false LINES false @@ -201,6 +208,8 @@ LOOP false MACRO false MAP false MATCHED false +MATERIALIZED false +MAX false MERGE false MICROSECOND false MICROSECONDS false @@ -221,6 +230,7 @@ NANOSECONDS false NATURAL false NO false NONE false +NORELY false NOT false NULL false NULLS false @@ -250,6 +260,8 @@ POSITION false PRECEDING false PRIMARY false PRINCIPALS false +PROCEDURE false +PROCEDURES false PROPERTIES false PURGE false QUARTER false @@ -260,10 +272,12 @@ REAL false RECORDREADER false RECORDWRITER false RECOVER false +RECURSION false RECURSIVE false REDUCE false REFERENCES false REFRESH false +RELY false RENAME false REPAIR false REPEAT false @@ -312,6 +326,8 @@ START false STATISTICS false STORED false STRATIFY false +STREAM false +STREAMING false STRING false STRUCT false SUBSTR false @@ -369,6 +385,7 @@ VERSION false VIEW false VIEWS false VOID false +WATERMARK false WEEK false WEEKS false WHEN false @@ -377,6 +394,7 @@ WHILE false WINDOW false WITH false WITHIN false +WITHOUT false X false YEAR false YEARS false diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/kllquantiles.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/kllquantiles.sql.out new file mode 100644 index 00000000000..3618c851939 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/kllquantiles.sql.out @@ -0,0 +1,1443 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +DROP TABLE IF EXISTS t_int_1_5_through_7_11 +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE t_int_1_5_through_7_11 AS +VALUES + (1, 5), (2, 6), (3, 7), (4, 8), (5, 9), (6, 10), (7, 11) AS tab(col1, col2) +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_long_1_5_through_7_11 +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE t_long_1_5_through_7_11 AS +VALUES + (1L, 5L), (2L, 6L), (3L, 7L), (4L, 8L), (5L, 9L), (6L, 10L), (7L, 11L) AS tab(col1, col2) +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_short_1_5_through_7_11 +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE t_short_1_5_through_7_11 AS +VALUES + (CAST(1 AS SMALLINT), CAST(5 AS SMALLINT)), + (CAST(2 AS SMALLINT), CAST(6 AS SMALLINT)), + (CAST(3 AS SMALLINT), CAST(7 AS SMALLINT)), + (CAST(4 AS SMALLINT), CAST(8 AS SMALLINT)), + (CAST(5 AS SMALLINT), CAST(9 AS SMALLINT)), + (CAST(6 AS SMALLINT), CAST(10 AS SMALLINT)), + (CAST(7 AS SMALLINT), CAST(11 AS SMALLINT)) + AS tab(col1, col2) +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_byte_1_5_through_7_11 +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE t_byte_1_5_through_7_11 AS +VALUES + (CAST(1 AS TINYINT), CAST(5 AS TINYINT)), + (CAST(2 AS TINYINT), CAST(6 AS TINYINT)), + (CAST(3 AS TINYINT), CAST(7 AS TINYINT)), + (CAST(4 AS TINYINT), CAST(8 AS TINYINT)), + (CAST(5 AS TINYINT), CAST(9 AS TINYINT)), + (CAST(6 AS TINYINT), CAST(10 AS TINYINT)), + (CAST(7 AS TINYINT), CAST(11 AS TINYINT)) + AS tab(col1, col2) +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_float_1_5_through_7_11 +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE t_float_1_5_through_7_11 AS +VALUES + (CAST(1 AS FLOAT), CAST(5 AS FLOAT)), + (CAST(2 AS FLOAT), CAST(6 AS FLOAT)), + (CAST(3 AS FLOAT), CAST(7 AS FLOAT)), + (CAST(4 AS FLOAT), CAST(8 AS FLOAT)), + (CAST(5 AS FLOAT), CAST(9 AS FLOAT)), + (CAST(6 AS FLOAT), CAST(10 AS FLOAT)), + (CAST(7 AS FLOAT), CAST(11 AS FLOAT)) AS tab(col1, col2) +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_double_1_5_through_7_11 +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE t_double_1_5_through_7_11 AS +VALUES + (CAST(1 AS DOUBLE), CAST(5 AS DOUBLE)), + (CAST(2 AS DOUBLE), CAST(6 AS DOUBLE)), + (CAST(3 AS DOUBLE), CAST(7 AS DOUBLE)), + (CAST(4 AS DOUBLE), CAST(8 AS DOUBLE)), + (CAST(5 AS DOUBLE), CAST(9 AS DOUBLE)), + (CAST(6 AS DOUBLE), CAST(10 AS DOUBLE)), + (CAST(7 AS DOUBLE), CAST(11 AS DOUBLE)) AS tab(col1, col2) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT split(kll_sketch_to_string_bigint(agg), '\n')[1] LIKE '%Kll%' AS str_contains_kll, + abs(kll_sketch_get_quantile_bigint(agg, 0.5) - 4) < 1 AS median_close_to_4, + abs(kll_sketch_get_rank_bigint(agg, 3) - 0.4) < 0.1 AS rank3_close_to_0_4 +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_byte_1_5_through_7_11 +) +-- !query schema +struct +-- !query output +true true true + + +-- !query +SELECT split(kll_sketch_to_string_bigint(agg), '\n')[1] LIKE '%Kll%' AS str_contains_kll, + abs(kll_sketch_get_quantile_bigint(agg, 0.5) - 4) < 1 AS median_close_to_4, + abs(kll_sketch_get_rank_bigint(agg, 3) - 0.4) < 0.1 AS rank3_close_to_0_4 +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_int_1_5_through_7_11 +) +-- !query schema +struct +-- !query output +true true true + + +-- !query +SELECT split(kll_sketch_to_string_bigint(agg), '\n')[1] LIKE '%Kll%' AS str_contains_kll, + abs(kll_sketch_get_quantile_bigint(agg, 0.5) - 4) < 1 AS median_close_to_4, + abs(kll_sketch_get_rank_bigint(agg, 3) - 0.4) < 0.1 AS rank3_close_to_0_4 +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_long_1_5_through_7_11 +) +-- !query schema +struct +-- !query output +true true true + + +-- !query +SELECT split(kll_sketch_to_string_bigint(agg), '\n')[1] LIKE '%Kll%' AS str_contains_kll, + abs(kll_sketch_get_quantile_bigint(agg, 0.5) - 4) < 1 AS median_close_to_4, + abs(kll_sketch_get_rank_bigint(agg, 3) - 0.4) < 0.1 AS rank3_close_to_0_4 +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_short_1_5_through_7_11 +) +-- !query schema +struct +-- !query output +true true true + + +-- !query +SELECT split(kll_sketch_to_string_float(agg), '\n')[1] LIKE '%Kll%' AS str_contains_kll, + abs(kll_sketch_get_quantile_float(agg, 0.5) - 4.0) < 0.5 AS median_close_to_4, + abs(kll_sketch_get_rank_float(agg, 3) - 0.4) < 0.1 AS rank3_close_to_0_4 +FROM ( + SELECT kll_sketch_agg_float(col1) AS agg + FROM t_float_1_5_through_7_11 +) +-- !query schema +struct +-- !query output +true true true + + +-- !query +SELECT split(kll_sketch_to_string_double(agg), '\n')[1] LIKE '%Kll%' AS str_contains_kll, + abs(kll_sketch_get_quantile_double(agg, 0.5) - 4.0) < 0.5 AS median_close_to_4, + abs(kll_sketch_get_rank_double(agg, 3) - 0.4) < 0.1 AS rank3_close_to_0_4 +FROM ( + SELECT kll_sketch_agg_double(col1) AS agg + FROM t_double_1_5_through_7_11 +) +-- !query schema +struct +-- !query output +true true true + + +-- !query +SELECT split(kll_sketch_to_string_double(agg), '\n')[1] LIKE '%Kll%' AS str_contains_kll, + abs(kll_sketch_get_quantile_double(agg, 0.5) - 4.0) < 0.5 AS median_close_to_4, + abs(kll_sketch_get_rank_double(agg, 3) - 0.4) < 0.1 AS rank3_close_to_0_4 +FROM ( + SELECT kll_sketch_agg_double(col1) AS agg + FROM t_float_1_5_through_7_11 +) +-- !query schema +struct +-- !query output +true true true + + +-- !query +SELECT + split( + kll_sketch_to_string_bigint( + kll_sketch_merge_bigint( + kll_sketch_agg_bigint(col1), + kll_sketch_agg_bigint(col1) + ) + ), + '\n' + )[1] AS result + FROM t_byte_1_5_through_7_11 +-- !query schema +struct +-- !query output +### KllKllLongsSketch Summary: + + +-- !query +SELECT + split( + kll_sketch_to_string_float( + kll_sketch_merge_float( + kll_sketch_agg_float(col1), + kll_sketch_agg_float(col1) + ) + ), + '\n' + )[1] AS result +FROM t_byte_1_5_through_7_11 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"col1\"", + "inputType" : "\"TINYINT\"", + "paramIndex" : "first", + "requiredType" : "\"FLOAT\"", + "sqlExpr" : "\"kll_sketch_agg_float(col1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 87, + "stopIndex" : 112, + "fragment" : "kll_sketch_agg_float(col1)" + } ] +} + + +-- !query +SELECT + split( + kll_sketch_to_string_double( + kll_sketch_merge_double( + kll_sketch_agg_double(col1), + kll_sketch_agg_double(col1) + ) + ), + '\n' + )[1] AS result +FROM t_byte_1_5_through_7_11 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"col1\"", + "inputType" : "\"TINYINT\"", + "paramIndex" : "first", + "requiredType" : "(\"FLOAT\" or \"DOUBLE\")", + "sqlExpr" : "\"kll_sketch_agg_double(col1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 89, + "stopIndex" : 115, + "fragment" : "kll_sketch_agg_double(col1)" + } ] +} + + +-- !query +SELECT abs(kll_sketch_get_quantile_bigint(agg_with_nulls, 0.5) - + kll_sketch_get_quantile_bigint(agg_without_nulls, 0.5)) < 1 AS medians_match, + abs(kll_sketch_get_rank_bigint(agg_with_nulls, 4) - + kll_sketch_get_rank_bigint(agg_without_nulls, 4)) < 0.1 AS ranks_match +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg_with_nulls + FROM (VALUES (1L), (CAST(NULL AS BIGINT)), (3L), (5L), (CAST(NULL AS BIGINT)), (7L)) AS tab(col1) +) WITH_NULLS, +( + SELECT kll_sketch_agg_bigint(col1) AS agg_without_nulls + FROM (VALUES (1L), (3L), (5L), (7L)) AS tab(col1) +) WITHOUT_NULLS +-- !query schema +struct +-- !query output +true true + + +-- !query +SELECT abs(kll_sketch_get_quantile_float(agg_with_nulls, 0.5) - + kll_sketch_get_quantile_float(agg_without_nulls, 0.5)) < 0.5 AS medians_match, + abs(kll_sketch_get_rank_float(agg_with_nulls, 4.0) - + kll_sketch_get_rank_float(agg_without_nulls, 4.0)) < 0.1 AS ranks_match +FROM ( + SELECT kll_sketch_agg_float(col1) AS agg_with_nulls + FROM (VALUES (1.0F), (CAST(NULL AS FLOAT)), (3.0F), (5.0F), (CAST(NULL AS FLOAT)), (7.0F)) AS tab(col1) +) WITH_NULLS, +( + SELECT kll_sketch_agg_float(col1) AS agg_without_nulls + FROM (VALUES (1.0F), (3.0F), (5.0F), (7.0F)) AS tab(col1) +) WITHOUT_NULLS +-- !query schema +struct +-- !query output +true true + + +-- !query +SELECT abs(kll_sketch_get_quantile_double(agg_with_nulls, 0.5) - + kll_sketch_get_quantile_double(agg_without_nulls, 0.5)) < 0.5 AS medians_match, + abs(kll_sketch_get_rank_double(agg_with_nulls, 4.0) - + kll_sketch_get_rank_double(agg_without_nulls, 4.0)) < 0.1 AS ranks_match +FROM ( + SELECT kll_sketch_agg_double(col1) AS agg_with_nulls + FROM (VALUES (1.0D), (CAST(NULL AS DOUBLE)), (3.0D), (5.0D), (CAST(NULL AS DOUBLE)), (7.0D)) AS tab(col1) +) WITH_NULLS, +( + SELECT kll_sketch_agg_double(col1) AS agg_without_nulls + FROM (VALUES (1.0D), (3.0D), (5.0D), (7.0D)) AS tab(col1) +) WITHOUT_NULLS +-- !query schema +struct +-- !query output +true true + + +-- !query +SELECT kll_sketch_get_quantile_bigint(CAST(NULL AS BINARY), 0.5) AS null_sketch +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT kll_sketch_get_rank_float(CAST(NULL AS BINARY), 5.0) AS null_sketch +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT LENGTH(kll_sketch_to_string_bigint(kll_sketch_agg_bigint(col1, 8))) > 0 AS k_min_value +FROM t_long_1_5_through_7_11 +-- !query schema +struct +-- !query output +true + + +-- !query +SELECT LENGTH(kll_sketch_to_string_bigint(kll_sketch_agg_bigint(col1, 200))) > 0 AS k_default_value +FROM t_long_1_5_through_7_11 +-- !query schema +struct +-- !query output +true + + +-- !query +SELECT LENGTH(kll_sketch_to_string_bigint(kll_sketch_agg_bigint(col1, 400))) > 0 AS k_custom_value +FROM t_long_1_5_through_7_11 +-- !query schema +struct +-- !query output +true + + +-- !query +SELECT LENGTH(kll_sketch_to_string_bigint(kll_sketch_agg_bigint(col1, 65535))) > 0 AS k_max_value +FROM t_long_1_5_through_7_11 +-- !query schema +struct +-- !query output +true + + +-- !query +SELECT LENGTH(kll_sketch_to_string_float(kll_sketch_agg_float(col1, 100))) > 0 AS k_float_sketch +FROM t_float_1_5_through_7_11 +-- !query schema +struct +-- !query output +true + + +-- !query +SELECT LENGTH(kll_sketch_to_string_double(kll_sketch_agg_double(col1, 300))) > 0 AS k_double_sketch +FROM t_double_1_5_through_7_11 +-- !query schema +struct +-- !query output +true + + +-- !query +SELECT kll_sketch_get_n_bigint(kll_sketch_agg_bigint(col1)) AS n_bigint +FROM t_long_1_5_through_7_11 +-- !query schema +struct +-- !query output +7 + + +-- !query +SELECT kll_sketch_get_n_bigint(kll_sketch_agg_bigint(col1)) AS n_byte +FROM t_byte_1_5_through_7_11 +-- !query schema +struct +-- !query output +7 + + +-- !query +SELECT kll_sketch_get_n_bigint(kll_sketch_agg_bigint(col1)) AS n_short +FROM t_short_1_5_through_7_11 +-- !query schema +struct +-- !query output +7 + + +-- !query +SELECT kll_sketch_get_n_bigint(kll_sketch_agg_bigint(col1)) AS n_int +FROM t_int_1_5_through_7_11 +-- !query schema +struct +-- !query output +7 + + +-- !query +SELECT kll_sketch_get_n_float(kll_sketch_agg_float(col1)) AS n_float +FROM t_float_1_5_through_7_11 +-- !query schema +struct +-- !query output +7 + + +-- !query +SELECT kll_sketch_get_n_double(kll_sketch_agg_double(col1)) AS n_double +FROM t_double_1_5_through_7_11 +-- !query schema +struct +-- !query output +7 + + +-- !query +SELECT kll_sketch_get_n_bigint(kll_sketch_agg_bigint(col1, 100)) AS n_k_100 +FROM t_long_1_5_through_7_11 +-- !query schema +struct +-- !query output +7 + + +-- !query +SELECT split(kll_sketch_to_string_bigint(agg), '\n')[1] LIKE '%Kll%' AS str_contains_kll, + abs(kll_sketch_get_quantile_bigint(agg, 0.5) - 4) < 1 AS median_close_to_4, + abs(kll_sketch_get_rank_bigint(agg, 3) - 0.4) < 0.1 AS rank3_close_to_0_4 +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_double_1_5_through_7_11 +) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"col1\"", + "inputType" : "\"DOUBLE\"", + "paramIndex" : "first", + "requiredType" : "(\"TINYINT\" or \"INT\" or \"BIGINT\" or \"SMALLINT\")", + "sqlExpr" : "\"kll_sketch_agg_bigint(col1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 273, + "stopIndex" : 299, + "fragment" : "kll_sketch_agg_bigint(col1)" + } ] +} + + +-- !query +SELECT split(kll_sketch_to_string_bigint(agg), '\n')[1] LIKE '%Kll%' AS str_contains_kll, + abs(kll_sketch_get_quantile_bigint(agg, 0.5) - 4) < 1 AS median_close_to_4, + abs(kll_sketch_get_rank_bigint(agg, 3) - 0.4) < 0.1 AS rank3_close_to_0_4 +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_float_1_5_through_7_11 +) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"col1\"", + "inputType" : "\"FLOAT\"", + "paramIndex" : "first", + "requiredType" : "(\"TINYINT\" or \"INT\" or \"BIGINT\" or \"SMALLINT\")", + "sqlExpr" : "\"kll_sketch_agg_bigint(col1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 273, + "stopIndex" : 299, + "fragment" : "kll_sketch_agg_bigint(col1)" + } ] +} + + +-- !query +SELECT split(kll_sketch_to_string_float(agg), '\n')[1] LIKE '%Kll%' AS str_contains_kll, + abs(kll_sketch_get_quantile_float(agg, 0.5) - 4.0) < 0.5 AS median_close_to_4, + abs(kll_sketch_get_rank_float(agg, 3) - 0.4) < 0.1 AS rank3_close_to_0_4 +FROM ( + SELECT kll_sketch_agg_float(col1) AS agg + FROM t_double_1_5_through_7_11 +) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"col1\"", + "inputType" : "\"DOUBLE\"", + "paramIndex" : "first", + "requiredType" : "\"FLOAT\"", + "sqlExpr" : "\"kll_sketch_agg_float(col1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 274, + "stopIndex" : 299, + "fragment" : "kll_sketch_agg_float(col1)" + } ] +} + + +-- !query +SELECT kll_sketch_agg_float(col1) AS invalid_float_bigint +FROM t_long_1_5_through_7_11 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"col1\"", + "inputType" : "\"BIGINT\"", + "paramIndex" : "first", + "requiredType" : "\"FLOAT\"", + "sqlExpr" : "\"kll_sketch_agg_float(col1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 33, + "fragment" : "kll_sketch_agg_float(col1)" + } ] +} + + +-- !query +SELECT kll_sketch_agg_float(col1) AS invalid_float_int +FROM t_int_1_5_through_7_11 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"col1\"", + "inputType" : "\"INT\"", + "paramIndex" : "first", + "requiredType" : "\"FLOAT\"", + "sqlExpr" : "\"kll_sketch_agg_float(col1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 33, + "fragment" : "kll_sketch_agg_float(col1)" + } ] +} + + +-- !query +SELECT kll_sketch_agg_float(col1) AS invalid_float_short +FROM t_short_1_5_through_7_11 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"col1\"", + "inputType" : "\"SMALLINT\"", + "paramIndex" : "first", + "requiredType" : "\"FLOAT\"", + "sqlExpr" : "\"kll_sketch_agg_float(col1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 33, + "fragment" : "kll_sketch_agg_float(col1)" + } ] +} + + +-- !query +SELECT kll_sketch_agg_float(col1) AS invalid_float_byte +FROM t_byte_1_5_through_7_11 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"col1\"", + "inputType" : "\"TINYINT\"", + "paramIndex" : "first", + "requiredType" : "\"FLOAT\"", + "sqlExpr" : "\"kll_sketch_agg_float(col1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 33, + "fragment" : "kll_sketch_agg_float(col1)" + } ] +} + + +-- !query +SELECT kll_sketch_agg_double(col1) AS invalid_double_bigint +FROM t_long_1_5_through_7_11 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"col1\"", + "inputType" : "\"BIGINT\"", + "paramIndex" : "first", + "requiredType" : "(\"FLOAT\" or \"DOUBLE\")", + "sqlExpr" : "\"kll_sketch_agg_double(col1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 34, + "fragment" : "kll_sketch_agg_double(col1)" + } ] +} + + +-- !query +SELECT kll_sketch_agg_double(col1) AS invalid_double_int +FROM t_int_1_5_through_7_11 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"col1\"", + "inputType" : "\"INT\"", + "paramIndex" : "first", + "requiredType" : "(\"FLOAT\" or \"DOUBLE\")", + "sqlExpr" : "\"kll_sketch_agg_double(col1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 34, + "fragment" : "kll_sketch_agg_double(col1)" + } ] +} + + +-- !query +SELECT kll_sketch_agg_double(col1) AS invalid_double_short +FROM t_short_1_5_through_7_11 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"col1\"", + "inputType" : "\"SMALLINT\"", + "paramIndex" : "first", + "requiredType" : "(\"FLOAT\" or \"DOUBLE\")", + "sqlExpr" : "\"kll_sketch_agg_double(col1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 34, + "fragment" : "kll_sketch_agg_double(col1)" + } ] +} + + +-- !query +SELECT kll_sketch_agg_double(col1) AS invalid_double_byte +FROM t_byte_1_5_through_7_11 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"col1\"", + "inputType" : "\"TINYINT\"", + "paramIndex" : "first", + "requiredType" : "(\"FLOAT\" or \"DOUBLE\")", + "sqlExpr" : "\"kll_sketch_agg_double(col1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 34, + "fragment" : "kll_sketch_agg_double(col1)" + } ] +} + + +-- !query +SELECT kll_sketch_get_quantile_bigint(agg, -0.5) AS invalid_quantile +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_long_1_5_through_7_11 +) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "KLL_SKETCH_INVALID_QUANTILE_RANGE", + "sqlState" : "22003", + "messageParameters" : { + "functionName" : "`kll_sketch_get_quantile_bigint`", + "quantile" : "-0.5D" + } +} + + +-- !query +SELECT kll_sketch_get_quantile_bigint(agg, 1.5) AS invalid_quantile +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_long_1_5_through_7_11 +) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "KLL_SKETCH_INVALID_QUANTILE_RANGE", + "sqlState" : "22003", + "messageParameters" : { + "functionName" : "`kll_sketch_get_quantile_bigint`", + "quantile" : "1.5D" + } +} + + +-- !query +SELECT kll_sketch_get_quantile_float(agg, array(-0.1, 0.5, 1.5)) AS invalid_quantiles +FROM ( + SELECT kll_sketch_agg_float(col1) AS agg + FROM t_float_1_5_through_7_11 +) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "KLL_SKETCH_INVALID_QUANTILE_RANGE", + "sqlState" : "22003", + "messageParameters" : { + "functionName" : "`kll_sketch_get_quantile_float`", + "quantile" : "-0.1D" + } +} + + +-- !query +SELECT kll_sketch_get_rank_bigint(agg, 5) AS wrong_type +FROM ( + SELECT kll_sketch_agg_float(col1) AS agg + FROM t_float_1_5_through_7_11 +) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "KLL_SKETCH_INVALID_INPUT", + "sqlState" : "22000", + "messageParameters" : { + "functionName" : "`kll_sketch_get_rank_bigint`", + "reason" : "reqOffset: 40, reqLength: 56, (reqOff + reqLen): 96, allocSize: 60" + } +} + + +-- !query +SELECT kll_sketch_merge_bigint(agg1, agg2) AS incompatible_merge +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg1, + kll_sketch_agg_float(CAST(col1 AS FLOAT)) AS agg2 + FROM t_long_1_5_through_7_11 +) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "KLL_SKETCH_INCOMPATIBLE_MERGE", + "sqlState" : "22000", + "messageParameters" : { + "functionName" : "`kll_sketch_merge_bigint`", + "reason" : "reqOffset: 40, reqLength: 56, (reqOff + reqLen): 96, allocSize: 60" + } +} + + +-- !query +SELECT kll_sketch_get_quantile_bigint(CAST('not_a_sketch' AS BINARY), 0.5) AS invalid_binary +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "KLL_SKETCH_INVALID_INPUT", + "sqlState" : "22000", + "messageParameters" : { + "functionName" : "`kll_sketch_get_quantile_bigint`", + "reason" : "Error combination of PreInts and SerVer: PreInts: 110, SerVer: 111" + } +} + + +-- !query +SELECT kll_sketch_get_quantile_float(agg, 0.5) IS NOT NULL AS returns_value +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_long_1_5_through_7_11 +) +-- !query schema +struct +-- !query output +true + + +-- !query +SELECT kll_sketch_to_string_double(agg) LIKE '%Kll%' AS contains_kll_header +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_long_1_5_through_7_11 +) +-- !query schema +struct +-- !query output +true + + +-- !query +SELECT kll_sketch_agg_bigint(col1, 7) AS k_too_small +FROM t_long_1_5_through_7_11 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.TYPE_CHECK_FAILURE_WITH_HINT", + "sqlState" : "42K09", + "messageParameters" : { + "hint" : "", + "msg" : "[KLL_SKETCH_K_OUT_OF_RANGE] For function `kll_sketch_agg_bigint`, the k parameter must be between 8 and 65535 (inclusive), but got 7. SQLSTATE: 22003", + "sqlExpr" : "\"kll_sketch_agg_bigint(col1, 7)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 37, + "fragment" : "kll_sketch_agg_bigint(col1, 7)" + } ] +} + + +-- !query +SELECT kll_sketch_agg_bigint(col1, 65536) AS k_too_large +FROM t_long_1_5_through_7_11 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.TYPE_CHECK_FAILURE_WITH_HINT", + "sqlState" : "42K09", + "messageParameters" : { + "hint" : "", + "msg" : "[KLL_SKETCH_K_OUT_OF_RANGE] For function `kll_sketch_agg_bigint`, the k parameter must be between 8 and 65535 (inclusive), but got 65536. SQLSTATE: 22003", + "sqlExpr" : "\"kll_sketch_agg_bigint(col1, 65536)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 41, + "fragment" : "kll_sketch_agg_bigint(col1, 65536)" + } ] +} + + +-- !query +SELECT kll_sketch_agg_float(col1, CAST(NULL AS INT)) AS k_is_null +FROM t_float_1_5_through_7_11 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_NULL", + "sqlState" : "42K09", + "messageParameters" : { + "exprName" : "k", + "sqlExpr" : "\"kll_sketch_agg_float(col1, CAST(NULL AS INT))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 52, + "fragment" : "kll_sketch_agg_float(col1, CAST(NULL AS INT))" + } ] +} + + +-- !query +SELECT kll_sketch_agg_double(col1, CAST(col1 AS INT)) AS k_non_constant +FROM t_double_1_5_through_7_11 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.NON_FOLDABLE_INPUT", + "sqlState" : "42K09", + "messageParameters" : { + "inputExpr" : "CAST(spark_catalog.default.t_double_1_5_through_7_11.col1 AS INT)", + "inputName" : "k", + "inputType" : "int", + "sqlExpr" : "\"kll_sketch_agg_double(col1, CAST(col1 AS INT))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 53, + "fragment" : "kll_sketch_agg_double(col1, CAST(col1 AS INT))" + } ] +} + + +-- !query +SELECT kll_sketch_agg_bigint(col1, '100') AS k_wrong_type +FROM t_long_1_5_through_7_11 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"100\"", + "inputType" : "\"STRING\"", + "paramIndex" : "second", + "requiredType" : "\"INT\"", + "sqlExpr" : "\"kll_sketch_agg_bigint(col1, 100)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 41, + "fragment" : "kll_sketch_agg_bigint(col1, '100')" + } ] +} + + +-- !query +SELECT kll_sketch_get_n_bigint(X'deadbeef') AS invalid_binary_bigint +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "KLL_SKETCH_INVALID_INPUT", + "sqlState" : "22000", + "messageParameters" : { + "functionName" : "`kll_sketch_get_n_bigint`", + "reason" : "A sketch memory image must be at least 8 bytes. 4" + } +} + + +-- !query +SELECT kll_sketch_get_n_float(X'cafebabe') AS invalid_binary_float +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "KLL_SKETCH_INVALID_INPUT", + "sqlState" : "22000", + "messageParameters" : { + "functionName" : "`kll_sketch_get_n_float`", + "reason" : "A sketch memory image must be at least 8 bytes. 4" + } +} + + +-- !query +SELECT kll_sketch_get_n_double(X'12345678') AS invalid_binary_double +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "KLL_SKETCH_INVALID_INPUT", + "sqlState" : "22000", + "messageParameters" : { + "functionName" : "`kll_sketch_get_n_double`", + "reason" : "A sketch memory image must be at least 8 bytes. 4" + } +} + + +-- !query +SELECT kll_sketch_get_n_bigint(42) AS wrong_argument_type +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"42\"", + "inputType" : "\"INT\"", + "paramIndex" : "first", + "requiredType" : "\"BINARY\"", + "sqlExpr" : "\"kll_sketch_get_n_bigint(42)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 34, + "fragment" : "kll_sketch_get_n_bigint(42)" + } ] +} + + +-- !query +SELECT kll_sketch_get_n_float(42.0) AS wrong_argument_type +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"42.0\"", + "inputType" : "\"DECIMAL(3,1)\"", + "paramIndex" : "first", + "requiredType" : "\"BINARY\"", + "sqlExpr" : "\"kll_sketch_get_n_float(42.0)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 35, + "fragment" : "kll_sketch_get_n_float(42.0)" + } ] +} + + +-- !query +SELECT kll_sketch_get_n_double(42.0D) AS wrong_argument_type +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"42.0\"", + "inputType" : "\"DOUBLE\"", + "paramIndex" : "first", + "requiredType" : "\"BINARY\"", + "sqlExpr" : "\"kll_sketch_get_n_double(42.0)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 37, + "fragment" : "kll_sketch_get_n_double(42.0D)" + } ] +} + + +-- !query +SELECT kll_sketch_get_quantile_bigint(agg, 'invalid') AS quantile_string +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_long_1_5_through_7_11 +) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkNumberFormatException +{ + "errorClass" : "CAST_INVALID_INPUT", + "sqlState" : "22018", + "messageParameters" : { + "ansiConfig" : "\"spark.sql.ansi.enabled\"", + "expression" : "'invalid'", + "sourceType" : "\"STRING\"", + "targetType" : "\"DOUBLE\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 53, + "fragment" : "kll_sketch_get_quantile_bigint(agg, 'invalid')" + } ] +} + + +-- !query +SELECT kll_sketch_get_quantile_float(agg, X'deadbeef') AS quantile_binary +FROM ( + SELECT kll_sketch_agg_float(col1) AS agg + FROM t_float_1_5_through_7_11 +) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"X'DEADBEEF'\"", + "inputType" : "\"BINARY\"", + "paramIndex" : "second", + "requiredType" : "(\"DOUBLE\" or \"ARRAY\")", + "sqlExpr" : "\"kll_sketch_get_quantile_float(agg, X'DEADBEEF')\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 54, + "fragment" : "kll_sketch_get_quantile_float(agg, X'deadbeef')" + } ] +} + + +-- !query +SELECT kll_sketch_get_quantile_double(agg, true) AS quantile_boolean +FROM ( + SELECT kll_sketch_agg_double(col1) AS agg + FROM t_double_1_5_through_7_11 +) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"true\"", + "inputType" : "\"BOOLEAN\"", + "paramIndex" : "second", + "requiredType" : "(\"DOUBLE\" or \"ARRAY\")", + "sqlExpr" : "\"kll_sketch_get_quantile_double(agg, true)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 48, + "fragment" : "kll_sketch_get_quantile_double(agg, true)" + } ] +} + + +-- !query +SELECT kll_sketch_get_rank_bigint(agg, 'invalid') AS rank_string +FROM ( + SELECT kll_sketch_agg_bigint(col1) AS agg + FROM t_long_1_5_through_7_11 +) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkNumberFormatException +{ + "errorClass" : "CAST_INVALID_INPUT", + "sqlState" : "22018", + "messageParameters" : { + "ansiConfig" : "\"spark.sql.ansi.enabled\"", + "expression" : "'invalid'", + "sourceType" : "\"STRING\"", + "targetType" : "\"BIGINT\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 49, + "fragment" : "kll_sketch_get_rank_bigint(agg, 'invalid')" + } ] +} + + +-- !query +SELECT kll_sketch_get_rank_float(agg, X'cafebabe') AS rank_binary +FROM ( + SELECT kll_sketch_agg_float(col1) AS agg + FROM t_float_1_5_through_7_11 +) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"X'CAFEBABE'\"", + "inputType" : "\"BINARY\"", + "paramIndex" : "second", + "requiredType" : "(\"FLOAT\" or \"ARRAY\")", + "sqlExpr" : "\"kll_sketch_get_rank_float(agg, X'CAFEBABE')\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 50, + "fragment" : "kll_sketch_get_rank_float(agg, X'cafebabe')" + } ] +} + + +-- !query +SELECT kll_sketch_get_rank_double(agg, false) AS rank_boolean +FROM ( + SELECT kll_sketch_agg_double(col1) AS agg + FROM t_double_1_5_through_7_11 +) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"false\"", + "inputType" : "\"BOOLEAN\"", + "paramIndex" : "second", + "requiredType" : "(\"DOUBLE\" or \"ARRAY\")", + "sqlExpr" : "\"kll_sketch_get_rank_double(agg, false)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 45, + "fragment" : "kll_sketch_get_rank_double(agg, false)" + } ] +} + + +-- !query +DROP TABLE IF EXISTS t_int_1_5_through_7_11 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_long_1_5_through_7_11 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_short_1_5_through_7_11 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_byte_1_5_through_7_11 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_float_1_5_through_7_11 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_double_1_5_through_7_11 +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/literals.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/literals.sql.out index 4e4c70cc333..29b93893b55 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/literals.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/literals.sql.out @@ -360,10 +360,12 @@ pattern% no-pattern\% pattern\% pattern\\% select '\'', '"', '\n', '\r', '\t', 'Z' -- !query schema struct<':string,":string, -:string, :string, :string,Z:string> +:string, +:string, :string,Z:string> -- !query output ' " - Z + + Z -- !query @@ -454,7 +456,7 @@ org.apache.spark.sql.catalyst.parser.ParseException "errorClass" : "UNSUPPORTED_TYPED_LITERAL", "sqlState" : "0A000", "messageParameters" : { - "supportedTypes" : "\"DATE\", \"TIMESTAMP_NTZ\", \"TIMESTAMP_LTZ\", \"TIMESTAMP\", \"INTERVAL\", \"X\"", + "supportedTypes" : "\"DATE\", \"TIMESTAMP_NTZ\", \"TIMESTAMP_LTZ\", \"TIMESTAMP\", \"INTERVAL\", \"X\", \"TIME\"", "unsupportedType" : "\"GEO\"" }, "queryContext" : [ { @@ -785,3 +787,59 @@ select -0, -0.0 struct<0:int,0.0:decimal(1,1)> -- !query output 0 0.0 + + +-- !query +SELECT "S""par""k" AS c1, "S\"par\"k" AS c2, 'S""par""k' AS c3 +-- !query schema +struct +-- !query output +S"par"k S"par"k S""par""k + + +-- !query +SELECT 'S''par''k' AS c1, 'S\'par\'k' AS c2, "S''par''k" AS c3 +-- !query schema +struct +-- !query output +S'par'k S'par'k S''par''k + + +-- !query +SELECT "S" "par" "k" AS c1, 'S' 'par' 'k' AS c2, "S" 'par' "k" AS c3, 'S' "par" 'k' AS c4, "S"'par'"k" AS c5, 'S'"par"'k' AS c6 +-- !query schema +struct +-- !query output +Spark Spark Spark Spark Spark Spark + + +-- !query +SET spark.sql.legacy.consecutiveStringLiterals.enabled=true +-- !query schema +struct +-- !query output +spark.sql.legacy.consecutiveStringLiterals.enabled true + + +-- !query +SELECT "S""par""k" AS c1, "S\"par\"k" AS c2, 'S""par""k' AS c3 +-- !query schema +struct +-- !query output +Spark S"par"k S""par""k + + +-- !query +SELECT 'S''par''k' AS c1, 'S\'par\'k' AS c2, "S''par''k" AS c3 +-- !query schema +struct +-- !query output +Spark S'par'k S''par''k + + +-- !query +SELECT "S" "par" "k" AS c1, 'S' 'par' 'k' AS c2, "S" 'par' "k" AS c3, 'S' "par" 'k' AS c4, "S"'par'"k" AS c5, 'S'"par"'k' AS c6 +-- !query schema +struct +-- !query output +Spark Spark Spark Spark Spark Spark diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/misc-functions.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/misc-functions.sql.out index 22305e75914..619a8c983e2 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/misc-functions.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/misc-functions.sql.out @@ -75,7 +75,7 @@ spark.sql.optimizer.excludedRules org.apache.spark.sql.catalyst.optimizer.Conver -- !query SELECT assert_true(true), assert_true(boolean(1)) -- !query schema -struct +struct -- !query output NULL NULL @@ -105,7 +105,7 @@ org.apache.spark.SparkRuntimeException "errorClass" : "USER_RAISED_EXCEPTION", "sqlState" : "P0001", "messageParameters" : { - "errorMessage" : "'cast(0 as boolean)' is not true!" + "errorMessage" : "'0' is not true!" } } @@ -120,7 +120,7 @@ org.apache.spark.SparkRuntimeException "errorClass" : "USER_RAISED_EXCEPTION", "sqlState" : "P0001", "messageParameters" : { - "errorMessage" : "'null' is not true!" + "errorMessage" : "'NULL' is not true!" } } @@ -135,7 +135,7 @@ org.apache.spark.SparkRuntimeException "errorClass" : "USER_RAISED_EXCEPTION", "sqlState" : "P0001", "messageParameters" : { - "errorMessage" : "'cast(null as boolean)' is not true!" + "errorMessage" : "'NULL' is not true!" } } @@ -330,3 +330,11 @@ SET spark.sql.legacy.raiseErrorWithoutErrorClass=false struct -- !query output spark.sql.legacy.raiseErrorWithoutErrorClass false + + +-- !query +SELECT assert_true(col1 <= col2) FROM VALUES ('2025-03-01', '2025-03-10') +-- !query schema +struct +-- !query output +NULL diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/name-precedence-in-order-by-and-having-with-conflicting-attributes.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/name-precedence-in-order-by-and-having-with-conflicting-attributes.sql.out new file mode 100644 index 00000000000..ad46fdd5fee --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/name-precedence-in-order-by-and-having-with-conflicting-attributes.sql.out @@ -0,0 +1,764 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +CREATE OR REPLACE TEMPORARY VIEW v1 AS SELECT col1 FROM VALUES + (42), (17), (99), (5), (42), + (23), (8), (17), (76), (33), + (99), (55), (3), (42), (8) +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE OR REPLACE TEMPORARY VIEW v2 AS SELECT col1 FROM VALUES + ('apple'), ('banana'), ('cherry'), ('date'), ('apple'), + ('fig'), ('grape'), ('banana'), ('kiwi'), ('lemon'), + ('cherry'), ('mango'), ('orange'), ('apple'), ('grape') +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT 2 AS col1 FROM v1 ORDER BY col1 +-- !query schema +struct +-- !query output +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 +2 + + +-- !query +SELECT 2 AS col1 FROM v1 GROUP BY ALL ORDER BY col1 +-- !query schema +struct +-- !query output +2 + + +-- !query +SELECT 2 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50 +-- !query schema +struct +-- !query output + + + +-- !query +SELECT * FROM ( + SELECT col1 AS c, 2 AS col1 FROM v1 ORDER BY col1 +) ORDER BY 1 +-- !query schema +struct +-- !query output +3 2 +5 2 +8 2 +8 2 +17 2 +17 2 +23 2 +33 2 +42 2 +42 2 +42 2 +55 2 +76 2 +99 2 +99 2 + + +-- !query +SELECT * FROM ( + SELECT col1 AS c, 2 AS col1 FROM v1 GROUP BY ALL ORDER BY col1 +) ORDER BY 1 +-- !query schema +struct +-- !query output +3 2 +5 2 +8 2 +17 2 +23 2 +33 2 +42 2 +55 2 +76 2 +99 2 + + +-- !query +SELECT * FROM ( + SELECT col1 AS c, 2 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50 +) ORDER BY 1 +-- !query schema +struct +-- !query output +55 2 +76 2 +99 2 + + +-- !query +SELECT 2 AS col1, 3 AS col1 FROM v1 ORDER BY col1 +-- !query schema +struct +-- !query output +2 3 +2 3 +2 3 +2 3 +2 3 +2 3 +2 3 +2 3 +2 3 +2 3 +2 3 +2 3 +2 3 +2 3 +2 3 + + +-- !query +SELECT 2 AS col1, 3 AS col1 FROM v1 GROUP BY ALL ORDER BY col1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col1`", + "proposal" : "`col1`, `col1`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 59, + "stopIndex" : 62, + "fragment" : "col1" + } ] +} + + +-- !query +SELECT 2 AS col1, 3 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "AMBIGUOUS_REFERENCE", + "sqlState" : "42704", + "messageParameters" : { + "name" : "`col1`", + "referenceNames" : "[`col1`, `col1`]" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 57, + "stopIndex" : 60, + "fragment" : "col1" + } ] +} + + +-- !query +SELECT col1 AS c, 2 AS col1, 3 AS col1 FROM v1 ORDER BY col1 +-- !query schema +struct +-- !query output +3 2 3 +5 2 3 +8 2 3 +8 2 3 +17 2 3 +17 2 3 +23 2 3 +33 2 3 +42 2 3 +42 2 3 +42 2 3 +55 2 3 +76 2 3 +99 2 3 +99 2 3 + + +-- !query +SELECT col1 AS c, 2 AS col1, 3 AS col1 FROM v1 GROUP BY ALL ORDER BY col1 +-- !query schema +struct +-- !query output +3 2 3 +5 2 3 +8 2 3 +17 2 3 +23 2 3 +33 2 3 +42 2 3 +55 2 3 +76 2 3 +99 2 3 + + +-- !query +SELECT * FROM ( + SELECT col1 AS c, 2 AS col1, 3 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50 +) ORDER BY 1 +-- !query schema +struct +-- !query output +55 2 3 +76 2 3 +99 2 3 + + +-- !query +SELECT col1, 2 AS col1 FROM v1 ORDER BY col1 +-- !query schema +struct +-- !query output +3 2 +5 2 +8 2 +8 2 +17 2 +17 2 +23 2 +33 2 +42 2 +42 2 +42 2 +55 2 +76 2 +99 2 +99 2 + + +-- !query +SELECT col1, 2 AS col1 FROM v1 GROUP BY ALL ORDER BY col1 +-- !query schema +struct +-- !query output +3 2 +5 2 +8 2 +17 2 +23 2 +33 2 +42 2 +55 2 +76 2 +99 2 + + +-- !query +SELECT * FROM ( + SELECT col1, 2 AS col1 FROM v1 GROUP BY ALL HAVING col1 > 50 +) ORDER BY 1 +-- !query schema +struct +-- !query output +55 2 +76 2 +99 2 + + +-- !query +SELECT 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) ORDER BY col1 +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) GROUP BY ALL ORDER BY col1 +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) GROUP BY ALL HAVING col1 > 50 +-- !query schema +struct +-- !query output + + + +-- !query +SELECT col1 AS c, 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) ORDER BY col1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "AMBIGUOUS_REFERENCE", + "sqlState" : "42704", + "messageParameters" : { + "name" : "`col1`", + "referenceNames" : "[`col1`, `col1`]" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 11, + "fragment" : "col1" + } ] +} + + +-- !query +SELECT col1 AS c, 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) GROUP BY ALL ORDER BY col1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "AMBIGUOUS_REFERENCE", + "sqlState" : "42704", + "messageParameters" : { + "name" : "`col1`", + "referenceNames" : "[`col1`, `col1`]" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 11, + "fragment" : "col1" + } ] +} + + +-- !query +SELECT col1 AS c, 3 AS col1 FROM (SELECT 1 AS col1, 2 AS col1) GROUP BY ALL HAVING col1 > 50 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "AMBIGUOUS_REFERENCE", + "sqlState" : "42704", + "messageParameters" : { + "name" : "`col1`", + "referenceNames" : "[`col1`, `col1`]" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 11, + "fragment" : "col1" + } ] +} + + +-- !query +SELECT 'col1' FROM v2 ORDER BY col1 +-- !query schema +struct +-- !query output +col1 +col1 +col1 +col1 +col1 +col1 +col1 +col1 +col1 +col1 +col1 +col1 +col1 +col1 +col1 + + +-- !query +SELECT 'col1' FROM v2 GROUP BY ALL ORDER BY col1 +-- !query schema +struct +-- !query output +col1 + + +-- !query +SELECT 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana' +-- !query schema +struct +-- !query output +col1 + + +-- !query +SELECT * FROM ( + SELECT col1 AS c, 'col1' FROM v2 ORDER BY col1 +) ORDER BY 1 +-- !query schema +struct +-- !query output +apple col1 +apple col1 +apple col1 +banana col1 +banana col1 +cherry col1 +cherry col1 +date col1 +fig col1 +grape col1 +grape col1 +kiwi col1 +lemon col1 +mango col1 +orange col1 + + +-- !query +SELECT * FROM ( + SELECT col1 AS c, 'col1' FROM v2 GROUP BY ALL ORDER BY col1 +) ORDER BY 1 +-- !query schema +struct +-- !query output +apple col1 +banana col1 +cherry col1 +date col1 +fig col1 +grape col1 +kiwi col1 +lemon col1 +mango col1 +orange col1 + + +-- !query +SELECT * FROM ( + SELECT col1 AS c, 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana' +) ORDER BY 1 +-- !query schema +struct +-- !query output +cherry col1 +date col1 +fig col1 +grape col1 +kiwi col1 +lemon col1 +mango col1 +orange col1 + + +-- !query +SELECT 'col1', 'col1' FROM v2 ORDER BY col1 +-- !query schema +struct +-- !query output +col1 col1 +col1 col1 +col1 col1 +col1 col1 +col1 col1 +col1 col1 +col1 col1 +col1 col1 +col1 col1 +col1 col1 +col1 col1 +col1 col1 +col1 col1 +col1 col1 +col1 col1 + + +-- !query +SELECT 'col1', 'col1' FROM v2 GROUP BY ALL ORDER BY col1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col1`", + "proposal" : "`col1`, `col1`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 53, + "stopIndex" : 56, + "fragment" : "col1" + } ] +} + + +-- !query +SELECT 'col1', 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana' +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "AMBIGUOUS_REFERENCE", + "sqlState" : "42704", + "messageParameters" : { + "name" : "`col1`", + "referenceNames" : "[`col1`, `col1`]" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 51, + "stopIndex" : 54, + "fragment" : "col1" + } ] +} + + +-- !query +SELECT col1 AS c, 'col1', 'col1' FROM v2 ORDER BY col1 +-- !query schema +struct +-- !query output +apple col1 col1 +apple col1 col1 +apple col1 col1 +banana col1 col1 +banana col1 col1 +cherry col1 col1 +cherry col1 col1 +date col1 col1 +fig col1 col1 +grape col1 col1 +grape col1 col1 +kiwi col1 col1 +lemon col1 col1 +mango col1 col1 +orange col1 col1 + + +-- !query +SELECT col1 AS c, 'col1', 'col1' FROM v2 GROUP BY ALL ORDER BY col1 +-- !query schema +struct +-- !query output +apple col1 col1 +banana col1 col1 +cherry col1 col1 +date col1 col1 +fig col1 col1 +grape col1 col1 +kiwi col1 col1 +lemon col1 col1 +mango col1 col1 +orange col1 col1 + + +-- !query +SELECT * FROM ( + SELECT col1 AS c, 'col1', 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana' +) ORDER BY 1 +-- !query schema +struct +-- !query output +cherry col1 col1 +date col1 col1 +fig col1 col1 +grape col1 col1 +kiwi col1 col1 +lemon col1 col1 +mango col1 col1 +orange col1 col1 + + +-- !query +SELECT col1, 'col1' FROM v2 ORDER BY col1 +-- !query schema +struct +-- !query output +apple col1 +apple col1 +apple col1 +banana col1 +banana col1 +cherry col1 +cherry col1 +date col1 +fig col1 +grape col1 +grape col1 +kiwi col1 +lemon col1 +mango col1 +orange col1 + + +-- !query +SELECT col1, 'col1' FROM v2 GROUP BY ALL ORDER BY col1 +-- !query schema +struct +-- !query output +apple col1 +banana col1 +cherry col1 +date col1 +fig col1 +grape col1 +kiwi col1 +lemon col1 +mango col1 +orange col1 + + +-- !query +SELECT * FROM ( + SELECT col1, 'col1' FROM v2 GROUP BY ALL HAVING col1 > 'banana' +) ORDER BY 1 +-- !query schema +struct +-- !query output +cherry col1 +date col1 +fig col1 +grape col1 +kiwi col1 +lemon col1 +mango col1 +orange col1 + + +-- !query +SELECT 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) ORDER BY col1 +-- !query schema +struct +-- !query output +col1 + + +-- !query +SELECT 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) GROUP BY ALL ORDER BY col1 +-- !query schema +struct +-- !query output +col1 + + +-- !query +SELECT 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) GROUP BY ALL HAVING col1 > 'banana' +-- !query schema +struct +-- !query output +col1 + + +-- !query +SELECT col1 AS c, 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) ORDER BY col1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "AMBIGUOUS_REFERENCE", + "sqlState" : "42704", + "messageParameters" : { + "name" : "`col1`", + "referenceNames" : "[`col1`, `col1`]" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 11, + "fragment" : "col1" + } ] +} + + +-- !query +SELECT col1 AS c, 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) GROUP BY ALL ORDER BY col1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "AMBIGUOUS_REFERENCE", + "sqlState" : "42704", + "messageParameters" : { + "name" : "`col1`", + "referenceNames" : "[`col1`, `col1`]" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 11, + "fragment" : "col1" + } ] +} + + +-- !query +SELECT col1 AS c, 'col1' FROM (SELECT 'a' AS col1, 'b' AS col1) GROUP BY ALL HAVING col1 > 'banana' +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "AMBIGUOUS_REFERENCE", + "sqlState" : "42704", + "messageParameters" : { + "name" : "`col1`", + "referenceNames" : "[`col1`, `col1`]" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 11, + "fragment" : "col1" + } ] +} + + +-- !query +DROP VIEW v2 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP VIEW v1 +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/array.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/array.sql.out index c1330c620ac..460cb89113a 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/array.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/array.sql.out @@ -413,6 +413,214 @@ struct NULL +-- !query +select get(1, 0) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"1\"", + "inputType" : "\"INT\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"get(1, 0)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 16, + "fragment" : "get(1, 0)" + } ] +} + + +-- !query +select get(1, -1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"1\"", + "inputType" : "\"INT\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"get(1, -1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 17, + "fragment" : "get(1, -1)" + } ] +} + + +-- !query +select get('1', 0) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"1\"", + "inputType" : "\"STRING\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"get(1, 0)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 18, + "fragment" : "get('1', 0)" + } ] +} + + +-- !query +select get('1', -1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"1\"", + "inputType" : "\"STRING\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"get(1, -1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 19, + "fragment" : "get('1', -1)" + } ] +} + + +-- !query +select get(null, 0) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"NULL\"", + "inputType" : "\"VOID\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"get(NULL, 0)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 19, + "fragment" : "get(null, 0)" + } ] +} + + +-- !query +select get(null, -1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"NULL\"", + "inputType" : "\"VOID\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"get(NULL, -1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 20, + "fragment" : "get(null, -1)" + } ] +} + + +-- !query +select get(null, null) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"NULL\"", + "inputType" : "\"VOID\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"get(NULL, NULL)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 22, + "fragment" : "get(null, null)" + } ] +} + + +-- !query +select get(CAST (null AS string), 0) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"CAST(NULL AS STRING)\"", + "inputType" : "\"STRING\"", + "paramIndex" : "first", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"get(CAST(NULL AS STRING), 0)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 36, + "fragment" : "get(CAST (null AS string), 0)" + } ] +} + + -- !query select array_insert(array(1, 2, 3), 3, 4) -- !query schema diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/cast.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/cast.sql.out index 6f74c63da35..d01da5d0070 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/cast.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/cast.sql.out @@ -489,7 +489,8 @@ NULL select cast('\t\t true \n\r ' as boolean) -- !query schema struct + + AS BOOLEAN):boolean> -- !query output true @@ -498,7 +499,8 @@ true select cast('\t\n false \t\r' as boolean) -- !query schema struct + false + AS BOOLEAN):boolean> -- !query output false @@ -507,7 +509,8 @@ false select cast('\t\n xyz \t\r' as boolean) -- !query schema struct + xyz + AS BOOLEAN):boolean> -- !query output NULL @@ -916,6 +919,110 @@ struct 0-11 +-- !query +SELECT CAST(TIME '00:01:52' AS tinyint) +-- !query schema +struct +-- !query output +112 + + +-- !query +SELECT CAST(TIME '00:01:52' AS smallint) +-- !query schema +struct +-- !query output +112 + + +-- !query +SELECT CAST(TIME '00:01:52' AS int) +-- !query schema +struct +-- !query output +112 + + +-- !query +SELECT CAST(TIME '00:01:52' AS bigint) +-- !query schema +struct +-- !query output +112 + + +-- !query +SELECT CAST(TIME '23:59:59' AS tinyint) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT CAST(TIME '23:59:59' AS smallint) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT CAST(TIME '23:59:59' AS int) +-- !query schema +struct +-- !query output +86399 + + +-- !query +SELECT CAST(TIME '23:59:59' AS bigint) +-- !query schema +struct +-- !query output +86399 + + +-- !query +SELECT CAST(TIME '00:00:17.5' AS tinyint) +-- !query schema +struct +-- !query output +17 + + +-- !query +SELECT CAST(TIME '00:00:17.5' AS int) +-- !query schema +struct +-- !query output +17 + + +-- !query +SELECT CAST(TIME '00:00:17.9' AS int) +-- !query schema +struct +-- !query output +17 + + +-- !query +SELECT CAST(TIME '00:00:00' AS tinyint) +-- !query schema +struct +-- !query output +0 + + +-- !query +SELECT CAST(TIME '00:00:00' AS int) +-- !query schema +struct +-- !query output +0 + + -- !query SELECT '1.23' :: int -- !query schema @@ -1024,7 +1131,8 @@ struct select '\t\t true \n\r ' :: boolean -- !query schema struct + + AS BOOLEAN):boolean> -- !query output true @@ -1069,6 +1177,38 @@ struct 0 00:00:10.123456000 +-- !query +SELECT TIME '00:01:52' :: tinyint +-- !query schema +struct +-- !query output +112 + + +-- !query +SELECT TIME '00:01:52' :: int +-- !query schema +struct +-- !query output +112 + + +-- !query +SELECT TIME '23:59:59' :: tinyint +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT TIME '23:59:59' :: int +-- !query schema +struct +-- !query output +86399 + + -- !query SELECT '1.23' :: int :: long -- !query schema @@ -1159,3 +1299,139 @@ org.apache.spark.sql.catalyst.parser.ParseException "hint" : "" } } + + +-- !query +SELECT CAST(time '00:00:00' AS decimal(1, 0)) +-- !query schema +struct +-- !query output +0 + + +-- !query +SELECT CAST(time '12:00:00' AS decimal(7, 2)) +-- !query schema +struct +-- !query output +43200.00 + + +-- !query +SELECT CAST(time '01:30:45' AS decimal(8, 3)) +-- !query schema +struct +-- !query output +5445.000 + + +-- !query +SELECT CAST(time '23:59:59' AS decimal(9, 4)) +-- !query schema +struct +-- !query output +86399.0000 + + +-- !query +SELECT CAST(time '01:02:03' AS decimal(15, 9)) +-- !query schema +struct +-- !query output +3723.000000000 + + +-- !query +SELECT CAST(time '10:20:30' AS decimal(20, 10)) +-- !query schema +struct +-- !query output +37230.0000000000 + + +-- !query +SELECT CAST(time '23:59:59.001' AS decimal(8, 3)) +-- !query schema +struct +-- !query output +86399.001 + + +-- !query +SELECT CAST(time '23:59:59.999999' AS decimal(11, 6)) +-- !query schema +struct +-- !query output +86399.999999 + + +-- !query +SELECT CAST(time '23:59:59.999999999' AS decimal(14, 9)) +-- !query schema +struct +-- !query output +86399.999999000 + + +-- !query +SELECT CAST(time '23:59:59.999999999' AS decimal(20, 10)) +-- !query schema +struct +-- !query output +86399.9999990000 + + +-- !query +SELECT CAST(time '00:01:00' AS decimal(1, 0)) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT CAST(time '01:00:00' AS decimal(3, 0)) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT CAST(time '10:00:00' AS decimal(5, 2)) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT CAST(time '23:59:59.9' AS decimal(6, 0)) +-- !query schema +struct +-- !query output +86400 + + +-- !query +SELECT CAST(time '23:59:59.999' AS decimal(8, 2)) +-- !query schema +struct +-- !query output +86400.00 + + +-- !query +SELECT CAST(time '23:59:59.999999' AS decimal(11, 5)) +-- !query schema +struct +-- !query output +86400.00000 + + +-- !query +SELECT CAST(time '23:59:59.999999999' AS decimal(14, 8)) +-- !query schema +struct +-- !query output +86399.99999900 diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/date.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/date.sql.out index c46c200ff02..c3f8661d7f2 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/date.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/date.sql.out @@ -788,7 +788,7 @@ struct<(2001-10-01 - DATE '2001-09-28'):interval day> -- !query select date '2001-09-28' - null -- !query schema -struct +struct<(DATE '2001-09-28' - NULL):interval day> -- !query output NULL @@ -890,7 +890,7 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException -- !query select date'2011-11-11' + null -- !query schema -struct +struct -- !query output NULL @@ -898,7 +898,7 @@ NULL -- !query select null + date'2011-11-11' -- !query schema -struct +struct -- !query output NULL diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/double-quoted-identifiers.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/double-quoted-identifiers.sql.out index 81a98a60590..2c0fd9587c8 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/double-quoted-identifiers.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/double-quoted-identifiers.sql.out @@ -127,6 +127,22 @@ org.apache.spark.sql.catalyst.parser.ParseException } +-- !query +select 1 from "not_""exists" +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'\"not_\"\"exists\"'", + "hint" : "" + } +} + + -- !query SELECT 1 FROM `hello` -- !query schema diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/higher-order-functions.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/higher-order-functions.sql.out index 7bfc35a61e0..b16bbcda2eb 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/higher-order-functions.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/higher-order-functions.sql.out @@ -348,3 +348,837 @@ select aggregate(split('abcdefgh',''), array(array('')), (acc, x) -> array(array struct>> -- !query output [["h"]] + + +-- !query +select aggregate(array(1, 2, 3), 0, 100) as aggregate_int_literal +-- !query schema +struct +-- !query output +100 + + +-- !query +select aggregate(array(1, 2, 3), map(), map('result', 999)) as aggregate_map_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(map(result, 999), namedlambdavariable(), namedlambdavariable())\"", + "inputType" : "\"MAP\"", + "paramIndex" : "third", + "requiredType" : "\"MAP\"", + "sqlExpr" : "\"aggregate(array(1, 2, 3), map(), lambdafunction(map(result, 999), namedlambdavariable(), namedlambdavariable()), lambdafunction(namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 59, + "fragment" : "aggregate(array(1, 2, 3), map(), map('result', 999))" + } ] +} + + +-- !query +select aggregate(array(1, 2, 3), struct('init', 0), struct('final', 999)) as aggregate_struct_literal +-- !query schema +struct> +-- !query output +{"col1":"final","col2":999} + + +-- !query +select aggregate(array(1, 2, 3), array(), array('result')) as aggregate_array_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(array(result), namedlambdavariable(), namedlambdavariable())\"", + "inputType" : "\"ARRAY\"", + "paramIndex" : "third", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"aggregate(array(1, 2, 3), array(), lambdafunction(array(result), namedlambdavariable(), namedlambdavariable()), lambdafunction(namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 58, + "fragment" : "aggregate(array(1, 2, 3), array(), array('result'))" + } ] +} + + +-- !query +select array_sort(array(3, 1, 2), 1) as array_sort_int_literal +-- !query schema +struct> +-- !query output +[3,1,2] + + +-- !query +select array_sort(array(3, 1, 2), map('compare', 0)) as array_sort_map_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_RETURN_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "actualType" : "\"MAP\"", + "expectedType" : "\"INT\"", + "functionName" : "`lambdafunction`", + "sqlExpr" : "\"array_sort(array(3, 1, 2), lambdafunction(map(compare, 0), namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 52, + "fragment" : "array_sort(array(3, 1, 2), map('compare', 0))" + } ] +} + + +-- !query +select array_sort(array(3, 1, 2), struct('result', 0)) as array_sort_struct_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_RETURN_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "actualType" : "\"STRUCT\"", + "expectedType" : "\"INT\"", + "functionName" : "`lambdafunction`", + "sqlExpr" : "\"array_sort(array(3, 1, 2), lambdafunction(struct(result, 0), namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 54, + "fragment" : "array_sort(array(3, 1, 2), struct('result', 0))" + } ] +} + + +-- !query +select array_sort(array(3, 1, 2), array(0)) as array_sort_array_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_RETURN_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "actualType" : "\"ARRAY\"", + "expectedType" : "\"INT\"", + "functionName" : "`lambdafunction`", + "sqlExpr" : "\"array_sort(array(3, 1, 2), lambdafunction(array(0), namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 43, + "fragment" : "array_sort(array(3, 1, 2), array(0))" + } ] +} + + +-- !query +select exists(array(1, 2, 3), 1) as exists_int_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(1, namedlambdavariable())\"", + "inputType" : "\"INT\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"exists(array(1, 2, 3), lambdafunction(1, namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 32, + "fragment" : "exists(array(1, 2, 3), 1)" + } ] +} + + +-- !query +select exists(array(1, 2, 3), map('found', true)) as exists_map_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(map(found, true), namedlambdavariable())\"", + "inputType" : "\"MAP\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"exists(array(1, 2, 3), lambdafunction(map(found, true), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 49, + "fragment" : "exists(array(1, 2, 3), map('found', true))" + } ] +} + + +-- !query +select exists(array(1, 2, 3), struct('exists', true)) as exists_struct_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(struct(exists, true), namedlambdavariable())\"", + "inputType" : "\"STRUCT\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"exists(array(1, 2, 3), lambdafunction(struct(exists, true), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 53, + "fragment" : "exists(array(1, 2, 3), struct('exists', true))" + } ] +} + + +-- !query +select exists(array(1, 2, 3), array(true)) as exists_array_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(array(true), namedlambdavariable())\"", + "inputType" : "\"ARRAY\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"exists(array(1, 2, 3), lambdafunction(array(true), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 42, + "fragment" : "exists(array(1, 2, 3), array(true))" + } ] +} + + +-- !query +select filter(array(1, 2, 3), 1) as filter_int_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(1, namedlambdavariable())\"", + "inputType" : "\"INT\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"filter(array(1, 2, 3), lambdafunction(1, namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 32, + "fragment" : "filter(array(1, 2, 3), 1)" + } ] +} + + +-- !query +select filter(array(1, 2, 3), map('key', 'value')) as filter_map_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(map(key, value), namedlambdavariable())\"", + "inputType" : "\"MAP\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"filter(array(1, 2, 3), lambdafunction(map(key, value), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 50, + "fragment" : "filter(array(1, 2, 3), map('key', 'value'))" + } ] +} + + +-- !query +select filter(array(1, 2, 3), struct('valid', true)) as filter_struct_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(struct(valid, true), namedlambdavariable())\"", + "inputType" : "\"STRUCT\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"filter(array(1, 2, 3), lambdafunction(struct(valid, true), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 52, + "fragment" : "filter(array(1, 2, 3), struct('valid', true))" + } ] +} + + +-- !query +select filter(array(1, 2, 3), array(true, false)) as filter_array_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(array(true, false), namedlambdavariable())\"", + "inputType" : "\"ARRAY\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"filter(array(1, 2, 3), lambdafunction(array(true, false), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 49, + "fragment" : "filter(array(1, 2, 3), array(true, false))" + } ] +} + + +-- !query +select forall(array(1, 2, 3), 1) as forall_int_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(1, namedlambdavariable())\"", + "inputType" : "\"INT\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"forall(array(1, 2, 3), lambdafunction(1, namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 32, + "fragment" : "forall(array(1, 2, 3), 1)" + } ] +} + + +-- !query +select forall(array(1, 2, 3), map('all', true)) as forall_map_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(map(all, true), namedlambdavariable())\"", + "inputType" : "\"MAP\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"forall(array(1, 2, 3), lambdafunction(map(all, true), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 47, + "fragment" : "forall(array(1, 2, 3), map('all', true))" + } ] +} + + +-- !query +select forall(array(1, 2, 3), struct('all', true)) as forall_struct_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(struct(all, true), namedlambdavariable())\"", + "inputType" : "\"STRUCT\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"forall(array(1, 2, 3), lambdafunction(struct(all, true), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 50, + "fragment" : "forall(array(1, 2, 3), struct('all', true))" + } ] +} + + +-- !query +select forall(array(1, 2, 3), array(true, true)) as forall_array_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(array(true, true), namedlambdavariable())\"", + "inputType" : "\"ARRAY\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"forall(array(1, 2, 3), lambdafunction(array(true, true), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 48, + "fragment" : "forall(array(1, 2, 3), array(true, true))" + } ] +} + + +-- !query +select map_filter(map('a', 1, 'b', 2), 1) as map_filter_int_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(1, namedlambdavariable(), namedlambdavariable())\"", + "inputType" : "\"INT\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"map_filter(map(a, 1, b, 2), lambdafunction(1, namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 41, + "fragment" : "map_filter(map('a', 1, 'b', 2), 1)" + } ] +} + + +-- !query +select map_filter(map('a', 1, 'b', 2), map('keep', true)) as map_filter_map_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(map(keep, true), namedlambdavariable(), namedlambdavariable())\"", + "inputType" : "\"MAP\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"map_filter(map(a, 1, b, 2), lambdafunction(map(keep, true), namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 57, + "fragment" : "map_filter(map('a', 1, 'b', 2), map('keep', true))" + } ] +} + + +-- !query +select map_filter(map('a', 1, 'b', 2), struct('filter', true)) as map_filter_struct_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(struct(filter, true), namedlambdavariable(), namedlambdavariable())\"", + "inputType" : "\"STRUCT\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"map_filter(map(a, 1, b, 2), lambdafunction(struct(filter, true), namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 62, + "fragment" : "map_filter(map('a', 1, 'b', 2), struct('filter', true))" + } ] +} + + +-- !query +select map_filter(map('a', 1, 'b', 2), array(true)) as map_filter_array_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(array(true), namedlambdavariable(), namedlambdavariable())\"", + "inputType" : "\"ARRAY\"", + "paramIndex" : "second", + "requiredType" : "\"BOOLEAN\"", + "sqlExpr" : "\"map_filter(map(a, 1, b, 2), lambdafunction(array(true), namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 51, + "fragment" : "map_filter(map('a', 1, 'b', 2), array(true))" + } ] +} + + +-- !query +select map_zip_with(map('a', 1), map('a', 10), 100) as map_zipwith_int_literal +-- !query schema +struct> +-- !query output +{"a":100} + + +-- !query +select map_zip_with(map('a', 1), map('a', 10), map('merged', true)) as map_zipwith_map_literal +-- !query schema +struct>> +-- !query output +{"a":{"merged":true}} + + +-- !query +select map_zip_with(map('a', 1), map('a', 10), struct('left', 1, 'right', 10)) as map_zipwith_struct_literal +-- !query schema +struct>> +-- !query output +{"a":{"col1":"left","col2":1,"col3":"right","col4":10}} + + +-- !query +select map_zip_with(map('a', 1), map('a', 10), array('combined')) as map_zipwith_array_literal +-- !query schema +struct>> +-- !query output +{"a":["combined"]} + + +-- !query +select reduce(array(1, 2, 3), 0, 100) as reduce_int_literal +-- !query schema +struct +-- !query output +100 + + +-- !query +select reduce(array(1, 2, 3), map(), map('result', 999)) as reduce_map_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(map(result, 999), namedlambdavariable(), namedlambdavariable())\"", + "inputType" : "\"MAP\"", + "paramIndex" : "third", + "requiredType" : "\"MAP\"", + "sqlExpr" : "\"reduce(array(1, 2, 3), map(), lambdafunction(map(result, 999), namedlambdavariable(), namedlambdavariable()), lambdafunction(namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 56, + "fragment" : "reduce(array(1, 2, 3), map(), map('result', 999))" + } ] +} + + +-- !query +select reduce(array(1, 2, 3), struct('init', 0), struct('final', 999)) as reduce_struct_literal +-- !query schema +struct> +-- !query output +{"col1":"final","col2":999} + + +-- !query +select reduce(array(1, 2, 3), array(), array('result')) as reduce_array_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"lambdafunction(array(result), namedlambdavariable(), namedlambdavariable())\"", + "inputType" : "\"ARRAY\"", + "paramIndex" : "third", + "requiredType" : "\"ARRAY\"", + "sqlExpr" : "\"reduce(array(1, 2, 3), array(), lambdafunction(array(result), namedlambdavariable(), namedlambdavariable()), lambdafunction(namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 55, + "fragment" : "reduce(array(1, 2, 3), array(), array('result'))" + } ] +} + + +-- !query +select transform(array(1, 2, 3), 42) as transform_int_literal +-- !query schema +struct> +-- !query output +[42,42,42] + + +-- !query +select transform(array(1, 2, 3), map('key', 'value')) as transform_map_literal +-- !query schema +struct>> +-- !query output +[{"key":"value"},{"key":"value"},{"key":"value"}] + + +-- !query +select transform(array(1, 2, 3), struct('id', 99, 'name', 'test')) as transform_struct_literal +-- !query schema +struct>> +-- !query output +[{"col1":"id","col2":99,"col3":"name","col4":"test"},{"col1":"id","col2":99,"col3":"name","col4":"test"},{"col1":"id","col2":99,"col3":"name","col4":"test"}] + + +-- !query +select transform(array(1, 2, 3), array('a', 'b')) as transform_array_literal +-- !query schema +struct>> +-- !query output +[["a","b"],["a","b"],["a","b"]] + + +-- !query +select transform_keys(map('a', 1, 'b', 2), 42) as transform_keys_int_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "DUPLICATED_MAP_KEY", + "sqlState" : "23505", + "messageParameters" : { + "key" : "42", + "mapKeyDedupPolicy" : "\"spark.sql.mapKeyDedupPolicy\"" + } +} + + +-- !query +select transform_keys(map('a', 1, 'b', 2), map('new', 'key')) as transform_keys_map_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.INVALID_MAP_KEY_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "keyType" : "\"MAP\"", + "sqlExpr" : "\"transform_keys(map(a, 1, b, 2), lambdafunction(map(new, key), namedlambdavariable(), namedlambdavariable()))\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 61, + "fragment" : "transform_keys(map('a', 1, 'b', 2), map('new', 'key'))" + } ] +} + + +-- !query +select transform_keys(map('a', 1, 'b', 2), struct('key', 'value')) as transform_keys_struct_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "DUPLICATED_MAP_KEY", + "sqlState" : "23505", + "messageParameters" : { + "key" : "[key,value]", + "mapKeyDedupPolicy" : "\"spark.sql.mapKeyDedupPolicy\"" + } +} + + +-- !query +select transform_keys(map('a', 1, 'b', 2), array('new_key')) as transform_keys_array_literal +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "DUPLICATED_MAP_KEY", + "sqlState" : "23505", + "messageParameters" : { + "key" : "[new_key]", + "mapKeyDedupPolicy" : "\"spark.sql.mapKeyDedupPolicy\"" + } +} + + +-- !query +select transform_values(map('a', 1, 'b', 2), 999) as transform_values_int_literal +-- !query schema +struct> +-- !query output +{"a":999,"b":999} + + +-- !query +select transform_values(map('a', 1, 'b', 2), map('new', 'value')) as transform_values_map_literal +-- !query schema +struct>> +-- !query output +{"a":{"new":"value"},"b":{"new":"value"}} + + +-- !query +select transform_values(map('a', 1, 'b', 2), struct('val', 999)) as transform_values_struct_literal +-- !query schema +struct>> +-- !query output +{"a":{"col1":"val","col2":999},"b":{"col1":"val","col2":999}} + + +-- !query +select transform_values(map('a', 1, 'b', 2), array('new_value')) as transform_values_array_literal +-- !query schema +struct>> +-- !query output +{"a":["new_value"],"b":["new_value"]} + + +-- !query +select zip_with(array(1, 2, 3), array(4, 5, 6), 100) as zipwith_int_literal +-- !query schema +struct> +-- !query output +[100,100,100] + + +-- !query +select zip_with(array(1, 2, 3), array(4, 5, 6), map('merged', true)) as zipwith_map_literal +-- !query schema +struct>> +-- !query output +[{"merged":true},{"merged":true},{"merged":true}] + + +-- !query +select zip_with(array(1, 2, 3), array(4, 5, 6), struct('left', 1, 'right', 2)) as zipwith_struct_literal +-- !query schema +struct>> +-- !query output +[{"col1":"left","col2":1,"col3":"right","col4":2},{"col1":"left","col2":1,"col3":"right","col4":2},{"col1":"left","col2":1,"col3":"right","col4":2}] + + +-- !query +select zip_with(array(1, 2, 3), array(4, 5, 6), array('combined')) as zipwith_array_literal +-- !query schema +struct>> +-- !query output +[["combined"],["combined"],["combined"]] diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/interval.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/interval.sql.out index a8a0423bdb3..e40053d1bc7 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/interval.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/interval.sql.out @@ -75,8 +75,11 @@ select interval 2147483647 day * 2 -- !query schema struct<> -- !query output -java.lang.ArithmeticException -long overflow +org.apache.spark.SparkArithmeticException +{ + "errorClass" : "INTERVAL_ARITHMETIC_OVERFLOW.WITHOUT_SUGGESTION", + "sqlState" : "22015" +} -- !query @@ -84,8 +87,11 @@ select interval 2147483647 day / 0.5 -- !query schema struct<> -- !query output -java.lang.ArithmeticException -long overflow +org.apache.spark.SparkArithmeticException +{ + "errorClass" : "INTERVAL_ARITHMETIC_OVERFLOW.WITHOUT_SUGGESTION", + "sqlState" : "22015" +} -- !query @@ -3710,3 +3716,15 @@ SELECT width_bucket(INTERVAL '-59' MINUTE, INTERVAL -'1 01' DAY TO HOUR, INTERVA struct -- !query output 5 + + +-- !query +SELECT interval 106751991 day 4 hour 0 minute 54.776 second +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkArithmeticException +{ + "errorClass" : "INTERVAL_ARITHMETIC_OVERFLOW.WITHOUT_SUGGESTION", + "sqlState" : "22015" +} diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/keywords.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/keywords.sql.out index fb4c72a88ca..00baa0c7e72 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/keywords.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/keywords.sql.out @@ -92,6 +92,7 @@ DECLARE false DEFAULT false DEFINED false DEFINER false +DELAY false DELETE false DELIMITED false DESC false @@ -109,6 +110,7 @@ DROP false ELSE false ELSEIF false END false +ENFORCED false ESCAPE false ESCAPED false EVOLUTION false @@ -131,6 +133,7 @@ FILEFORMAT false FILTER false FIRST false FLOAT false +FLOW false FOLLOWING false FOR false FOREIGN false @@ -142,6 +145,8 @@ FULL false FUNCTION false FUNCTIONS false GENERATED false +GEOGRAPHY false +GEOMETRY false GLOBAL false GRANT false GROUP false @@ -178,6 +183,7 @@ ITEMS false ITERATE false JOIN false JSON false +KEY false KEYS false LANGUAGE false LAST false @@ -186,6 +192,7 @@ LAZY false LEADING false LEAVE false LEFT false +LEVEL false LIKE false LIMIT false LINES false @@ -201,6 +208,8 @@ LOOP false MACRO false MAP false MATCHED false +MATERIALIZED false +MAX false MERGE false MICROSECOND false MICROSECONDS false @@ -221,6 +230,7 @@ NANOSECONDS false NATURAL false NO false NONE false +NORELY false NOT false NULL false NULLS false @@ -250,6 +260,8 @@ POSITION false PRECEDING false PRIMARY false PRINCIPALS false +PROCEDURE false +PROCEDURES false PROPERTIES false PURGE false QUARTER false @@ -260,10 +272,12 @@ REAL false RECORDREADER false RECORDWRITER false RECOVER false +RECURSION false RECURSIVE false REDUCE false REFERENCES false REFRESH false +RELY false RENAME false REPAIR false REPEAT false @@ -312,6 +326,8 @@ START false STATISTICS false STORED false STRATIFY false +STREAM false +STREAMING false STRING false STRUCT false SUBSTR false @@ -369,6 +385,7 @@ VERSION false VIEW false VIEWS false VOID false +WATERMARK false WEEK false WEEKS false WHEN false @@ -377,6 +394,7 @@ WHILE false WINDOW false WITH false WITHIN false +WITHOUT false X false YEAR false YEARS false diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/literals.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/literals.sql.out index 4e4c70cc333..29b93893b55 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/literals.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/literals.sql.out @@ -360,10 +360,12 @@ pattern% no-pattern\% pattern\% pattern\\% select '\'', '"', '\n', '\r', '\t', 'Z' -- !query schema struct<':string,":string, -:string, :string, :string,Z:string> +:string, +:string, :string,Z:string> -- !query output ' " - Z + + Z -- !query @@ -454,7 +456,7 @@ org.apache.spark.sql.catalyst.parser.ParseException "errorClass" : "UNSUPPORTED_TYPED_LITERAL", "sqlState" : "0A000", "messageParameters" : { - "supportedTypes" : "\"DATE\", \"TIMESTAMP_NTZ\", \"TIMESTAMP_LTZ\", \"TIMESTAMP\", \"INTERVAL\", \"X\"", + "supportedTypes" : "\"DATE\", \"TIMESTAMP_NTZ\", \"TIMESTAMP_LTZ\", \"TIMESTAMP\", \"INTERVAL\", \"X\", \"TIME\"", "unsupportedType" : "\"GEO\"" }, "queryContext" : [ { @@ -785,3 +787,59 @@ select -0, -0.0 struct<0:int,0.0:decimal(1,1)> -- !query output 0 0.0 + + +-- !query +SELECT "S""par""k" AS c1, "S\"par\"k" AS c2, 'S""par""k' AS c3 +-- !query schema +struct +-- !query output +S"par"k S"par"k S""par""k + + +-- !query +SELECT 'S''par''k' AS c1, 'S\'par\'k' AS c2, "S''par''k" AS c3 +-- !query schema +struct +-- !query output +S'par'k S'par'k S''par''k + + +-- !query +SELECT "S" "par" "k" AS c1, 'S' 'par' 'k' AS c2, "S" 'par' "k" AS c3, 'S' "par" 'k' AS c4, "S"'par'"k" AS c5, 'S'"par"'k' AS c6 +-- !query schema +struct +-- !query output +Spark Spark Spark Spark Spark Spark + + +-- !query +SET spark.sql.legacy.consecutiveStringLiterals.enabled=true +-- !query schema +struct +-- !query output +spark.sql.legacy.consecutiveStringLiterals.enabled true + + +-- !query +SELECT "S""par""k" AS c1, "S\"par\"k" AS c2, 'S""par""k' AS c3 +-- !query schema +struct +-- !query output +Spark S"par"k S""par""k + + +-- !query +SELECT 'S''par''k' AS c1, 'S\'par\'k' AS c2, "S''par''k" AS c3 +-- !query schema +struct +-- !query output +Spark S'par'k S''par''k + + +-- !query +SELECT "S" "par" "k" AS c1, 'S' 'par' 'k' AS c2, "S" 'par' "k" AS c3, 'S' "par" 'k' AS c4, "S"'par'"k" AS c5, 'S'"par"'k' AS c6 +-- !query schema +struct +-- !query output +Spark Spark Spark Spark Spark Spark diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/st-functions.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/st-functions.sql.out new file mode 100644 index 00000000000..95e7412bfea --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/st-functions.sql.out @@ -0,0 +1,487 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +DROP TABLE IF EXISTS geodata +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE geodata(wkb BINARY) USING parquet +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO geodata VALUES +(NULL), +(X'0101000000000000000000F03F0000000000000040') +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040') AS STRING) AS result +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.CAST_WITHOUT_SUGGESTION", + "sqlState" : "42K09", + "messageParameters" : { + "sqlExpr" : "\"CAST(st_geogfromwkb(X'0101000000000000000000F03F0000000000000040') AS STRING)\"", + "srcType" : "\"GEOGRAPHY(4326)\"", + "targetType" : "\"STRING\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 84, + "fragment" : "CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040') AS STRING)" + } ] +} + + +-- !query +SELECT CAST(X'0101000000000000000000f03f0000000000000040' AS GEOMETRY(4326)) AS result +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.CAST_WITHOUT_SUGGESTION", + "sqlState" : "42K09", + "messageParameters" : { + "sqlExpr" : "\"CAST(X'0101000000000000000000F03F0000000000000040' AS GEOMETRY(4326))\"", + "srcType" : "\"BINARY\"", + "targetType" : "\"GEOMETRY(4326)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 76, + "fragment" : "CAST(X'0101000000000000000000f03f0000000000000040' AS GEOMETRY(4326))" + } ] +} + + +-- !query +SELECT hex(ST_AsBinary(CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040') AS GEOGRAPHY(ANY)))) AS result +-- !query schema +struct +-- !query output +0101000000000000000000F03F0000000000000040 + + +-- !query +SELECT CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040')::GEOGRAPHY(ANY) AS GEOGRAPHY(4326)) AS result +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.CAST_WITHOUT_SUGGESTION", + "sqlState" : "42K09", + "messageParameters" : { + "sqlExpr" : "\"CAST(CAST(st_geogfromwkb(X'0101000000000000000000F03F0000000000000040') AS GEOGRAPHY(ANY)) AS GEOGRAPHY(4326))\"", + "srcType" : "\"GEOGRAPHY(ANY)\"", + "targetType" : "\"GEOGRAPHY(4326)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 109, + "fragment" : "CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040')::GEOGRAPHY(ANY) AS GEOGRAPHY(4326))" + } ] +} + + +-- !query +SELECT hex(ST_AsBinary(CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040') AS GEOMETRY(4326)))) AS result +-- !query schema +struct +-- !query output +0101000000000000000000F03F0000000000000040 + + +-- !query +SELECT CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040') AS GEOMETRY(ANY)) AS result +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.CAST_WITHOUT_SUGGESTION", + "sqlState" : "42K09", + "messageParameters" : { + "sqlExpr" : "\"CAST(st_geogfromwkb(X'0101000000000000000000F03F0000000000000040') AS GEOMETRY(ANY))\"", + "srcType" : "\"GEOGRAPHY(4326)\"", + "targetType" : "\"GEOMETRY(ANY)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 91, + "fragment" : "CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040') AS GEOMETRY(ANY))" + } ] +} + + +-- !query +SELECT hex(ST_AsBinary(CAST(ST_GeomFromWKB(X'0101000000000000000000f03f0000000000000040') AS GEOMETRY(ANY)))) AS result +-- !query schema +struct +-- !query output +0101000000000000000000F03F0000000000000040 + + +-- !query +SELECT CAST(ST_GeomFromWKB(X'0101000000000000000000f03f0000000000000040')::GEOMETRY(ANY) AS GEOMETRY(4326)) AS result +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.CAST_WITHOUT_SUGGESTION", + "sqlState" : "42K09", + "messageParameters" : { + "sqlExpr" : "\"CAST(CAST(st_geomfromwkb(X'0101000000000000000000F03F0000000000000040') AS GEOMETRY(ANY)) AS GEOMETRY(4326))\"", + "srcType" : "\"GEOMETRY(ANY)\"", + "targetType" : "\"GEOMETRY(4326)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 107, + "fragment" : "CAST(ST_GeomFromWKB(X'0101000000000000000000f03f0000000000000040')::GEOMETRY(ANY) AS GEOMETRY(4326))" + } ] +} + + +-- !query +SELECT typeof(array(ST_GeogFromWKB(wkb), ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY))) FROM geodata +-- !query schema +struct +-- !query output +array +array + + +-- !query +SELECT typeof(array(ST_GeomFromWKB(wkb), ST_GeomFromWKB(wkb)::GEOMETRY(ANY))) FROM geodata +-- !query schema +struct +-- !query output +array +array + + +-- !query +SELECT typeof(map('a', ST_GeogFromWKB(wkb), 'b', ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY))) FROM geodata +-- !query schema +struct +-- !query output +map +map + + +-- !query +SELECT typeof(map('a', ST_GeomFromWKB(wkb), 'b', ST_GeomFromWKB(wkb)::GEOMETRY(ANY))) FROM geodata +-- !query schema +struct +-- !query output +map +map + + +-- !query +SELECT typeof(array(named_struct('g1', ST_GeogFromWKB(wkb), 'g2', ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY)), named_struct('g1', ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY), 'g2', ST_GeogFromWKB(wkb)))) FROM geodata +-- !query schema +struct +-- !query output +array> +array> + + +-- !query +SELECT typeof(array(named_struct('g1', ST_GeomFromWKB(wkb), 'g2', ST_GeomFromWKB(wkb)::GEOMETRY(ANY)), named_struct('g1', ST_GeomFromWKB(wkb)::GEOMETRY(ANY), 'g2', ST_GeomFromWKB(wkb)))) FROM geodata +-- !query schema +struct +-- !query output +array> +array> + + +-- !query +SELECT typeof(named_struct('a', array(ST_GeogFromWKB(wkb), ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY)), 'b', map('g', ST_GeogFromWKB(wkb), 'h', ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY)))) FROM geodata +-- !query schema +struct +-- !query output +struct,b:map> +struct,b:map> + + +-- !query +SELECT typeof(named_struct('a', array(ST_GeomFromWKB(wkb), ST_GeomFromWKB(wkb)::GEOMETRY(ANY)), 'b', map('g', ST_GeomFromWKB(wkb), 'h', ST_GeomFromWKB(wkb)::GEOMETRY(ANY)))) FROM geodata +-- !query schema +struct +-- !query output +struct,b:map> +struct,b:map> + + +-- !query +SELECT typeof(nvl(ST_GeogFromWKB(wkb), ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY))) FROM geodata +-- !query schema +struct +-- !query output +geography(any) +geography(any) + + +-- !query +SELECT typeof(nvl(ST_GeomFromWKB(wkb), ST_GeomFromWKB(wkb)::GEOMETRY(ANY))) FROM geodata +-- !query schema +struct +-- !query output +geometry(any) +geometry(any) + + +-- !query +SELECT typeof(nvl2(ST_GeogFromWKB(wkb), ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY), ST_GeogFromWKB(wkb))) FROM geodata +-- !query schema +struct +-- !query output +geography(any) +geography(any) + + +-- !query +SELECT typeof(nvl2(ST_GeomFromWKB(wkb), ST_GeomFromWKB(wkb)::GEOMETRY(ANY), ST_GeomFromWKB(wkb))) FROM geodata +-- !query schema +struct +-- !query output +geometry(any) +geometry(any) + + +-- !query +SELECT typeof(CASE WHEN wkb IS NOT NULL THEN ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY) ELSE ST_GeogFromWKB(wkb) END) FROM geodata +-- !query schema +struct +-- !query output +geography(any) +geography(any) + + +-- !query +SELECT typeof(CASE WHEN wkb IS NOT NULL THEN ST_GeomFromWKB(wkb)::GEOMETRY(ANY) ELSE ST_GeomFromWKB(wkb) END) FROM geodata +-- !query schema +struct +-- !query output +geometry(any) +geometry(any) + + +-- !query +SELECT typeof(coalesce(ST_GeogFromWKB(wkb), ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY))) FROM geodata +-- !query schema +struct +-- !query output +geography(any) +geography(any) + + +-- !query +SELECT typeof(coalesce(ST_GeomFromWKB(wkb), ST_GeomFromWKB(wkb)::GEOMETRY(ANY))) FROM geodata +-- !query schema +struct +-- !query output +geometry(any) +geometry(any) + + +-- !query +SELECT typeof(IF(wkb IS NOT NULL, ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY), ST_GeogFromWKB(wkb))) FROM geodata +-- !query schema +struct +-- !query output +geography(any) +geography(any) + + +-- !query +SELECT typeof(IF(wkb IS NOT NULL, ST_GeomFromWKB(wkb)::GEOMETRY(ANY), ST_GeomFromWKB(wkb))) FROM geodata +-- !query schema +struct +-- !query output +geometry(any) +geometry(any) + + +-- !query +SELECT hex(ST_AsBinary(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040'))) AS result +-- !query schema +struct +-- !query output +0101000000000000000000F03F0000000000000040 + + +-- !query +SELECT hex(ST_AsBinary(ST_GeomFromWKB(X'0101000000000000000000f03f0000000000000040'))) AS result +-- !query schema +struct +-- !query output +0101000000000000000000F03F0000000000000040 + + +-- !query +SELECT ST_Srid(NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT ST_Srid(ST_GeogFromWKB(X'0101000000000000000000F03F0000000000000040')) +-- !query schema +struct +-- !query output +4326 + + +-- !query +SELECT ST_Srid(ST_GeomFromWKB(X'0101000000000000000000F03F0000000000000040')) +-- !query schema +struct +-- !query output +0 + + +-- !query +SELECT COUNT(*) FROM geodata WHERE ST_Srid(ST_GeogFromWKB(wkb)) <> 4326 +-- !query schema +struct +-- !query output +0 + + +-- !query +SELECT COUNT(*) FROM geodata WHERE ST_Srid(ST_GeomFromWKB(wkb)) <> 0 +-- !query schema +struct +-- !query output +0 + + +-- !query +SELECT ST_Srid(ST_SetSrid(ST_GeogFromWKB(X'0101000000000000000000F03F0000000000000040'), 4326)) +-- !query schema +struct +-- !query output +4326 + + +-- !query +SELECT ST_Srid(ST_SetSrid(ST_GeomFromWKB(X'0101000000000000000000F03F0000000000000040'), 3857)) +-- !query schema +struct +-- !query output +3857 + + +-- !query +SELECT ST_Srid(ST_SetSrid(ST_GeogFromWKB(X'0101000000000000000000F03F0000000000000040'), 3857)) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkIllegalArgumentException +{ + "errorClass" : "ST_INVALID_SRID_VALUE", + "sqlState" : "22023", + "messageParameters" : { + "srid" : "3857" + } +} + + +-- !query +SELECT ST_Srid(ST_SetSrid(ST_GeomFromWKB(X'0101000000000000000000F03F0000000000000040'), 9999)) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkIllegalArgumentException +{ + "errorClass" : "ST_INVALID_SRID_VALUE", + "sqlState" : "22023", + "messageParameters" : { + "srid" : "9999" + } +} + + +-- !query +SELECT COUNT(*) FROM geodata WHERE ST_Srid(ST_SetSrid(ST_GeogFromWKB(wkb), 4326)) <> 4326 +-- !query schema +struct +-- !query output +0 + + +-- !query +SELECT COUNT(*) FROM geodata WHERE ST_Srid(ST_SetSrid(ST_GeomFromWKB(wkb), 3857)) <> 3857 +-- !query schema +struct +-- !query output +0 + + +-- !query +SELECT COUNT(*) FROM geodata WHERE ST_Srid(ST_SetSrid(ST_GeogFromWKB(wkb), 3857)) IS NOT NULL +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkIllegalArgumentException +{ + "errorClass" : "ST_INVALID_SRID_VALUE", + "sqlState" : "22023", + "messageParameters" : { + "srid" : "3857" + } +} + + +-- !query +SELECT COUNT(*) FROM geodata WHERE ST_Srid(ST_SetSrid(ST_GeomFromWKB(wkb), 9999)) IS NOT NULL +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkIllegalArgumentException +{ + "errorClass" : "ST_INVALID_SRID_VALUE", + "sqlState" : "22023", + "messageParameters" : { + "srid" : "9999" + } +} + + +-- !query +DROP TABLE geodata +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/string-functions.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/string-functions.sql.out index d28ce4645ef..a4131b14672 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/string-functions.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/string-functions.sql.out @@ -147,6 +147,46 @@ struct> ["h","e","l","l","o"] +-- !query +SELECT split('hello', '', 0) +-- !query schema +struct> +-- !query output +["h","e","l","l","o"] + + +-- !query +SELECT split('hello', '', 1) +-- !query schema +struct> +-- !query output +["hello"] + + +-- !query +SELECT split('hello', '', 3) +-- !query schema +struct> +-- !query output +["h","e","llo"] + + +-- !query +SELECT split('hello', '', 5) +-- !query schema +struct> +-- !query output +["h","e","l","l","o"] + + +-- !query +SELECT split('hello', '', 100) +-- !query schema +struct> +-- !query output +["h","e","l","l","o"] + + -- !query SELECT split('', '') -- !query schema @@ -155,6 +195,30 @@ struct> [""] +-- !query +SELECT split('', '', -1) +-- !query schema +struct> +-- !query output +[""] + + +-- !query +SELECT split('', '', 0) +-- !query schema +struct> +-- !query output +[""] + + +-- !query +SELECT split('', '', 1) +-- !query schema +struct> +-- !query output +[""] + + -- !query SELECT split('abc', null) -- !query schema @@ -2277,3 +2341,27 @@ select try_validate_utf8(x'80') struct -- !query output NULL + + +-- !query +select quote('Spark') +-- !query schema +struct +-- !query output +'Spark' + + +-- !query +select quote("Don't") +-- !query schema +struct +-- !query output +'Don\'t' + + +-- !query +select quote(NULL) +-- !query schema +struct +-- !query output +NULL diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/timestamp.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/timestamp.sql.out index 0e0b014a3b1..191090f736f 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/timestamp.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/timestamp.sql.out @@ -180,6 +180,378 @@ struct NULL +-- !query +SELECT make_timestamp(make_date(2021, 07, 11)) +-- !query schema +struct +-- !query output +2021-07-11 00:00:00 + + +-- !query +SELECT make_timestamp(DATE'1970-01-01') +-- !query schema +struct +-- !query output +1970-01-01 00:00:00 + + +-- !query +SELECT make_timestamp(NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678)) +-- !query schema +struct +-- !query output +2021-07-11 06:30:45.678 + + +-- !query +SELECT make_timestamp(DATE'1970-01-01', TIME'00:00:00') +-- !query schema +struct +-- !query output +1970-01-01 00:00:00 + + +-- !query +SELECT make_timestamp(NULL, TIME'00:00:00') +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(DATE'1970-01-01', NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(NULL, NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'MIT') +-- !query schema +struct +-- !query output +2021-07-10 10:30:45.678 + + +-- !query +SELECT make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'PST') +-- !query schema +struct +-- !query output +2021-07-11 06:30:45.678 + + +-- !query +SELECT make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'UTC') +-- !query schema +struct +-- !query output +2021-07-10 23:30:45.678 + + +-- !query +SELECT make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'CET') +-- !query schema +struct +-- !query output +2021-07-10 21:30:45.678 + + +-- !query +SELECT make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'JST') +-- !query schema +struct +-- !query output +2021-07-10 14:30:45.678 + + +-- !query +SELECT make_timestamp(DATE'1970-01-01', TIME'00:00:00', 'UTC') +-- !query schema +struct +-- !query output +1969-12-31 16:00:00 + + +-- !query +SELECT make_timestamp(NULL, TIME'00:00:00', 'UTC') +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(DATE'1970-01-01', NULL, 'UTC') +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(DATE'1970-01-01', TIME'00:00:00', NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(NULL, NULL, 'UTC') +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(NULL, TIME'00:00:00', NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(DATE'1970-01-01', NULL, NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(NULL, NULL, NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT make_timestamp(timestamp '2018-11-17 13:33:33', TIME'0:0:0', 'CET') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"TIMESTAMP '2018-11-17 13:33:33'\"", + "inputType" : "\"TIMESTAMP\"", + "paramIndex" : "first", + "requiredType" : "\"DATE\"", + "sqlExpr" : "\"make_timestamp(TIMESTAMP '2018-11-17 13:33:33', TIME '00:00:00', CET)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 74, + "fragment" : "make_timestamp(timestamp '2018-11-17 13:33:33', TIME'0:0:0', 'CET')" + } ] +} + + +-- !query +SELECT make_timestamp(timestamp_ntz '2018-11-17 13:33:33', TIME'0:0:0', 'CET') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"TIMESTAMP_NTZ '2018-11-17 13:33:33'\"", + "inputType" : "\"TIMESTAMP_NTZ\"", + "paramIndex" : "first", + "requiredType" : "\"DATE\"", + "sqlExpr" : "\"make_timestamp(TIMESTAMP_NTZ '2018-11-17 13:33:33', TIME '00:00:00', CET)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 78, + "fragment" : "make_timestamp(timestamp_ntz '2018-11-17 13:33:33', TIME'0:0:0', 'CET')" + } ] +} + + +-- !query +SELECT make_timestamp(DATE'1970-01-01', timestamp '2018-11-17 13:33:33', 'CET') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"TIMESTAMP '2018-11-17 13:33:33'\"", + "inputType" : "\"TIMESTAMP\"", + "paramIndex" : "second", + "requiredType" : "\"TIME\"", + "sqlExpr" : "\"make_timestamp(DATE '1970-01-01', TIMESTAMP '2018-11-17 13:33:33', CET)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 79, + "fragment" : "make_timestamp(DATE'1970-01-01', timestamp '2018-11-17 13:33:33', 'CET')" + } ] +} + + +-- !query +SELECT make_timestamp(DATE'1970-01-01', timestamp_ntz '2018-11-17 13:33:33', 'CET') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"TIMESTAMP_NTZ '2018-11-17 13:33:33'\"", + "inputType" : "\"TIMESTAMP_NTZ\"", + "paramIndex" : "second", + "requiredType" : "\"TIME\"", + "sqlExpr" : "\"make_timestamp(DATE '1970-01-01', TIMESTAMP_NTZ '2018-11-17 13:33:33', CET)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 83, + "fragment" : "make_timestamp(DATE'1970-01-01', timestamp_ntz '2018-11-17 13:33:33', 'CET')" + } ] +} + + +-- !query +SELECT try_make_timestamp(make_date(2021, 07, 11)) +-- !query schema +struct +-- !query output +2021-07-11 00:00:00 + + +-- !query +SELECT try_make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678)) +-- !query schema +struct +-- !query output +2021-07-11 06:30:45.678 + + +-- !query +SELECT try_make_timestamp(make_date(2021, 07, 11), make_time(6, 30, 45.678), 'CET') +-- !query schema +struct +-- !query output +2021-07-10 21:30:45.678 + + +-- !query +SELECT try_make_timestamp(NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT try_make_timestamp(NULL, NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT try_make_timestamp(NULL, NULL, NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT try_make_timestamp(timestamp '2018-11-17 13:33:33', TIME'0:0:0', 'CET') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"TIMESTAMP '2018-11-17 13:33:33'\"", + "inputType" : "\"TIMESTAMP\"", + "paramIndex" : "first", + "requiredType" : "\"DATE\"", + "sqlExpr" : "\"make_timestamp(TIMESTAMP '2018-11-17 13:33:33', TIME '00:00:00', CET)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 78, + "fragment" : "try_make_timestamp(timestamp '2018-11-17 13:33:33', TIME'0:0:0', 'CET')" + } ] +} + + +-- !query +SELECT try_make_timestamp(DATE'1970-01-01', timestamp_ntz '2018-11-17 13:33:33', 'CET') +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"TIMESTAMP_NTZ '2018-11-17 13:33:33'\"", + "inputType" : "\"TIMESTAMP_NTZ\"", + "paramIndex" : "second", + "requiredType" : "\"TIME\"", + "sqlExpr" : "\"make_timestamp(DATE '1970-01-01', TIMESTAMP_NTZ '2018-11-17 13:33:33', CET)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 87, + "fragment" : "try_make_timestamp(DATE'1970-01-01', timestamp_ntz '2018-11-17 13:33:33', 'CET')" + } ] +} + + -- !query select TIMESTAMP_SECONDS(1230219000),TIMESTAMP_SECONDS(-1230219000),TIMESTAMP_SECONDS(null) -- !query schema @@ -805,49 +1177,17 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException -- !query select timestamp'2011-11-11 11:11:11' + null -- !query schema -struct<> +struct -- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "DATATYPE_MISMATCH.BINARY_OP_DIFF_TYPES", - "sqlState" : "42K09", - "messageParameters" : { - "left" : "\"TIMESTAMP\"", - "right" : "\"VOID\"", - "sqlExpr" : "\"(TIMESTAMP '2011-11-11 11:11:11' + NULL)\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 44, - "fragment" : "timestamp'2011-11-11 11:11:11' + null" - } ] -} +NULL -- !query select null + timestamp'2011-11-11 11:11:11' -- !query schema -struct<> +struct -- !query output -org.apache.spark.sql.catalyst.ExtendedAnalysisException -{ - "errorClass" : "DATATYPE_MISMATCH.BINARY_OP_DIFF_TYPES", - "sqlState" : "42K09", - "messageParameters" : { - "left" : "\"VOID\"", - "right" : "\"TIMESTAMP\"", - "sqlExpr" : "\"(NULL + TIMESTAMP '2011-11-11 11:11:11')\"" - }, - "queryContext" : [ { - "objectType" : "", - "objectName" : "", - "startIndex" : 8, - "stopIndex" : 44, - "fragment" : "null + timestamp'2011-11-11 11:11:11'" - } ] -} +NULL -- !query diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/try_arithmetic.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/try_arithmetic.sql.out index b12680c2a67..ba49909bd14 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/try_arithmetic.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/try_arithmetic.sql.out @@ -79,6 +79,14 @@ struct NULL +-- !query +SELECT try_add(sum(1), 1) GROUP BY ALL +-- !query schema +struct +-- !query output +2 + + -- !query SELECT try_add(date'2021-01-01', 1) -- !query schema @@ -281,6 +289,14 @@ struct NULL +-- !query +SELECT try_divide(sum(1), 1) GROUP BY ALL +-- !query schema +struct +-- !query output +1.0 + + -- !query SELECT try_divide(interval 2 year, 2) -- !query schema @@ -409,6 +425,14 @@ struct NULL +-- !query +SELECT try_subtract(sum(1), 1) GROUP BY ALL +-- !query schema +struct +-- !query output +0 + + -- !query SELECT try_subtract(interval 2 year, interval 3 year) -- !query schema @@ -521,6 +545,14 @@ struct NULL +-- !query +SELECT try_multiply(sum(1), 1) GROUP BY ALL +-- !query schema +struct +-- !query output +1 + + -- !query SELECT try_multiply(interval 2 year, 2) -- !query schema diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/try_arithmetic.sql.out.java21 b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/try_arithmetic.sql.out.java21 index 002a0dfcf37..b3f78b5a4a8 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/try_arithmetic.sql.out.java21 +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/nonansi/try_arithmetic.sql.out.java21 @@ -79,6 +79,14 @@ struct NULL +-- !query +SELECT try_add(sum(1), 1) GROUP BY ALL +-- !query schema +struct +-- !query output +2 + + -- !query SELECT try_add(date'2021-01-01', 1) -- !query schema @@ -281,6 +289,14 @@ struct NULL +-- !query +SELECT try_divide(sum(1), 1) GROUP BY ALL +-- !query schema +struct +-- !query output +1.0 + + -- !query SELECT try_divide(interval 2 year, 2) -- !query schema @@ -409,6 +425,14 @@ struct NULL +-- !query +SELECT try_subtract(sum(1), 1) GROUP BY ALL +-- !query schema +struct +-- !query output +0 + + -- !query SELECT try_subtract(interval 2 year, interval 3 year) -- !query schema @@ -521,6 +545,14 @@ struct NULL +-- !query +SELECT try_multiply(sum(1), 1) GROUP BY ALL +-- !query schema +struct +-- !query output +1 + + -- !query SELECT try_multiply(interval 2 year, 2) -- !query schema diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/operators.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/operators.sql.out index 356e5eca5fe..64d2c6f5f2a 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/operators.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/operators.sql.out @@ -496,7 +496,7 @@ struct<> -- !query output org.apache.spark.SparkArithmeticException { - "errorClass" : "DIVIDE_BY_ZERO", + "errorClass" : "REMAINDER_BY_ZERO", "sqlState" : "22012", "messageParameters" : { "config" : "\"spark.sql.ansi.enabled\"" @@ -566,7 +566,7 @@ struct<> -- !query output org.apache.spark.SparkArithmeticException { - "errorClass" : "DIVIDE_BY_ZERO", + "errorClass" : "REMAINDER_BY_ZERO", "sqlState" : "22012", "messageParameters" : { "config" : "\"spark.sql.ansi.enabled\"" @@ -588,7 +588,7 @@ struct<> -- !query output org.apache.spark.SparkArithmeticException { - "errorClass" : "DIVIDE_BY_ZERO", + "errorClass" : "REMAINDER_BY_ZERO", "sqlState" : "22012", "messageParameters" : { "config" : "\"spark.sql.ansi.enabled\"" diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/order-by-alias.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/order-by-alias.sql.out new file mode 100644 index 00000000000..9167e8bf997 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/order-by-alias.sql.out @@ -0,0 +1,263 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +CREATE OR REPLACE TEMPORARY VIEW testData AS SELECT * FROM VALUES +(1, 1), (1, 2), (2, 1), (2, 2), (3, 1), (3, 2), (null, 1), (3, null), (null, null) +AS testData(a, b) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT a FROM testData ORDER BY A +-- !query schema +struct +-- !query output +NULL +NULL +1 +1 +2 +2 +3 +3 +3 + + +-- !query +SELECT a as alias FROM testData ORDER BY ALIAS +-- !query schema +struct +-- !query output +NULL +NULL +1 +1 +2 +2 +3 +3 +3 + + +-- !query +SELECT a AS k FROM testData ORDER BY 'k' +-- !query schema +struct +-- !query output +1 +1 +2 +2 +3 +3 +NULL +3 +NULL + + +-- !query +SELECT 1 AS k FROM testData ORDER BY 'k' +-- !query schema +struct +-- !query output +1 +1 +1 +1 +1 +1 +1 +1 +1 + + +-- !query +SELECT concat_ws(' ', a, b) FROM testData ORDER BY `concat_ws( , a, b)` +-- !query schema +struct +-- !query output + +1 +1 1 +1 2 +2 1 +2 2 +3 +3 1 +3 2 + + +-- !query +SELECT 1 AS a FROM testData ORDER BY a +-- !query schema +struct +-- !query output +1 +1 +1 +1 +1 +1 +1 +1 +1 + + +-- !query +SELECT 1 AS a FROM testData ORDER BY `a` +-- !query schema +struct +-- !query output +1 +1 +1 +1 +1 +1 +1 +1 +1 + + +-- !query +SELECT 1 ORDER BY `1` +-- !query schema +struct<1:int> +-- !query output +1 + + +-- !query +SELECT a, b FROM testData ORDER BY a, (SELECT b FROM testData LIMIT 1) +-- !query schema +struct +-- !query output +NULL 1 +NULL NULL +1 1 +1 2 +2 1 +2 2 +3 1 +3 2 +3 NULL + + +-- !query +SELECT a FROM testData ORDER BY (SELECT b FROM testData) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkException +{ + "errorClass" : "SCALAR_SUBQUERY_TOO_MANY_ROWS", + "sqlState" : "21000", + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 33, + "stopIndex" : 56, + "fragment" : "(SELECT b FROM testData)" + } ] +} + + +-- !query +SELECT a, b FROM testData ORDER BY a, b IN (SELECT a FROM testData) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.UNSUPPORTED_IN_EXISTS_SUBQUERY", + "sqlState" : "0A000", + "messageParameters" : { + "treeNode" : "Sort [a#x ASC NULLS FIRST, b#x IN (list#x []) ASC NULLS FIRST], true\n: +- Project [a#x]\n: +- SubqueryAlias testdata\n: +- View (`testData`, [a#x, b#x])\n: +- Project [cast(a#x as int) AS a#x, cast(b#x as int) AS b#x]\n: +- Project [a#x, b#x]\n: +- SubqueryAlias testData\n: +- LocalRelation [a#x, b#x]\n+- Project [a#x, b#x]\n +- SubqueryAlias testdata\n +- View (`testData`, [a#x, b#x])\n +- Project [cast(a#x as int) AS a#x, cast(b#x as int) AS b#x]\n +- Project [a#x, b#x]\n +- SubqueryAlias testData\n +- LocalRelation [a#x, b#x]\n" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 41, + "stopIndex" : 67, + "fragment" : "IN (SELECT a FROM testData)" + } ] +} + + +-- !query +SELECT a, b FROM testData ORDER BY a, EXISTS(SELECT b FROM testData) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.UNSUPPORTED_IN_EXISTS_SUBQUERY", + "sqlState" : "0A000", + "messageParameters" : { + "treeNode" : "Sort [a#x ASC NULLS FIRST, exists#x [] ASC NULLS FIRST], true\n: +- Project [b#x]\n: +- SubqueryAlias testdata\n: +- View (`testData`, [a#x, b#x])\n: +- Project [cast(a#x as int) AS a#x, cast(b#x as int) AS b#x]\n: +- Project [a#x, b#x]\n: +- SubqueryAlias testData\n: +- LocalRelation [a#x, b#x]\n+- Project [a#x, b#x]\n +- SubqueryAlias testdata\n +- View (`testData`, [a#x, b#x])\n +- Project [cast(a#x as int) AS a#x, cast(b#x as int) AS b#x]\n +- Project [a#x, b#x]\n +- SubqueryAlias testData\n +- LocalRelation [a#x, b#x]\n" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 39, + "stopIndex" : 68, + "fragment" : "EXISTS(SELECT b FROM testData)" + } ] +} + + +-- !query +SELECT a AS k, c FROM testData ORDER BY k +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`c`", + "proposal" : "`a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 16, + "stopIndex" : 16, + "fragment" : "c" + } ] +} + + +-- !query +SELECT 1 AS `2`, 2 FROM VALUES (2) t (`2`) ORDER BY `2` +-- !query schema +struct<2:int,2:int> +-- !query output +1 2 + + +-- !query +SELECT 2, 1 AS `2` FROM VALUES (2) t (`2`) ORDER BY `2` +-- !query schema +struct<2:int,2:int> +-- !query output +2 1 + + +-- !query +SELECT 1 AS `2` FROM VALUES (2) t (`2`) ORDER BY `2` +-- !query schema +struct<2:int> +-- !query output +1 + + +-- !query +SELECT 2 FROM VALUES (2) t (`2`) ORDER BY `2` +-- !query schema +struct<2:int> +-- !query output +2 diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/order-by-and-having-on-top-of-aggregate-with-join.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/order-by-and-having-on-top-of-aggregate-with-join.sql.out new file mode 100644 index 00000000000..19aee5e8e06 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/order-by-and-having-on-top-of-aggregate-with-join.sql.out @@ -0,0 +1,2513 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +CREATE OR REPLACE TEMPORARY VIEW v1 AS SELECT * FROM VALUES + (1, 2), + (3, 5), + (7, 2), + (1, 2), + (8, 3), + (4, 9), + (5, 7), + (9, 4), + (2, 6), + (5, 7), + (3, 8), + (6, 1), + (4, 9), + (7, 5), + (2, 8) +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE OR REPLACE TEMPORARY VIEW v2 AS SELECT * FROM VALUES + (1, 2), + (5, 9), + (8, 4), + (7, 5), + (4, 9), + (3, 1), + (7, 2), + (6, 8), + (9, 7), + (2, 3), + (8, 3), + (5, 7), + (1, 6), + (3, 2), + (9, 8) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 ORDER BY col1 +-- !query schema +struct +-- !query output +4 +18 +14 +7 +3 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 ORDER BY col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col2`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 65, + "stopIndex" : 68, + "fragment" : "col2" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY v1.col1 +-- !query schema +struct +-- !query output +4 +18 +14 +7 +3 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY v1.col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col2`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 68, + "stopIndex" : 74, + "fragment" : "v1.col2" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY v2.col1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col1`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 68, + "stopIndex" : 74, + "fragment" : "v2.col1" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY v2.col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col2`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 68, + "stopIndex" : 74, + "fragment" : "v2.col2" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 ORDER BY 1 + col1, 2 + col2 +-- !query schema +struct +-- !query output +4 +18 +14 +2 +5 +3 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 ORDER BY 1 + col2, 2 + col1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col2`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 83, + "stopIndex" : 86, + "fragment" : "col2" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 ORDER BY 1 + v1.col1, 2 + v1.col2 +-- !query schema +struct +-- !query output +4 +18 +14 +2 +5 +3 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 ORDER BY 1 + v1.col2, 2 + v1.col1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col2`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 89, + "stopIndex" : 95, + "fragment" : "v1.col2" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 ORDER BY 1 + v1.col1, 2 + v2.col2 +-- !query schema +struct +-- !query output +4 +18 +14 +2 +5 +3 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 ORDER BY 1 + v2.col1, 2 + v1.col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col1`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 89, + "stopIndex" : 95, + "fragment" : "v2.col1" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 ORDER BY MAX(col1) +-- !query schema +struct +-- !query output +4 +18 +14 +7 +3 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 ORDER BY MAX(col2) +-- !query schema +struct +-- !query output +4 +3 +7 +14 +18 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY MAX(v1.col1) +-- !query schema +struct +-- !query output +4 +18 +14 +7 +3 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY MAX(v1.col2) +-- !query schema +struct +-- !query output +4 +3 +7 +14 +18 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY MAX(v2.col1) +-- !query schema +struct +-- !query output +4 +18 +14 +7 +3 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY MAX(v2.col2) +-- !query schema +struct +-- !query output +4 +3 +7 +14 +18 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 ORDER BY 1 + MAX(col1), 2 + MIN(col2) +-- !query schema +struct +-- !query output +4 +18 +14 +2 +5 +3 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 ORDER BY 1 + MAX(col2), 2 + MIN(col1) +-- !query schema +struct +-- !query output +4 +2 +3 +5 +14 +18 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 ORDER BY 1 + MAX(v1.col1), 2 + MIN(v1.col2) +-- !query schema +struct +-- !query output +4 +18 +14 +2 +5 +3 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 ORDER BY 1 + MAX(v1.col2), 2 + MIN(v1.col1) +-- !query schema +struct +-- !query output +4 +2 +3 +5 +14 +18 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 ORDER BY 1 + MAX(v1.col1), 2 + MIN(v2.col2) +-- !query schema +struct +-- !query output +4 +18 +14 +2 +5 +3 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 ORDER BY 1 + MAX(v2.col1), 2 + MIN(v1.col2) +-- !query schema +struct +-- !query output +4 +18 +14 +2 +5 +3 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 ORDER BY col1 +-- !query schema +struct +-- !query output +4 5 6 +18 19 20 +14 15 16 +7 8 9 +3 4 5 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 ORDER BY col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col2`", + "proposal" : "`a`, `b`, `c`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 94, + "stopIndex" : 97, + "fragment" : "col2" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY v1.col1 +-- !query schema +struct +-- !query output +4 5 6 +18 19 20 +14 15 16 +7 8 9 +3 4 5 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY v1.col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col2`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 97, + "stopIndex" : 103, + "fragment" : "v1.col2" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY v2.col1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col1`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 97, + "stopIndex" : 103, + "fragment" : "v2.col1" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY v2.col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col2`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 97, + "stopIndex" : 103, + "fragment" : "v2.col2" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 ORDER BY 1 + col1, 2 + col2 +-- !query schema +struct +-- !query output +4 5 6 +18 19 20 +14 15 16 +2 3 4 +5 6 7 +3 4 5 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 ORDER BY 1 + col2, 2 + col1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col2`", + "proposal" : "`a`, `b`, `c`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 112, + "stopIndex" : 115, + "fragment" : "col2" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 ORDER BY 1 + v1.col1, 2 + v1.col2 +-- !query schema +struct +-- !query output +4 5 6 +18 19 20 +14 15 16 +2 3 4 +5 6 7 +3 4 5 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 ORDER BY 1 + v1.col2, 2 + v1.col1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col2`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 118, + "stopIndex" : 124, + "fragment" : "v1.col2" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 ORDER BY 1 + v1.col1, 2 + v2.col2 +-- !query schema +struct +-- !query output +4 5 6 +18 19 20 +14 15 16 +2 3 4 +5 6 7 +3 4 5 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 ORDER BY 1 + v2.col1, 2 + v1.col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col1`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 118, + "stopIndex" : 124, + "fragment" : "v2.col1" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 ORDER BY MAX(col1) +-- !query schema +struct +-- !query output +4 5 6 +18 19 20 +14 15 16 +7 8 9 +3 4 5 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 ORDER BY MAX(col2) +-- !query schema +struct +-- !query output +4 5 6 +3 4 5 +7 8 9 +14 15 16 +18 19 20 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY MAX(v1.col1) +-- !query schema +struct +-- !query output +4 5 6 +18 19 20 +14 15 16 +7 8 9 +3 4 5 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY MAX(v1.col2) +-- !query schema +struct +-- !query output +4 5 6 +3 4 5 +7 8 9 +14 15 16 +18 19 20 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY MAX(v2.col1) +-- !query schema +struct +-- !query output +4 5 6 +18 19 20 +14 15 16 +7 8 9 +3 4 5 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 ORDER BY MAX(v2.col2) +-- !query schema +struct +-- !query output +4 5 6 +3 4 5 +7 8 9 +14 15 16 +18 19 20 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 ORDER BY 1 + MAX(col1), 2 + MIN(col2) +-- !query schema +struct +-- !query output +4 5 6 +18 19 20 +14 15 16 +2 3 4 +5 6 7 +3 4 5 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 ORDER BY 1 + MAX(col2), 2 + MIN(col1) +-- !query schema +struct +-- !query output +4 5 6 +2 3 4 +3 4 5 +5 6 7 +14 15 16 +18 19 20 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 ORDER BY 1 + MAX(v1.col1), 2 + MIN(v1.col2) +-- !query schema +struct +-- !query output +4 5 6 +18 19 20 +14 15 16 +2 3 4 +5 6 7 +3 4 5 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 ORDER BY 1 + MAX(v1.col2), 2 + MIN(v1.col1) +-- !query schema +struct +-- !query output +4 5 6 +2 3 4 +3 4 5 +5 6 7 +14 15 16 +18 19 20 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 ORDER BY 1 + MAX(v1.col1), 2 + MIN(v2.col2) +-- !query schema +struct +-- !query output +4 5 6 +18 19 20 +14 15 16 +2 3 4 +5 6 7 +3 4 5 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 ORDER BY 1 + MAX(v2.col1), 2 + MIN(v1.col2) +-- !query schema +struct +-- !query output +4 5 6 +18 19 20 +14 15 16 +2 3 4 +5 6 7 +3 4 5 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING col1 > 5 +-- !query schema +struct +-- !query output +3 +7 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING col2 > 5 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col2`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 63, + "stopIndex" : 66, + "fragment" : "col2" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v1.col1 > 5 +-- !query schema +struct +-- !query output +3 +7 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v1.col2 > 5 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col2`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 66, + "stopIndex" : 72, + "fragment" : "v1.col2" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v2.col1 > 5 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col1`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 66, + "stopIndex" : 72, + "fragment" : "v2.col1" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v2.col2 > 5 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col2`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 66, + "stopIndex" : 72, + "fragment" : "v2.col2" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + col1 > 5 +-- !query schema +struct +-- !query output +14 +2 +3 +5 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + col2 > 5 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col2`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 81, + "stopIndex" : 84, + "fragment" : "col2" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + v1.col1 > 5 +-- !query schema +struct +-- !query output +14 +2 +3 +5 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + v1.col2 > 5 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col2`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 87, + "stopIndex" : 93, + "fragment" : "v1.col2" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + v1.col1 > 5 +-- !query schema +struct +-- !query output +14 +2 +3 +5 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + v2.col1 > 5 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col1`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 87, + "stopIndex" : 93, + "fragment" : "v2.col1" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING MAX(col1) > 5 +-- !query schema +struct +-- !query output +3 +7 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING MAX(col2) > 5 +-- !query schema +struct +-- !query output +14 +18 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v1.col1) > 5 +-- !query schema +struct +-- !query output +3 +7 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v1.col2) > 5 +-- !query schema +struct +-- !query output +14 +18 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v2.col1) > 5 +-- !query schema +struct +-- !query output +3 +7 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v2.col2) > 5 +-- !query schema +struct +-- !query output +14 +18 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + MAX(col1) > 5 +-- !query schema +struct +-- !query output +14 +2 +3 +5 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + MAX(col2) > 5 +-- !query schema +struct +-- !query output +14 +18 +5 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + MAX(v1.col1) > 5 +-- !query schema +struct +-- !query output +14 +2 +3 +5 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + MAX(v1.col2) > 5 +-- !query schema +struct +-- !query output +14 +18 +5 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + MAX(v1.col1) > 5 +-- !query schema +struct +-- !query output +14 +2 +3 +5 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + MAX(v2.col1) > 5 +-- !query schema +struct +-- !query output +14 +2 +3 +5 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING col1 > 5 +-- !query schema +struct +-- !query output +3 4 5 +7 8 9 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING col2 > 5 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col2`", + "proposal" : "`a`, `b`, `c`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 92, + "stopIndex" : 95, + "fragment" : "col2" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v1.col1 > 5 +-- !query schema +struct +-- !query output +3 4 5 +7 8 9 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v1.col2 > 5 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col2`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 95, + "stopIndex" : 101, + "fragment" : "v1.col2" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v2.col1 > 5 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col1`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 95, + "stopIndex" : 101, + "fragment" : "v2.col1" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v2.col2 > 5 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col2`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 95, + "stopIndex" : 101, + "fragment" : "v2.col2" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + col1 > 5 +-- !query schema +struct +-- !query output +14 15 16 +2 3 4 +3 4 5 +5 6 7 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + col2 > 5 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col2`", + "proposal" : "`a`, `b`, `c`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 110, + "stopIndex" : 113, + "fragment" : "col2" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + v1.col1 > 5 +-- !query schema +struct +-- !query output +14 15 16 +2 3 4 +3 4 5 +5 6 7 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + v1.col2 > 5 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col2`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 116, + "stopIndex" : 122, + "fragment" : "v1.col2" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + v1.col1 > 5 +-- !query schema +struct +-- !query output +14 15 16 +2 3 4 +3 4 5 +5 6 7 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + v2.col1 > 5 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col1`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 116, + "stopIndex" : 122, + "fragment" : "v2.col1" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING MAX(col1) > 5 +-- !query schema +struct +-- !query output +3 4 5 +7 8 9 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING MAX(col2) > 5 +-- !query schema +struct +-- !query output +14 15 16 +18 19 20 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v1.col1) > 5 +-- !query schema +struct +-- !query output +3 4 5 +7 8 9 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v1.col2) > 5 +-- !query schema +struct +-- !query output +14 15 16 +18 19 20 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v2.col1) > 5 +-- !query schema +struct +-- !query output +3 4 5 +7 8 9 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v2.col2) > 5 +-- !query schema +struct +-- !query output +14 15 16 +18 19 20 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + MAX(col1) > 5 +-- !query schema +struct +-- !query output +14 15 16 +2 3 4 +3 4 5 +5 6 7 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + MAX(col2) > 5 +-- !query schema +struct +-- !query output +14 15 16 +18 19 20 +5 6 7 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + MAX(v1.col1) > 5 +-- !query schema +struct +-- !query output +14 15 16 +2 3 4 +3 4 5 +5 6 7 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + MAX(v1.col2) > 5 +-- !query schema +struct +-- !query output +14 15 16 +18 19 20 +5 6 7 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + MAX(v1.col1) > 5 +-- !query schema +struct +-- !query output +14 15 16 +2 3 4 +3 4 5 +5 6 7 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + MAX(v2.col1) > 5 +-- !query schema +struct +-- !query output +14 15 16 +2 3 4 +3 4 5 +5 6 7 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING col1 > 5 ORDER BY col1 +-- !query schema +struct +-- !query output +7 +3 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING col2 > 5 ORDER BY col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col2`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 63, + "stopIndex" : 66, + "fragment" : "col2" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v1.col1 > 5 ORDER BY v1.col1 +-- !query schema +struct +-- !query output +7 +3 + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v1.col2 > 5 ORDER BY v1.col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col2`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 66, + "stopIndex" : 72, + "fragment" : "v1.col2" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v2.col1 > 5 ORDER BY v2.col1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col1`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 66, + "stopIndex" : 72, + "fragment" : "v2.col1" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v2.col2 > 5 ORDER BY v2.col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col2`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 66, + "stopIndex" : 72, + "fragment" : "v2.col2" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + col1 > 5 ORDER BY 1 + col1, 2 + col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col1`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 103, + "stopIndex" : 106, + "fragment" : "col1" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + col2 > 5 ORDER BY 1 + col2, 2 + col1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col2`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 81, + "stopIndex" : 84, + "fragment" : "col2" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + v1.col1 > 5 ORDER BY 1 + v1.col1, 2 + v1.col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col1`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 112, + "stopIndex" : 118, + "fragment" : "v1.col1" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + v1.col2 > 5 ORDER BY 1 + v1.col2, 2 + v1.col1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col2`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 87, + "stopIndex" : 93, + "fragment" : "v1.col2" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + v1.col1 > 5 ORDER BY 1 + v1.col1, 2 + v2.col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col1`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 112, + "stopIndex" : 118, + "fragment" : "v1.col1" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + v2.col1 > 5 ORDER BY 1 + v2.col1, 2 + v1.col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col1`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 87, + "stopIndex" : 93, + "fragment" : "v2.col1" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING MAX(col1) > 5 ORDER BY MAX(col1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNSUPPORTED_EXPR_FOR_OPERATOR", + "sqlState" : "42K0E", + "messageParameters" : { + "invalidExprSqls" : "\"max(col1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 77, + "stopIndex" : 94, + "fragment" : "ORDER BY MAX(col1)" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING MAX(col2) > 5 ORDER BY MAX(col2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col2`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 90, + "stopIndex" : 93, + "fragment" : "col2" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v1.col1) > 5 ORDER BY MAX(v1.col1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNSUPPORTED_EXPR_FOR_OPERATOR", + "sqlState" : "42K0E", + "messageParameters" : { + "invalidExprSqls" : "\"max(col1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 83, + "stopIndex" : 103, + "fragment" : "ORDER BY MAX(v1.col1)" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v1.col2) > 5 ORDER BY MAX(v1.col2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col2`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 96, + "stopIndex" : 102, + "fragment" : "v1.col2" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v2.col1) > 5 ORDER BY MAX(v2.col1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col1`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 96, + "stopIndex" : 102, + "fragment" : "v2.col1" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v2.col2) > 5 ORDER BY MAX(v2.col2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col2`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 96, + "stopIndex" : 102, + "fragment" : "v2.col2" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + MAX(col1) > 5 ORDER BY 1 + MAX(col1), 2 + MIN(col2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col1`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 112, + "stopIndex" : 115, + "fragment" : "col1" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + MAX(col2) > 5 ORDER BY 1 + MAX(col2), 2 + MIN(col1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col2`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 112, + "stopIndex" : 115, + "fragment" : "col2" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + MAX(v1.col1) > 5 ORDER BY 1 + MAX(v1.col1), 2 + MIN(v1.col2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col1`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 121, + "stopIndex" : 127, + "fragment" : "v1.col1" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + MAX(v1.col2) > 5 ORDER BY 1 + MAX(v1.col2), 2 + MIN(v1.col1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col2`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 121, + "stopIndex" : 127, + "fragment" : "v1.col2" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + MAX(v1.col1) > 5 ORDER BY 1 + MAX(v1.col1), 2 + MIN(v2.col2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col1`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 121, + "stopIndex" : 127, + "fragment" : "v1.col1" + } ] +} + + +-- !query +SELECT SUM(col2) FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + MAX(v1.col1) > 5 ORDER BY 1 + MAX(v1.col1), 2 + MIN(v2.col2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col1`", + "proposal" : "`sum(col2)`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 121, + "stopIndex" : 127, + "fragment" : "v1.col1" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING col1 > 5 ORDER BY col1 +-- !query schema +struct +-- !query output +7 8 9 +3 4 5 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING col2 > 5 ORDER BY col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col2`", + "proposal" : "`a`, `b`, `c`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 92, + "stopIndex" : 95, + "fragment" : "col2" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v1.col1 > 5 ORDER BY v1.col1 +-- !query schema +struct +-- !query output +7 8 9 +3 4 5 + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v1.col2 > 5 ORDER BY v1.col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col2`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 95, + "stopIndex" : 101, + "fragment" : "v1.col2" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v2.col1 > 5 ORDER BY v2.col1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col1`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 95, + "stopIndex" : 101, + "fragment" : "v2.col1" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING v2.col2 > 5 ORDER BY v2.col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col2`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 95, + "stopIndex" : 101, + "fragment" : "v2.col2" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + col1 > 5 ORDER BY 1 + col1, 2 + col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col1`", + "proposal" : "`a`, `b`, `c`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 132, + "stopIndex" : 135, + "fragment" : "col1" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + col2 > 5 ORDER BY 1 + col2, 2 + col1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col2`", + "proposal" : "`a`, `b`, `c`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 110, + "stopIndex" : 113, + "fragment" : "col2" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + v1.col1 > 5 ORDER BY 1 + v1.col1, 2 + v1.col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col1`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 141, + "stopIndex" : 147, + "fragment" : "v1.col1" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + v1.col2 > 5 ORDER BY 1 + v1.col2, 2 + v1.col1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col2`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 116, + "stopIndex" : 122, + "fragment" : "v1.col2" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + v1.col1 > 5 ORDER BY 1 + v1.col1, 2 + v2.col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col1`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 141, + "stopIndex" : 147, + "fragment" : "v1.col1" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + v2.col1 > 5 ORDER BY 1 + v2.col1, 2 + v1.col2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col1`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 116, + "stopIndex" : 122, + "fragment" : "v2.col1" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING MAX(col1) > 5 ORDER BY MAX(col1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNSUPPORTED_EXPR_FOR_OPERATOR", + "sqlState" : "42K0E", + "messageParameters" : { + "invalidExprSqls" : "\"max(col1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 106, + "stopIndex" : 123, + "fragment" : "ORDER BY MAX(col1)" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 HAVING MAX(col2) > 5 ORDER BY MAX(col2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col2`", + "proposal" : "`a`, `b`, `c`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 119, + "stopIndex" : 122, + "fragment" : "col2" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v1.col1) > 5 ORDER BY MAX(v1.col1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNSUPPORTED_EXPR_FOR_OPERATOR", + "sqlState" : "42K0E", + "messageParameters" : { + "invalidExprSqls" : "\"max(col1)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 112, + "stopIndex" : 132, + "fragment" : "ORDER BY MAX(v1.col1)" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v1.col2) > 5 ORDER BY MAX(v1.col2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col2`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 125, + "stopIndex" : 131, + "fragment" : "v1.col2" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v2.col1) > 5 ORDER BY MAX(v2.col1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col1`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 125, + "stopIndex" : 131, + "fragment" : "v2.col1" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 HAVING MAX(v2.col2) > 5 ORDER BY MAX(v2.col2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v2`.`col2`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 125, + "stopIndex" : 131, + "fragment" : "v2.col2" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + MAX(col1) > 5 ORDER BY 1 + MAX(col1), 2 + MIN(col2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col1`", + "proposal" : "`a`, `b`, `c`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 141, + "stopIndex" : 144, + "fragment" : "col1" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY col1 + 1, col2 + 2 HAVING 1 + MAX(col2) > 5 ORDER BY 1 + MAX(col2), 2 + MIN(col1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`col2`", + "proposal" : "`a`, `b`, `c`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 141, + "stopIndex" : 144, + "fragment" : "col2" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + MAX(v1.col1) > 5 ORDER BY 1 + MAX(v1.col1), 2 + MIN(v1.col2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col1`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 150, + "stopIndex" : 156, + "fragment" : "v1.col1" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v1.col2 + 2 HAVING 1 + MAX(v1.col2) > 5 ORDER BY 1 + MAX(v1.col2), 2 + MIN(v1.col1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col2`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 150, + "stopIndex" : 156, + "fragment" : "v1.col2" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + MAX(v1.col1) > 5 ORDER BY 1 + MAX(v1.col1), 2 + MIN(v2.col2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col1`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 150, + "stopIndex" : 156, + "fragment" : "v1.col1" + } ] +} + + +-- !query +SELECT SUM(col2) AS a, a + 1 AS b, b + 1 AS c FROM v1 NATURAL JOIN v2 GROUP BY v1.col1 + 1, v2.col2 + 2 HAVING 1 + MAX(v1.col1) > 5 ORDER BY 1 + MAX(v1.col1), 2 + MIN(v2.col2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITH_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`v1`.`col1`", + "proposal" : "`c`, `a`, `b`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 150, + "stopIndex" : 156, + "fragment" : "v1.col1" + } ] +} + + +-- !query +DROP VIEW IF EXISTS v1 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP VIEW IF EXISTS v2 +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/order-by-ordinal.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/order-by-ordinal.sql.out index f975715c12b..b1b63b1de1e 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/order-by-ordinal.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/order-by-ordinal.sql.out @@ -148,6 +148,304 @@ struct 3 2 +-- !query +set spark.sql.prioritizeOrdinalResolutionInSort.enabled=true +-- !query schema +struct +-- !query output +spark.sql.prioritizeOrdinalResolutionInSort.enabled true + + +-- !query +SELECT a FROM data ORDER BY 2, b +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "ORDER_BY_POS_OUT_OF_RANGE", + "sqlState" : "42805", + "messageParameters" : { + "index" : "2", + "size" : "1" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 29, + "stopIndex" : 29, + "fragment" : "2" + } ] +} + + +-- !query +SELECT a FROM data ORDER BY b, 2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "ORDER_BY_POS_OUT_OF_RANGE", + "sqlState" : "42805", + "messageParameters" : { + "index" : "2", + "size" : "1" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 32, + "stopIndex" : 32, + "fragment" : "2" + } ] +} + + +-- !query +SELECT a FROM data ORDER BY 'b', 2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "ORDER_BY_POS_OUT_OF_RANGE", + "sqlState" : "42805", + "messageParameters" : { + "index" : "2", + "size" : "1" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 34, + "stopIndex" : 34, + "fragment" : "2" + } ] +} + + +-- !query +SELECT a FROM data ORDER BY `b`, 2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "ORDER_BY_POS_OUT_OF_RANGE", + "sqlState" : "42805", + "messageParameters" : { + "index" : "2", + "size" : "1" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 34, + "stopIndex" : 34, + "fragment" : "2" + } ] +} + + +-- !query +SELECT a FROM data ORDER BY a, 2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "ORDER_BY_POS_OUT_OF_RANGE", + "sqlState" : "42805", + "messageParameters" : { + "index" : "2", + "size" : "1" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 32, + "stopIndex" : 32, + "fragment" : "2" + } ] +} + + +-- !query +SELECT a FROM data ORDER BY b, 3 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "ORDER_BY_POS_OUT_OF_RANGE", + "sqlState" : "42805", + "messageParameters" : { + "index" : "3", + "size" : "1" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 32, + "stopIndex" : 32, + "fragment" : "3" + } ] +} + + +-- !query +SELECT a, a + 1 FROM data ORDER BY b, 3 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "ORDER_BY_POS_OUT_OF_RANGE", + "sqlState" : "42805", + "messageParameters" : { + "index" : "3", + "size" : "2" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 39, + "stopIndex" : 39, + "fragment" : "3" + } ] +} + + +-- !query +set spark.sql.prioritizeOrdinalResolutionInSort.enabled=false +-- !query schema +struct +-- !query output +spark.sql.prioritizeOrdinalResolutionInSort.enabled false + + +-- !query +SELECT a FROM data ORDER BY 2, b +-- !query schema +struct +-- !query output +1 +2 +3 +1 +2 +3 + + +-- !query +SELECT a FROM data ORDER BY b, 2 +-- !query schema +struct +-- !query output +1 +2 +3 +1 +2 +3 + + +-- !query +SELECT a FROM data ORDER BY 'b', 2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "ORDER_BY_POS_OUT_OF_RANGE", + "sqlState" : "42805", + "messageParameters" : { + "index" : "2", + "size" : "1" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 34, + "stopIndex" : 34, + "fragment" : "2" + } ] +} + + +-- !query +SELECT a FROM data ORDER BY `b`, 2 +-- !query schema +struct +-- !query output +1 +2 +3 +1 +2 +3 + + +-- !query +SELECT a FROM data ORDER BY a, 2 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "ORDER_BY_POS_OUT_OF_RANGE", + "sqlState" : "42805", + "messageParameters" : { + "index" : "2", + "size" : "1" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 32, + "stopIndex" : 32, + "fragment" : "2" + } ] +} + + +-- !query +SELECT a FROM data ORDER BY b, 3 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "ORDER_BY_POS_OUT_OF_RANGE", + "sqlState" : "42805", + "messageParameters" : { + "index" : "3", + "size" : "2" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 32, + "stopIndex" : 32, + "fragment" : "3" + } ] +} + + +-- !query +SELECT a, a + 1 FROM data ORDER BY b, 3 +-- !query schema +struct +-- !query output +1 2 +2 3 +3 4 +1 2 +2 3 +3 4 + + -- !query set spark.sql.orderByOrdinal=false -- !query schema diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/order-by.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/order-by.sql.out index 786564fbc3d..0fb46cc2864 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/order-by.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/order-by.sql.out @@ -186,6 +186,326 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException } +-- !query +SELECT col1 FROM VALUES (1, 2) GROUP BY col1 ORDER BY MAX(col2), RAND() +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT 1 AS col1, col1 FROM VALUES (10) ORDER BY col1 +-- !query schema +struct +-- !query output +1 10 + + +-- !query +SELECT 'a' ORDER BY CAST('a' AS VARIANT) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.INVALID_ORDERING_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "dataType" : "\"VARIANT\"", + "functionName" : "`sortorder`", + "sqlExpr" : "\"CAST(a AS VARIANT) ASC NULLS FIRST\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 21, + "stopIndex" : 40, + "fragment" : "CAST('a' AS VARIANT)" + } ] +} + + +-- !query +SELECT a, b FROM testData ORDER BY CAST(a + b AS VARIANT) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.INVALID_ORDERING_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "dataType" : "\"VARIANT\"", + "functionName" : "`sortorder`", + "sqlExpr" : "\"CAST((a + b) AS VARIANT) ASC NULLS FIRST\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 36, + "stopIndex" : 57, + "fragment" : "CAST(a + b AS VARIANT)" + } ] +} + + +-- !query +SELECT a FROM testData ORDER BY CAST(CAST(a AS VARIANT) AS VARIANT) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.INVALID_ORDERING_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "dataType" : "\"VARIANT\"", + "functionName" : "`sortorder`", + "sqlExpr" : "\"CAST(CAST(a AS VARIANT) AS VARIANT) ASC NULLS FIRST\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 33, + "stopIndex" : 67, + "fragment" : "CAST(CAST(a AS VARIANT) AS VARIANT)" + } ] +} + + +-- !query +SELECT a FROM testData GROUP BY a ORDER BY CAST(CAST(a AS STRING) AS VARIANT) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.INVALID_ORDERING_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "dataType" : "\"VARIANT\"", + "functionName" : "`sortorder`", + "sqlExpr" : "\"CAST(CAST(a AS STRING) AS VARIANT) ASC NULLS FIRST\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 44, + "stopIndex" : 77, + "fragment" : "CAST(CAST(a AS STRING) AS VARIANT)" + } ] +} + + +-- !query +SELECT * FROM testData ORDER BY CAST(null AS VARIANT) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.INVALID_ORDERING_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "dataType" : "\"VARIANT\"", + "functionName" : "`sortorder`", + "sqlExpr" : "\"CAST(NULL AS VARIANT) ASC NULLS FIRST\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 33, + "stopIndex" : 53, + "fragment" : "CAST(null AS VARIANT)" + } ] +} + + +-- !query +SELECT a FROM testData ORDER BY ARRAY(CAST(true AS VARIANT)) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.INVALID_ORDERING_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "dataType" : "\"ARRAY\"", + "functionName" : "`sortorder`", + "sqlExpr" : "\"array(CAST(true AS VARIANT)) ASC NULLS FIRST\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 33, + "stopIndex" : 60, + "fragment" : "ARRAY(CAST(true AS VARIANT))" + } ] +} + + +-- !query +SELECT a FROM testData ORDER BY CAST(ARRAY('a') AS VARIANT) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.INVALID_ORDERING_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "dataType" : "\"VARIANT\"", + "functionName" : "`sortorder`", + "sqlExpr" : "\"CAST(array(a) AS VARIANT) ASC NULLS FIRST\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 33, + "stopIndex" : 59, + "fragment" : "CAST(ARRAY('a') AS VARIANT)" + } ] +} + + +-- !query +SELECT a FROM testData ORDER BY CAST(ARRAY(CAST(true AS VARIANT)) AS VARIANT) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.INVALID_ORDERING_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "dataType" : "\"VARIANT\"", + "functionName" : "`sortorder`", + "sqlExpr" : "\"CAST(array(CAST(true AS VARIANT)) AS VARIANT) ASC NULLS FIRST\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 33, + "stopIndex" : 77, + "fragment" : "CAST(ARRAY(CAST(true AS VARIANT)) AS VARIANT)" + } ] +} + + +-- !query +SELECT SUM(a) + 1 FROM testData ORDER BY SUM(a) + 1 +-- !query schema +struct<(sum(a) + 1):bigint> +-- !query output +16 + + +-- !query +SELECT 1 + SUM(b) FROM testData ORDER BY SUM(b) + 1 +-- !query schema +struct<(1 + sum(b)):bigint> +-- !query output +11 + + +-- !query +SELECT SUM(a) + 1 FROM testData ORDER BY 1 + SUM(a) +-- !query schema +struct<(sum(a) + 1):bigint> +-- !query output +16 + + +-- !query +SELECT MAX(a) + SUM(b) FROM testData ORDER BY SUM(b) + MAX(a) +-- !query schema +struct<(max(a) + sum(b)):bigint> +-- !query output +13 + + +-- !query +SELECT SUM(a) + 1 + MIN(a) FROM testData ORDER BY 1 + 1 + 1 + MIN(a) + 1 + SUM(a) +-- !query schema +struct<((sum(a) + 1) + min(a)):bigint> +-- !query output +17 + + +-- !query +SELECT SUM(b) + 1 FROM testData HAVING SUM(b) + 1 > 0 ORDER BY SUM(b) + 1 +-- !query schema +struct<(sum(b) + 1):bigint> +-- !query output +11 + + +-- !query +SELECT col1 FROM VALUES(1,2) GROUP BY col1, col2 ORDER BY col2, col2 +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT col1 AS a, a AS b FROM VALUES(1,2) GROUP BY col1, col2 ORDER BY col2, col2 +-- !query schema +struct +-- !query output +1 1 + + +-- !query +SELECT col1, col1 AS a FROM VALUES(1) GROUP BY col1 ORDER BY col1 ASC +-- !query schema +struct +-- !query output +1 1 + + +-- !query +SELECT col1 AS a, col1 FROM VALUES(1) GROUP BY col1 ORDER BY col1 ASC +-- !query schema +struct +-- !query output +1 1 + + +-- !query +SELECT make_date(col1, col2, col3) AS a, a AS b FROM VALUES(1,2,3) GROUP BY make_date(col1, col2, col3) ORDER BY make_date(col1, col2, col3) +-- !query schema +struct +-- !query output +0001-02-03 0001-02-03 + + +-- !query +SELECT 1 AS a, 1 / a AS b, ZEROIFNULL(SUM(col1)) FROM VALUES(1) GROUP BY 1 ORDER BY ZEROIFNULL(SUM(col1)) +-- !query schema +struct +-- !query output +1 1.0 1 + + +-- !query +SELECT col1 AS a, SUM(col2) AS b, CASE WHEN col1 = 1 THEN 1 END AS c FROM VALUES(1,2) GROUP BY col1 ORDER BY CASE WHEN col1 = 1 THEN 1 END ASC +-- !query schema +struct +-- !query output +1 2 1 + + +-- !query +SELECT col1+1 AS ltrl2, col1+1 AS ltrl1 FROM VALUES(1) GROUP BY col1+1 ORDER BY col1+1 +-- !query schema +struct +-- !query output +2 2 + + -- !query DROP VIEW IF EXISTS testData -- !query schema diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/parse-query-correctness-old-behavior.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/parse-query-correctness-old-behavior.sql.out index 6c975186432..8ab45616735 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/parse-query-correctness-old-behavior.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/parse-query-correctness-old-behavior.sql.out @@ -614,7 +614,11 @@ EXECUTE IMMEDIATE 'SELECT 1 UNION SELECT 2 UNION SELECT 3' INTO v1 -- !query schema struct<> -- !query output - +org.apache.spark.SparkException +{ + "errorClass" : "ROW_SUBQUERY_TOO_MANY_ROWS", + "sqlState" : "21000" +} -- !query @@ -622,7 +626,7 @@ SELECT v1 -- !query schema struct -- !query output -1 +NULL -- !query @@ -670,7 +674,7 @@ SELECT v1 -- !query schema struct -- !query output -1 +NULL -- !query @@ -686,7 +690,7 @@ SELECT v1 -- !query schema struct -- !query output -1 +NULL -- !query @@ -710,7 +714,22 @@ EXECUTE IMMEDIATE 'SELECT 1 JOIN SELECT 2' INTO v1 -- !query schema struct<> -- !query output - +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'SELECT'", + "hint" : "" + }, + "queryContext" : [ { + "objectType" : "EXECUTE IMMEDIATE", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 22, + "fragment" : "SELECT 1 JOIN SELECT 2" + } ] +} -- !query @@ -726,7 +745,22 @@ EXECUTE IMMEDIATE 'SELECT 1 VALUES (1)' INTO v1 -- !query schema struct<> -- !query output - +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'('", + "hint" : "" + }, + "queryContext" : [ { + "objectType" : "EXECUTE IMMEDIATE", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 19, + "fragment" : "SELECT 1 VALUES (1)" + } ] +} -- !query @@ -742,7 +776,22 @@ EXECUTE IMMEDIATE 'SELECT 1 alias garbage garbage garbage' INTO v1 -- !query schema struct<> -- !query output - +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'garbage'", + "hint" : "" + }, + "queryContext" : [ { + "objectType" : "EXECUTE IMMEDIATE", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 38, + "fragment" : "SELECT 1 alias garbage garbage garbage" + } ] +} -- !query @@ -758,7 +807,22 @@ EXECUTE IMMEDIATE 'SELECT 1 WITH abc' INTO v1 -- !query schema struct<> -- !query output - +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "PARSE_SYNTAX_ERROR", + "sqlState" : "42601", + "messageParameters" : { + "error" : "'abc'", + "hint" : ": extra input 'abc'" + }, + "queryContext" : [ { + "objectType" : "EXECUTE IMMEDIATE", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 17, + "fragment" : "SELECT 1 WITH abc" + } ] +} -- !query diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/parse-query-correctness.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/parse-query-correctness.sql.out index 1a16dd7564c..d18fee57ef2 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/parse-query-correctness.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/parse-query-correctness.sql.out @@ -647,11 +647,11 @@ org.apache.spark.sql.catalyst.parser.ParseException "hint" : "" }, "queryContext" : [ { - "objectType" : "", + "objectType" : "EXECUTE IMMEDIATE", "objectName" : "", "startIndex" : 1, - "stopIndex" : 50, - "fragment" : "EXECUTE IMMEDIATE 'SELECT 1 JOIN SELECT 2' INTO v1" + "stopIndex" : 22, + "fragment" : "SELECT 1 JOIN SELECT 2" } ] } @@ -678,11 +678,11 @@ org.apache.spark.sql.catalyst.parser.ParseException "hint" : "" }, "queryContext" : [ { - "objectType" : "", + "objectType" : "EXECUTE IMMEDIATE", "objectName" : "", "startIndex" : 1, - "stopIndex" : 47, - "fragment" : "EXECUTE IMMEDIATE 'SELECT 1 VALUES (1)' INTO v1" + "stopIndex" : 19, + "fragment" : "SELECT 1 VALUES (1)" } ] } @@ -709,11 +709,11 @@ org.apache.spark.sql.catalyst.parser.ParseException "hint" : "" }, "queryContext" : [ { - "objectType" : "", + "objectType" : "EXECUTE IMMEDIATE", "objectName" : "", "startIndex" : 1, - "stopIndex" : 66, - "fragment" : "EXECUTE IMMEDIATE 'SELECT 1 alias garbage garbage garbage' INTO v1" + "stopIndex" : 38, + "fragment" : "SELECT 1 alias garbage garbage garbage" } ] } @@ -740,11 +740,11 @@ org.apache.spark.sql.catalyst.parser.ParseException "hint" : ": extra input 'abc'" }, "queryContext" : [ { - "objectType" : "", + "objectType" : "EXECUTE IMMEDIATE", "objectName" : "", "startIndex" : 1, - "stopIndex" : 45, - "fragment" : "EXECUTE IMMEDIATE 'SELECT 1 WITH abc' INTO v1" + "stopIndex" : 17, + "fragment" : "SELECT 1 WITH abc" } ] } diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/postgreSQL/date.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/postgreSQL/date.sql.out index d9f4301dd0e..7dc53d2f264 100755 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/postgreSQL/date.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/postgreSQL/date.sql.out @@ -687,7 +687,7 @@ struct<> -- !query output org.apache.spark.SparkDateTimeException { - "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS", + "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION", "sqlState" : "22023", "messageParameters" : { "ansiConfig" : "\"spark.sql.ansi.enabled\"", @@ -703,7 +703,7 @@ struct<> -- !query output org.apache.spark.SparkDateTimeException { - "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS", + "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION", "sqlState" : "22023", "messageParameters" : { "ansiConfig" : "\"spark.sql.ansi.enabled\"", @@ -719,7 +719,7 @@ struct<> -- !query output org.apache.spark.SparkDateTimeException { - "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS", + "errorClass" : "DATETIME_FIELD_OUT_OF_BOUNDS.WITH_SUGGESTION", "sqlState" : "22023", "messageParameters" : { "ansiConfig" : "\"spark.sql.ansi.enabled\"", diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/postgreSQL/with.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/postgreSQL/with.sql.out index af1c33023a9..1e0441e0739 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/postgreSQL/with.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/postgreSQL/with.sql.out @@ -21,6 +21,204 @@ struct 5 +-- !query +WITH RECURSIVE t(n) AS ( + VALUES (1) +UNION ALL + SELECT n+1 FROM t WHERE n < 100 +) +SELECT sum(n) FROM t +-- !query schema +struct +-- !query output +5050 + + +-- !query +WITH RECURSIVE t(n) AS ( + SELECT (VALUES(1)) +UNION ALL + SELECT n+1 FROM t WHERE n < 5 +) +SELECT * FROM t +-- !query schema +struct +-- !query output +1 +2 +3 +4 +5 + + +-- !query +CREATE TEMPORARY VIEW nums AS +WITH RECURSIVE nums (n) AS ( + VALUES (1) +UNION ALL + SELECT n+1 FROM nums WHERE n < 5 +) +SELECT * FROM nums +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT * FROM nums +-- !query schema +struct +-- !query output +1 +2 +3 +4 +5 + + +-- !query +CREATE OR REPLACE TEMPORARY VIEW nums AS +WITH RECURSIVE nums (n) AS ( + VALUES (1) +UNION ALL + SELECT n+1 FROM nums WHERE n < 6 +) +SELECT * FROM nums +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT * FROM nums +-- !query schema +struct +-- !query output +1 +2 +3 +4 +5 +6 + + +-- !query +WITH RECURSIVE t(n) AS ( + SELECT 1 +UNION + SELECT 10-n FROM t) +SELECT * FROM t +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UNION_NOT_SUPPORTED_IN_RECURSIVE_CTE", + "sqlState" : "42836", + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 83, + "fragment" : "WITH RECURSIVE t(n) AS (\n SELECT 1\nUNION\n SELECT 10-n FROM t)\nSELECT * FROM t" + } ] +} + + +-- !query +WITH RECURSIVE t(n) AS ( + VALUES (1) +UNION ALL + SELECT n+1 FROM t) +SELECT * FROM t LIMIT 10 +-- !query schema +struct +-- !query output +1 +10 +2 +3 +4 +5 +6 +7 +8 +9 + + +-- !query +WITH RECURSIVE t(n) AS ( + SELECT 1 +UNION + SELECT n+1 FROM t) +SELECT * FROM t LIMIT 10 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UNION_NOT_SUPPORTED_IN_RECURSIVE_CTE", + "sqlState" : "42836", + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 91, + "fragment" : "WITH RECURSIVE t(n) AS (\n SELECT 1\nUNION\n SELECT n+1 FROM t)\nSELECT * FROM t LIMIT 10" + } ] +} + + +-- !query +WITH q AS (SELECT 'foo' AS x) +SELECT x FROM q +-- !query schema +struct +-- !query output +foo + + +-- !query +WITH RECURSIVE t(n) AS ( + SELECT 'foo' +UNION ALL + SELECT n || ' bar' FROM t WHERE length(n) < 20 +) +SELECT n AS is_text FROM t +-- !query schema +struct +-- !query output +foo +foo bar +foo bar bar +foo bar bar bar +foo bar bar bar bar +foo bar bar bar bar bar + + +-- !query +WITH RECURSIVE t(n) AS ( + SELECT '7' +UNION ALL + SELECT n+1 FROM t WHERE n < 10 +) +SELECT n FROM t +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkException +{ + "errorClass" : "CANNOT_MERGE_INCOMPATIBLE_DATA_TYPE", + "sqlState" : "42825", + "messageParameters" : { + "left" : "\"STRING\"", + "right" : "\"BIGINT\"" + } +} + + -- !query CREATE TABLE department ( id INTEGER, -- department ID @@ -34,7 +232,590 @@ struct<> -- !query -INSERT INTO department VALUES (0, NULL, 'ROOT') +INSERT INTO department VALUES (0, NULL, 'ROOT') +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO department VALUES (1, 0, 'A') +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO department VALUES (2, 1, 'B') +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO department VALUES (3, 2, 'C') +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO department VALUES (4, 2, 'D') +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO department VALUES (5, 0, 'E') +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO department VALUES (6, 4, 'F') +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO department VALUES (7, 5, 'G') +-- !query schema +struct<> +-- !query output + + + +-- !query +WITH RECURSIVE subdepartment AS +( + SELECT name as root_name, * FROM department WHERE name = 'A' + + UNION ALL + + SELECT sd.root_name, d.* FROM department AS d, subdepartment AS sd + WHERE d.parent_department = sd.id +) +SELECT * FROM subdepartment ORDER BY name +-- !query schema +struct +-- !query output +A 1 0 A +A 2 1 B +A 3 2 C +A 4 2 D +A 6 4 F + + +-- !query +WITH RECURSIVE subdepartment(level, id, parent_department, name) AS +( + SELECT 1, * FROM department WHERE name = 'A' + + UNION ALL + + SELECT sd.level + 1, d.* FROM department AS d, subdepartment AS sd + WHERE d.parent_department = sd.id +) +SELECT * FROM subdepartment ORDER BY name +-- !query schema +struct +-- !query output +1 1 0 A +2 2 1 B +3 3 2 C +3 4 2 D +4 6 4 F + + +-- !query +WITH RECURSIVE subdepartment(level, id, parent_department, name) AS +( + SELECT 1, * FROM department WHERE name = 'A' + + UNION ALL + + SELECT sd.level + 1, d.* FROM department AS d, subdepartment AS sd + WHERE d.parent_department = sd.id +) +SELECT * FROM subdepartment WHERE level >= 2 ORDER BY name +-- !query schema +struct +-- !query output +2 2 1 B +3 3 2 C +3 4 2 D +4 6 4 F + + +-- !query +WITH RECURSIVE subdepartment AS +( + SELECT * FROM department WHERE name = 'A' +) +SELECT * FROM subdepartment ORDER BY name +-- !query schema +struct +-- !query output +1 0 A + + +-- !query +SET spark.sql.cteRecursionLevelLimit=200 +-- !query schema +struct +-- !query output +spark.sql.cteRecursionLevelLimit 200 + + +-- !query +SELECT count(*) FROM ( + WITH RECURSIVE t(n) AS ( + SELECT 1 UNION ALL SELECT n + 1 FROM t WHERE n < 200 + ) + SELECT * FROM t) AS t WHERE n < ( + SELECT count(*) FROM ( + WITH RECURSIVE t(n) AS ( + SELECT 1 UNION ALL SELECT n + 1 FROM t WHERE n < 100 + ) + SELECT * FROM t WHERE n < 50000 + ) AS t WHERE n < 100) +-- !query schema +struct +-- !query output +98 + + +-- !query +SET spark.sql.cteRecursionLevelLimit=100 +-- !query schema +struct +-- !query output +spark.sql.cteRecursionLevelLimit 100 + + +-- !query +WITH q1(x,y) AS ( + SELECT hundred, sum(ten) FROM tenk1 GROUP BY hundred + ) +SELECT count(*) FROM q1 WHERE y > (SELECT sum(y)/100 FROM q1 qsub) +-- !query schema +struct +-- !query output +50 + + +-- !query +CREATE TEMPORARY VIEW vsubdepartment AS + WITH RECURSIVE subdepartment AS + ( + SELECT * FROM department WHERE name = 'A' + UNION ALL + SELECT d.* FROM department AS d, subdepartment AS sd + WHERE d.parent_department = sd.id + ) + SELECT * FROM subdepartment +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT * FROM vsubdepartment ORDER BY name +-- !query schema +struct +-- !query output +1 0 A +2 1 B +3 2 C +4 2 D +6 4 F + + +-- !query +CREATE VIEW sums_1_100 AS +WITH RECURSIVE t(n) AS ( + VALUES (1) +UNION ALL + SELECT n+1 FROM t WHERE n < 100 +) +SELECT sum(n) AS sum FROM t +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT * FROM sums_1_100 +-- !query schema +struct +-- !query output +5050 + + +-- !query +WITH RECURSIVE t(i,j) AS ( + VALUES (1,2) + UNION ALL + SELECT t2.i, t.j+1 FROM + (SELECT 2 AS i UNION ALL SELECT 3 AS i) AS t2 + JOIN t ON (t2.i = t.i+1)) + + SELECT * FROM t +-- !query schema +struct +-- !query output +1 2 +2 3 +3 4 + + +-- !query +CREATE TABLE tree( + id INTEGER, + parent_id INTEGER +) USING parquet +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO tree +VALUES (1, NULL), (2, 1), (3,1), (4,2), (5,2), (6,2), (7,3), (8,3), + (9,4), (10,4), (11,7), (12,7), (13,7), (14, 9), (15,11), (16,11) +-- !query schema +struct<> +-- !query output + + + +-- !query +WITH RECURSIVE t(id, path) AS ( + VALUES(1,cast(array() as array)) +UNION ALL + SELECT tree.id, t.path || array(tree.id) + FROM tree JOIN t ON (tree.parent_id = t.id) +) +SELECT t1.*, t2.* FROM t AS t1 JOIN t AS t2 ON + (t1.path[0] = t2.path[0] AND + size(t1.path) = 1 AND + size(t2.path) > 1) + ORDER BY t1.id, t2.id +-- !query schema +struct,id:int,path:array> +-- !query output +2 [2] 4 [2,4] +2 [2] 5 [2,5] +2 [2] 6 [2,6] +2 [2] 9 [2,4,9] +2 [2] 10 [2,4,10] +2 [2] 14 [2,4,9,14] +3 [3] 7 [3,7] +3 [3] 8 [3,8] +3 [3] 11 [3,7,11] +3 [3] 12 [3,7,12] +3 [3] 13 [3,7,13] +3 [3] 15 [3,7,11,15] +3 [3] 16 [3,7,11,16] + + +-- !query +WITH RECURSIVE t(id, path) AS ( + VALUES(1,cast(array() as array)) +UNION ALL + SELECT tree.id, t.path || array(tree.id) + FROM tree JOIN t ON (tree.parent_id = t.id) +) +SELECT t1.id, count(*) FROM t AS t1 JOIN t AS t2 ON + (t1.path[0] = t2.path[0] AND + size(t1.path) = 1 AND + size(t2.path) > 1) + GROUP BY t1.id + ORDER BY t1.id +-- !query schema +struct +-- !query output +2 6 +3 7 + + +-- !query +WITH RECURSIVE t(id, path) AS ( + VALUES(1,cast(array() as array)) +UNION ALL + SELECT tree.id, t.path || array(tree.id) + FROM tree JOIN t ON (tree.parent_id = t.id) +) +SELECT t1.id, t2.path, struct(t2.*) FROM t AS t1 JOIN t AS t2 ON +(t1.id=t2.id) +-- !query schema +struct,struct(id, path):struct>> +-- !query output +1 [] {"id":1,"path":[]} +10 [2,4,10] {"id":10,"path":[2,4,10]} +11 [3,7,11] {"id":11,"path":[3,7,11]} +12 [3,7,12] {"id":12,"path":[3,7,12]} +13 [3,7,13] {"id":13,"path":[3,7,13]} +14 [2,4,9,14] {"id":14,"path":[2,4,9,14]} +15 [3,7,11,15] {"id":15,"path":[3,7,11,15]} +16 [3,7,11,16] {"id":16,"path":[3,7,11,16]} +2 [2] {"id":2,"path":[2]} +3 [3] {"id":3,"path":[3]} +4 [2,4] {"id":4,"path":[2,4]} +5 [2,5] {"id":5,"path":[2,5]} +6 [2,6] {"id":6,"path":[2,6]} +7 [3,7] {"id":7,"path":[3,7]} +8 [3,8] {"id":8,"path":[3,8]} +9 [2,4,9] {"id":9,"path":[2,4,9]} + + +-- !query +create table graph( f int, t int, label string ) USING parquet +-- !query schema +struct<> +-- !query output + + + +-- !query +insert into graph values + (1, 2, 'arc 1 -> 2'), + (1, 3, 'arc 1 -> 3'), + (2, 3, 'arc 2 -> 3'), + (1, 4, 'arc 1 -> 4'), + (4, 5, 'arc 4 -> 5'), + (5, 1, 'arc 5 -> 1') +-- !query schema +struct<> +-- !query output + + + +-- !query +with recursive search_graph(f, t, label, path, cycle) as ( + select *, array(struct(g.f, g.t)), false from graph g + union all + select g.*, path || array(struct(g.f, g.t)), array_contains(path, struct(g.f, g.t)) + from graph g, search_graph sg + where g.f = sg.t and not cycle +) +select * from search_graph +-- !query schema +struct>,cycle:boolean> +-- !query output +1 2 arc 1 -> 2 [{"f":1,"t":2}] false +1 2 arc 1 -> 2 [{"f":1,"t":4},{"f":4,"t":5},{"f":5,"t":1},{"f":1,"t":2}] false +1 2 arc 1 -> 2 [{"f":4,"t":5},{"f":5,"t":1},{"f":1,"t":2}] false +1 2 arc 1 -> 2 [{"f":5,"t":1},{"f":1,"t":2}] false +1 3 arc 1 -> 3 [{"f":1,"t":3}] false +1 3 arc 1 -> 3 [{"f":1,"t":4},{"f":4,"t":5},{"f":5,"t":1},{"f":1,"t":3}] false +1 3 arc 1 -> 3 [{"f":4,"t":5},{"f":5,"t":1},{"f":1,"t":3}] false +1 3 arc 1 -> 3 [{"f":5,"t":1},{"f":1,"t":3}] false +1 4 arc 1 -> 4 [{"f":1,"t":4},{"f":4,"t":5},{"f":5,"t":1},{"f":1,"t":4}] true +1 4 arc 1 -> 4 [{"f":1,"t":4}] false +1 4 arc 1 -> 4 [{"f":4,"t":5},{"f":5,"t":1},{"f":1,"t":4}] false +1 4 arc 1 -> 4 [{"f":5,"t":1},{"f":1,"t":4}] false +2 3 arc 2 -> 3 [{"f":1,"t":2},{"f":2,"t":3}] false +2 3 arc 2 -> 3 [{"f":1,"t":4},{"f":4,"t":5},{"f":5,"t":1},{"f":1,"t":2},{"f":2,"t":3}] false +2 3 arc 2 -> 3 [{"f":2,"t":3}] false +2 3 arc 2 -> 3 [{"f":4,"t":5},{"f":5,"t":1},{"f":1,"t":2},{"f":2,"t":3}] false +2 3 arc 2 -> 3 [{"f":5,"t":1},{"f":1,"t":2},{"f":2,"t":3}] false +4 5 arc 4 -> 5 [{"f":1,"t":4},{"f":4,"t":5}] false +4 5 arc 4 -> 5 [{"f":4,"t":5},{"f":5,"t":1},{"f":1,"t":4},{"f":4,"t":5}] true +4 5 arc 4 -> 5 [{"f":4,"t":5}] false +4 5 arc 4 -> 5 [{"f":5,"t":1},{"f":1,"t":4},{"f":4,"t":5}] false +5 1 arc 5 -> 1 [{"f":1,"t":4},{"f":4,"t":5},{"f":5,"t":1}] false +5 1 arc 5 -> 1 [{"f":4,"t":5},{"f":5,"t":1}] false +5 1 arc 5 -> 1 [{"f":5,"t":1},{"f":1,"t":4},{"f":4,"t":5},{"f":5,"t":1}] true +5 1 arc 5 -> 1 [{"f":5,"t":1}] false + + +-- !query +with recursive search_graph(f, t, label, path, cycle) as ( + select *, array(struct(g.f, g.t)), false from graph g + union all + select g.*, path || array(struct(g.f, g.t)), array_contains(path, struct(g.f, g.t)) + from graph g, search_graph sg + where g.f = sg.t and not cycle +) +select * from search_graph order by path +-- !query schema +struct>,cycle:boolean> +-- !query output +1 2 arc 1 -> 2 [{"f":1,"t":2}] false +2 3 arc 2 -> 3 [{"f":1,"t":2},{"f":2,"t":3}] false +1 3 arc 1 -> 3 [{"f":1,"t":3}] false +1 4 arc 1 -> 4 [{"f":1,"t":4}] false +4 5 arc 4 -> 5 [{"f":1,"t":4},{"f":4,"t":5}] false +5 1 arc 5 -> 1 [{"f":1,"t":4},{"f":4,"t":5},{"f":5,"t":1}] false +1 2 arc 1 -> 2 [{"f":1,"t":4},{"f":4,"t":5},{"f":5,"t":1},{"f":1,"t":2}] false +2 3 arc 2 -> 3 [{"f":1,"t":4},{"f":4,"t":5},{"f":5,"t":1},{"f":1,"t":2},{"f":2,"t":3}] false +1 3 arc 1 -> 3 [{"f":1,"t":4},{"f":4,"t":5},{"f":5,"t":1},{"f":1,"t":3}] false +1 4 arc 1 -> 4 [{"f":1,"t":4},{"f":4,"t":5},{"f":5,"t":1},{"f":1,"t":4}] true +2 3 arc 2 -> 3 [{"f":2,"t":3}] false +4 5 arc 4 -> 5 [{"f":4,"t":5}] false +5 1 arc 5 -> 1 [{"f":4,"t":5},{"f":5,"t":1}] false +1 2 arc 1 -> 2 [{"f":4,"t":5},{"f":5,"t":1},{"f":1,"t":2}] false +2 3 arc 2 -> 3 [{"f":4,"t":5},{"f":5,"t":1},{"f":1,"t":2},{"f":2,"t":3}] false +1 3 arc 1 -> 3 [{"f":4,"t":5},{"f":5,"t":1},{"f":1,"t":3}] false +1 4 arc 1 -> 4 [{"f":4,"t":5},{"f":5,"t":1},{"f":1,"t":4}] false +4 5 arc 4 -> 5 [{"f":4,"t":5},{"f":5,"t":1},{"f":1,"t":4},{"f":4,"t":5}] true +5 1 arc 5 -> 1 [{"f":5,"t":1}] false +1 2 arc 1 -> 2 [{"f":5,"t":1},{"f":1,"t":2}] false +2 3 arc 2 -> 3 [{"f":5,"t":1},{"f":1,"t":2},{"f":2,"t":3}] false +1 3 arc 1 -> 3 [{"f":5,"t":1},{"f":1,"t":3}] false +1 4 arc 1 -> 4 [{"f":5,"t":1},{"f":1,"t":4}] false +4 5 arc 4 -> 5 [{"f":5,"t":1},{"f":1,"t":4},{"f":4,"t":5}] false +5 1 arc 5 -> 1 [{"f":5,"t":1},{"f":1,"t":4},{"f":4,"t":5},{"f":5,"t":1}] true + + +-- !query +WITH RECURSIVE + y (id) AS (VALUES (1)), + x (id) AS (SELECT * FROM y UNION ALL SELECT id+1 FROM x WHERE id < 5) +SELECT * FROM x +-- !query schema +struct +-- !query output +1 +2 +3 +4 +5 + + +-- !query +WITH RECURSIVE + x(id) AS + (SELECT 1 UNION ALL SELECT id+1 FROM x WHERE id < 3 ), + y(id) AS + (SELECT * FROM x UNION ALL SELECT * FROM x), + z(id) AS + (SELECT * FROM x UNION ALL SELECT id+1 FROM z WHERE id < 10) + SELECT * FROM z +-- !query schema +struct +-- !query output +1 +10 +10 +10 +2 +2 +3 +3 +3 +4 +4 +4 +5 +5 +5 +6 +6 +6 +7 +7 +7 +8 +8 +8 +9 +9 +9 + + +-- !query +WITH RECURSIVE + x(id) AS + (SELECT 1 UNION ALL SELECT id+1 FROM x WHERE id < 3 ), + y(id) AS + (SELECT * FROM x UNION ALL SELECT * FROM x), + z(id) AS + (SELECT * FROM y UNION ALL SELECT id+1 FROM z WHERE id < 10) + SELECT * FROM z +-- !query schema +struct +-- !query output +1 +1 +10 +10 +10 +10 +10 +10 +2 +2 +2 +2 +3 +3 +3 +3 +3 +3 +4 +4 +4 +4 +4 +4 +5 +5 +5 +5 +5 +5 +6 +6 +6 +6 +6 +6 +7 +7 +7 +7 +7 +7 +8 +8 +8 +8 +8 +8 +9 +9 +9 +9 +9 +9 + + +-- !query +CREATE TABLE y (a INTEGER) USING parquet +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO y SELECT EXPLODE(SEQUENCE(1, 10)) -- !query schema struct<> -- !query output @@ -42,7 +823,7 @@ struct<> -- !query -INSERT INTO department VALUES (1, 0, 'A') +DROP TABLE y -- !query schema struct<> -- !query output @@ -50,47 +831,85 @@ struct<> -- !query -INSERT INTO department VALUES (2, 1, 'B') +WITH RECURSIVE x(n) AS (SELECT 1 INTERSECT SELECT n+1 FROM x) + SELECT * FROM x -- !query schema struct<> -- !query output - +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_CTE", + "sqlState" : "42836" +} -- !query -INSERT INTO department VALUES (3, 2, 'C') +WITH RECURSIVE x(n) AS (SELECT 1 INTERSECT ALL SELECT n+1 FROM x) + SELECT * FROM x -- !query schema struct<> -- !query output - +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_CTE", + "sqlState" : "42836" +} -- !query -INSERT INTO department VALUES (4, 2, 'D') +WITH RECURSIVE x(n) AS (SELECT 1 EXCEPT SELECT n+1 FROM x) + SELECT * FROM x -- !query schema struct<> -- !query output - +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_CTE", + "sqlState" : "42836" +} -- !query -INSERT INTO department VALUES (5, 0, 'E') +WITH RECURSIVE x(n) AS (SELECT 1 EXCEPT ALL SELECT n+1 FROM x) + SELECT * FROM x -- !query schema struct<> -- !query output - +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_CTE", + "sqlState" : "42836" +} -- !query -INSERT INTO department VALUES (6, 4, 'F') +WITH RECURSIVE x(n) AS (SELECT n FROM x) + SELECT * FROM x -- !query schema struct<> -- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_CTE", + "sqlState" : "42836" +} + +-- !query +WITH RECURSIVE x(n) AS (SELECT n FROM x UNION ALL SELECT 1) + SELECT * FROM x +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_CTE", + "sqlState" : "42836" +} -- !query -INSERT INTO department VALUES (7, 5, 'G') +CREATE TABLE y (a INTEGER) USING parquet -- !query schema struct<> -- !query output @@ -98,10 +917,7 @@ struct<> -- !query -CREATE TABLE tree( - id INTEGER, - parent_id INTEGER -) USING parquet +INSERT INTO y SELECT EXPLODE(SEQUENCE(1, 10)) -- !query schema struct<> -- !query output @@ -109,75 +925,461 @@ struct<> -- !query -INSERT INTO tree -VALUES (1, NULL), (2, 1), (3,1), (4,2), (5,2), (6,2), (7,3), (8,3), - (9,4), (10,4), (11,7), (12,7), (13,7), (14, 9), (15,11), (16,11) +WITH RECURSIVE x(n) AS (SELECT a FROM y WHERE a = 1 + UNION ALL + SELECT x.n+1 FROM y LEFT JOIN x ON x.n = y.a WHERE n < 10) +SELECT * FROM x -- !query schema struct<> -- !query output - +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_REFERENCE.PLACE", + "sqlState" : "42836" +} -- !query -create table graph( f int, t int, label string ) USING parquet +WITH RECURSIVE x(n) AS (SELECT a FROM y WHERE a = 1 + UNION ALL + SELECT x.n+1 FROM x RIGHT JOIN y ON x.n = y.a WHERE n < 10) +SELECT * FROM x -- !query schema struct<> -- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_REFERENCE.PLACE", + "sqlState" : "42836" +} +-- !query +WITH RECURSIVE x(n) AS (SELECT a FROM y WHERE a = 1 + UNION ALL + SELECT x.n+1 FROM x FULL JOIN y ON x.n = y.a WHERE n < 10) +SELECT * FROM x +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_REFERENCE.PLACE", + "sqlState" : "42836" +} + -- !query -insert into graph values - (1, 2, 'arc 1 -> 2'), - (1, 3, 'arc 1 -> 3'), - (2, 3, 'arc 2 -> 3'), - (1, 4, 'arc 1 -> 4'), - (4, 5, 'arc 4 -> 5'), - (5, 1, 'arc 5 -> 1') +WITH RECURSIVE x(n) AS (SELECT 1 UNION ALL SELECT n+1 FROM x + WHERE n IN (SELECT * FROM x)) + SELECT * FROM x -- !query schema struct<> -- !query output +org.apache.spark.SparkException +{ + "errorClass" : "RECURSION_LEVEL_LIMIT_EXCEEDED", + "sqlState" : "42836", + "messageParameters" : { + "levelLimit" : "100" + } +} +-- !query +WITH RECURSIVE x(n) AS (SELECT cast(1 as bigint) UNION ALL SELECT count(*) FROM x) + SELECT * FROM x +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_REFERENCE.PLACE", + "sqlState" : "42836" +} + -- !query -CREATE TABLE y (a INTEGER) USING parquet +WITH RECURSIVE x(n) AS (SELECT cast(1 as bigint) UNION ALL SELECT sum(n) FROM x) + SELECT * FROM x -- !query schema struct<> -- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_REFERENCE.PLACE", + "sqlState" : "42836" +} +-- !query +WITH RECURSIVE x(n) AS (SELECT 1 UNION ALL SELECT n+1 FROM x ORDER BY 1) + SELECT * FROM x +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_CTE", + "sqlState" : "42836" +} + -- !query -INSERT INTO y SELECT EXPLODE(SEQUENCE(1, 10)) +WITH RECURSIVE x(n) AS (SELECT 1 UNION ALL SELECT n+1 FROM x LIMIT 10 OFFSET 1) + SELECT * FROM x -- !query schema struct<> -- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_CTE", + "sqlState" : "42836" +} +-- !query +WITH RECURSIVE x(id) AS (values (1) + UNION ALL + SELECT (SELECT * FROM x) FROM x WHERE id < 5 +) SELECT * FROM x +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkException +{ + "errorClass" : "RECURSION_LEVEL_LIMIT_EXCEEDED", + "sqlState" : "42836", + "messageParameters" : { + "levelLimit" : "100" + } +} + -- !query -DROP TABLE y +WITH RECURSIVE + x (id) AS (SELECT 1 UNION ALL SELECT id+1 FROM y WHERE id < 5), + y (id) AS (SELECT 1 UNION ALL SELECT id+1 FROM x WHERE id < 5) +SELECT * FROM x -- !query schema struct<> -- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNRESOLVED_COLUMN.WITHOUT_SUGGESTION", + "sqlState" : "42703", + "messageParameters" : { + "objectName" : "`id`" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 139, + "stopIndex" : 140, + "fragment" : "id" + } ] +} + + +-- !query +WITH RECURSIVE foo(i) AS + (values (1) + UNION ALL + (SELECT i+1 FROM foo WHERE i < 10 + UNION ALL + SELECT i+1 FROM foo WHERE i < 5) +) SELECT * FROM foo +-- !query schema +struct +-- !query output +1 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +2 +2 +3 +3 +3 +3 +4 +4 +4 +4 +4 +4 +4 +4 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +6 +6 +6 +6 +6 +6 +6 +6 +6 +6 +6 +6 +6 +6 +6 +6 +7 +7 +7 +7 +7 +7 +7 +7 +7 +7 +7 +7 +7 +7 +7 +7 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +9 +9 +9 +9 +9 +9 +9 +9 +9 +9 +9 +9 +9 +9 +9 +9 + +-- !query +WITH RECURSIVE foo(i) AS + (values (1) + UNION ALL + SELECT * FROM + (SELECT i+1 FROM foo WHERE i < 10 + UNION ALL + SELECT i+1 FROM foo WHERE i < 5) AS t +) SELECT * FROM foo +-- !query schema +struct +-- !query output +1 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +2 +2 +3 +3 +3 +3 +4 +4 +4 +4 +4 +4 +4 +4 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +5 +6 +6 +6 +6 +6 +6 +6 +6 +6 +6 +6 +6 +6 +6 +6 +6 +7 +7 +7 +7 +7 +7 +7 +7 +7 +7 +7 +7 +7 +7 +7 +7 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +8 +9 +9 +9 +9 +9 +9 +9 +9 +9 +9 +9 +9 +9 +9 +9 +9 -- !query -CREATE TABLE y (a INTEGER) USING parquet +WITH RECURSIVE foo(i) AS + (values (1) + UNION ALL + (SELECT i+1 FROM foo WHERE i < 10 + EXCEPT + SELECT i+1 FROM foo WHERE i < 5) +) SELECT * FROM foo -- !query schema -struct<> +struct -- !query output +1 + +-- !query +WITH RECURSIVE foo(i) AS + (values (1) + UNION ALL + (SELECT i+1 FROM foo WHERE i < 10 + INTERSECT + SELECT i+1 FROM foo WHERE i < 5) +) SELECT * FROM foo +-- !query schema +struct +-- !query output +1 +2 +3 +4 +5 -- !query -INSERT INTO y SELECT EXPLODE(SEQUENCE(1, 10)) +WITH RECURSIVE foo(i) AS + (SELECT i FROM (VALUES(1),(2)) t(i) + UNION ALL + SELECT cast((i+1) AS decimal(10,0)) FROM foo WHERE i < 10) +SELECT * FROM foo -- !query schema struct<> -- !query output - +org.apache.spark.SparkException +{ + "errorClass" : "CANNOT_MERGE_INCOMPATIBLE_DATA_TYPE", + "sqlState" : "42825", + "messageParameters" : { + "left" : "\"INT\"", + "right" : "\"DECIMAL(10,0)\"" + } +} -- !query @@ -188,6 +1390,78 @@ struct 42 +-- !query +WITH RECURSIVE t(j) AS ( + WITH RECURSIVE s(i) AS ( + VALUES (1) + UNION ALL + SELECT i+1 FROM s WHERE i < 10 + ) + SELECT i FROM s + UNION ALL + SELECT j+1 FROM t WHERE j < 10 +) +SELECT * FROM t +-- !query schema +struct +-- !query output +1 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +2 +2 +3 +3 +3 +4 +4 +4 +4 +5 +5 +5 +5 +5 +6 +6 +6 +6 +6 +6 +7 +7 +7 +7 +7 +7 +7 +8 +8 +8 +8 +8 +8 +8 +8 +9 +9 +9 +9 +9 +9 +9 +9 +9 + + -- !query WITH outermost(x) AS ( SELECT 1 @@ -232,6 +1506,48 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException } +-- !query +WITH RECURSIVE outermost(x) AS ( + SELECT 1 + UNION (WITH innermost as (SELECT 2) + SELECT * FROM outermost + UNION SELECT * FROM innermost) +) +SELECT * FROM outermost ORDER BY 1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "UNION_NOT_SUPPORTED_IN_RECURSIVE_CTE", + "sqlState" : "42836", + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 191, + "fragment" : "WITH RECURSIVE outermost(x) AS (\n SELECT 1\n UNION (WITH innermost as (SELECT 2)\n SELECT * FROM outermost\n UNION SELECT * FROM innermost)\n)\nSELECT * FROM outermost ORDER BY 1" + } ] +} + + +-- !query +WITH RECURSIVE outermost(x) AS ( + WITH innermost as (SELECT 2 FROM outermost) -- fail + SELECT * FROM innermost + UNION SELECT * from outermost +) +SELECT * FROM outermost ORDER BY 1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_RECURSIVE_CTE", + "sqlState" : "42836" +} + + -- !query CREATE TABLE withz USING parquet AS SELECT i AS k, CAST(i AS string) || ' v' AS v FROM (SELECT EXPLODE(SEQUENCE(1, 16, 3)) i) -- !query schema @@ -459,6 +1775,30 @@ struct<> +-- !query +DROP VIEW nums +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP VIEW vsubdepartment +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP VIEW sums_1_100 +-- !query schema +struct<> +-- !query output + + + -- !query DROP TABLE department -- !query schema diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/replacing-missing-expression-with-alias.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/replacing-missing-expression-with-alias.sql.out new file mode 100644 index 00000000000..f3a6b0424b6 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/replacing-missing-expression-with-alias.sql.out @@ -0,0 +1,178 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +SELECT col1 + 1 AS a FROM VALUES(1) GROUP BY a ORDER BY col1 + 1 +-- !query schema +struct +-- !query output +2 + + +-- !query +SELECT col1 + 1 AS a, a AS b FROM VALUES(1) GROUP BY a ORDER BY col1 + 1 +-- !query schema +struct +-- !query output +2 2 + + +-- !query +SELECT col1 + 1 AS a FROM VALUES(1) GROUP BY a HAVING col1 + 1 > 0 +-- !query schema +struct +-- !query output +2 + + +-- !query +SELECT col1 + 1 AS a, a AS b FROM VALUES(1) GROUP BY a HAVING col1 + 1 > 0 +-- !query schema +struct +-- !query output +2 2 + + +-- !query +SELECT col1, col2, GROUPING(col1) FROM VALUES("abc", 1) GROUP BY CUBE(col1, col2) ORDER BY GROUPING(col1) +-- !query schema +struct +-- !query output +abc 1 0 +abc NULL 0 +NULL 1 1 +NULL NULL 1 + + +-- !query +SELECT col1, col2, GROUPING(col1) FROM VALUES("abc", 1) GROUP BY CUBE(col1, col2) HAVING GROUPING(col1) != NULL +-- !query schema +struct +-- !query output + + + +-- !query +SELECT make_date(col1, col2, col3) AS a FROM VALUES(1,2,3) GROUP BY make_date(col1, col2, col3) ORDER BY make_date(col1, col2, col3) +-- !query schema +struct +-- !query output +0001-02-03 + + +-- !query +SELECT make_date(col1, col2, col3) AS a, a AS b FROM VALUES(1,2,3) GROUP BY make_date(col1, col2, col3) ORDER BY make_date(col1, col2, col3) +-- !query schema +struct +-- !query output +0001-02-03 0001-02-03 + + +-- !query +SELECT make_date(col1, col2, col3) AS a FROM VALUES(1,2,3) GROUP BY make_date(col1, col2, col3) HAVING make_date(col1, col2, col3) > '2025-01-01' +-- !query schema +struct +-- !query output + + + +-- !query +SELECT make_date(col1, col2, col3) AS a, a AS b FROM VALUES(1,2,3) GROUP BY make_date(col1, col2, col3) HAVING make_date(col1, col2, col3) > '2025-01-01' +-- !query schema +struct +-- !query output + + + +-- !query +SELECT make_date(col1, col2, col3) AS a FROM VALUES(1,2,3) ORDER BY make_date(col1, col2, col3) +-- !query schema +struct +-- !query output +0001-02-03 + + +-- !query +SELECT make_date(col1, col2, col3) AS a, a AS b FROM VALUES(1,2,3) ORDER BY make_date(col1, col2, col3) +-- !query schema +struct +-- !query output +0001-02-03 0001-02-03 + + +-- !query +SELECT col1, col1 AS a FROM VALUES(1) GROUP BY col1 ORDER BY col1 ASC +-- !query schema +struct +-- !query output +1 1 + + +-- !query +SELECT col1 AS a, col1 FROM VALUES(1) GROUP BY col1 ORDER BY col1 ASC +-- !query schema +struct +-- !query output +1 1 + + +-- !query +SELECT col1, col1 AS a FROM VALUES(1) GROUP BY col1 HAVING col1 > 0 +-- !query schema +struct +-- !query output +1 1 + + +-- !query +SELECT col1 AS a, col1 FROM VALUES(1) GROUP BY col1 HAVING col1 > 0 +-- !query schema +struct +-- !query output +1 1 + + +-- !query +SELECT col2 AS b, col2 FROM VALUES(1,2) GROUP BY 1,2 ORDER BY ALL +-- !query schema +struct +-- !query output +2 2 + + +-- !query +SELECT col2 AS b, col2 FROM VALUES(1,2) GROUP BY 1,2 HAVING col2 > 0 ORDER BY ALL +-- !query schema +struct +-- !query output +2 2 + + +-- !query +SELECT col2 AS b, col2, b as c FROM VALUES(1,2) GROUP BY 1,2 ORDER BY ALL +-- !query schema +struct +-- !query output +2 2 2 + + +-- !query +SELECT col2 AS b, col2, b as c FROM VALUES(1,2) GROUP BY 1,2 HAVING col2 > 0 ORDER BY ALL +-- !query schema +struct +-- !query output +2 2 2 + + +-- !query +SELECT col1 AS a FROM VALUES(1,2) GROUP BY col1, col2 HAVING col2 > 1 ORDER BY col1 +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT col1 AS a, a AS b FROM VALUES(1,2) GROUP BY col1, col2 HAVING col2 > 1 ORDER BY col1 +-- !query schema +struct +-- !query output +1 1 diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/runtime-replaceable-edge-cases.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/runtime-replaceable-edge-cases.sql.out new file mode 100644 index 00000000000..6fee715dc73 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/runtime-replaceable-edge-cases.sql.out @@ -0,0 +1,24 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +SELECT xpath_string('abc', date_format('X', 'unknown')) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkDateTimeException +{ + "errorClass" : "CAST_INVALID_INPUT", + "sqlState" : "22018", + "messageParameters" : { + "ansiConfig" : "\"spark.sql.ansi.enabled\"", + "expression" : "'X'", + "sourceType" : "\"STRING\"", + "targetType" : "\"TIMESTAMP\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 28, + "stopIndex" : 54, + "fragment" : "date_format('X', 'unknown')" + } ] +} diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/scripting/randomly_generated_scripts.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/scripting/randomly_generated_scripts.sql.out new file mode 100644 index 00000000000..1583266025e --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/scripting/randomly_generated_scripts.sql.out @@ -0,0 +1,7002 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +CREATE TABLE products ( + product_id INT, + product_name STRING, + product_category STRING, + product_price DOUBLE, + product_cost DECIMAL(10, 2), + supplier_id INT, + supplier_name STRING, + supplier_contact STRING, + supplier_address STRING, + product_quantity INT, + product_color STRING, + product_size STRING, + product_weight DOUBLE, + product_description STRING, + product_rating DOUBLE, + product_reviews INT, + product_launch_date TIMESTAMP, + product_last_update TIMESTAMP, + product_is_active BOOLEAN, + product_discount DOUBLE, + product_vat DOUBLE +) +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE customers ( + customer_id INT, + customer_name STRING, + customer_email STRING, + customer_phone STRING, + customer_address_1 STRING, + customer_address_2 STRING, + customer_city STRING, + customer_state STRING, + customer_zip STRING, + customer_country STRING, + customer_type STRING, + customer_membership_date TIMESTAMP, + customer_total_spent DOUBLE, + customer_last_order_id INT, + customer_last_order_date TIMESTAMP, + customer_last_payment_date TIMESTAMP, + customer_active_status BOOLEAN, + customer_opt_in_newsletter BOOLEAN, + customer_discount_percentage DOUBLE, + customer_vat_number STRING, + customer_billing_contact STRING +) +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE orders ( + order_id INT, + customer_id INT, + order_date TIMESTAMP, + order_status STRING, + order_total DOUBLE, + order_tax DOUBLE, + order_discount DOUBLE, + order_shipping DOUBLE, + order_shipping_address_1 STRING, + order_shipping_address_2 STRING, + order_shipping_city STRING, + order_shipping_state STRING, + order_shipping_zip STRING, + order_shipping_country STRING, + order_billing_identifier STRING, + order_payment_method STRING, + order_payment_status STRING, + order_payment_date TIMESTAMP, + order_cancelation_date TIMESTAMP, + order_return_request_date TIMESTAMP, + order_completion_date TIMESTAMP, + order_source STRING, + order_device STRING, + order_channel STRING +) +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE order_items ( + order_item_id INT, + order_id INT, + product_id INT, + item_quantity INT, + item_price_per_unit DOUBLE, + item_discount DOUBLE, + item_tax DOUBLE, + item_total DOUBLE, + item_status STRING, + item_offer_code STRING, + item_shipping_date TIMESTAMP, + item_delivery_date TIMESTAMP, + item_return_date TIMESTAMP +) +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE employees ( + employee_id INT, + employee_name STRING, + employee_email STRING, + employee_phone STRING, + employee_position STRING, + employee_department STRING, + employee_hire_date TIMESTAMP, + employee_termination_date TIMESTAMP, + employee_salary DOUBLE, + employee_commission DOUBLE, + employee_manager_id INT, + employee_address_1 STRING, + employee_address_2 STRING, + employee_city STRING, + employee_state STRING, + employee_zip STRING, + employee_country STRING, + employee_birth_date TIMESTAMP, + employee_gender STRING, + employee_marital_status STRING, + employee_dependents INT +) +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE suppliers ( + supplier_id INT, + supplier_name STRING, + supplier_contact STRING, + supplier_contact_role STRING, + supplier_contact_email STRING, + supplier_contact_phone_1 STRING, + supplier_contact_phone_2 STRING, + supplier_address_1 STRING, + supplier_address_2 STRING, + supplier_address_3 STRING, + supplier_city STRING, + supplier_state STRING, + supplier_zip STRING, + supplier_country STRING, + supplier_region STRING, + supplier_main_products STRING, + supplier_website STRING, + supplier_pricing_agreement_date TIMESTAMP, + supplier_last_order_date TIMESTAMP, + supplier_last_contact_date TIMESTAMP, + supplier_rating DOUBLE, + supplier_active BOOLEAN +) +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO products VALUES (1, 'Super Widget', 'Electronics', 155.99, 99.99, 1, 'Acme Inc', 'John D.', '123 Main St', 25, 'Blue', 'Large', 1.2, 'High quality widget', 4.5, 120, TIMESTAMP '2022-01-01', TIMESTAMP '2023-01-01', true, 0.0, 0.21) +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO products VALUES (2, 'Deluxe Gadget', 'Electronics', 89.99, 60.00, 2, 'Widgets Co', 'Mary K.', '456 Elm St', 100, 'Red', 'Small', 0.5, 'Portable gadget', 4.2, 200, TIMESTAMP '2022-02-15', TIMESTAMP '2023-02-15', true, 0.1, 0.19) +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO products VALUES (3, 'Classic Toy', 'Toys', 19.95, 12.00, 3, 'Toy Supply', 'Ann T.', '789 Oak St', 50, 'Multicolor', 'Medium', 0.8, 'Classic wooden toy', 4.7, 80, TIMESTAMP '2021-11-01', TIMESTAMP '2023-01-10', true, 0.05, 0.15) +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO customers VALUES (1, 'Alice Johnson', 'alice@example.com', '555-1000', '101 Maple Ave', NULL, 'Springfield', 'IL', '12345', 'USA', 'Retail', TIMESTAMP '2020-05-01', 899.99, 1001, TIMESTAMP '2023-01-20', TIMESTAMP '2023-01-21', true, true, 5.0, 'US123456', 'Alice Johnson') +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO customers VALUES (2, 'Bob Smith', 'bob@example.com', '555-1002', '202 Oak St', 'Apt 3', 'Oakville', 'CA', '67890', 'USA', 'Wholesale', TIMESTAMP '2021-03-15', 1200.50, 1002, TIMESTAMP '2023-02-10', TIMESTAMP '2023-02-11', true, false, 10.0, 'US923456', 'Bob Smith') +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO customers VALUES (3, 'Cathy Lee', 'cathy@example.com', '555-1003', '303 Pine Ln', NULL, 'Pineville', 'TX', '54321', 'USA', 'Retail', TIMESTAMP '2022-07-01', 400.75, 1003, TIMESTAMP '2023-03-05', TIMESTAMP '2023-03-06', true, true, 0.0, 'US563456', 'Cathy Lee') +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO orders VALUES (1001, 1, TIMESTAMP '2023-01-20', 'Completed', 155.99, 15.89, 0.0, 10.00, '101 Maple Ave', NULL, 'Springfield', 'IL', '12345', 'USA', 'ORD1001', 'Credit Card', 'Paid', TIMESTAMP '2023-01-21', NULL, NULL, TIMESTAMP '2023-01-25', 'Web', 'Desktop', 'Online') +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO orders VALUES (1002, 2, TIMESTAMP '2023-02-10', 'Completed', 179.89, 18.99, 10.0, 8.99, '202 Oak St', 'Apt 3', 'Oakville', 'CA', '67890', 'USA', 'ORD1002', 'Credit Card', 'Paid', TIMESTAMP '2023-02-11', NULL, NULL, TIMESTAMP '2023-02-15', 'Mobile', 'iOS', 'Online') +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO orders VALUES (1003, 3, TIMESTAMP '2023-03-05', 'Processing', 19.95, 3.99, 1.0, 5.99, '303 Pine Ln', NULL, 'Pineville', 'TX', '54321', 'USA', 'ORD1003', 'PayPal', 'Pending', NULL, NULL, NULL, NULL, 'App', 'Android', 'Mobile App') +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO order_items VALUES (101, 1001, 1, 1, 155.99, 0.0, 15.89, 171.88, 'Shipped', 'SPRING2023', TIMESTAMP '2023-01-20', NULL, NULL) +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO order_items VALUES (102, 1002, 2, 2, 89.99, 8.99, 8.99, 170.97, 'Shipped', 'SUMMER2023', TIMESTAMP '2023-02-10', NULL, NULL) +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO order_items VALUES (103, 1003, 3, 1, 19.95, 1.0, 3.99, 22.94, 'Processing', 'FALL2023', NULL, NULL, NULL) +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO employees VALUES (1, 'Dan Miller', 'dan@example.com', '555-2001', 'Manager', 'Sales', TIMESTAMP '2018-01-01', NULL, 75000.0, 2500.0, NULL, '404 Birch St', NULL, 'Birchville', 'NY', '00123', 'USA', TIMESTAMP '1980-07-10', 'Male', 'Married', 2) +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO employees VALUES (2, 'Eva Perez', 'eva@example.com', '555-2002', 'Salesperson', 'Sales', TIMESTAMP '2019-03-01', NULL, 50000.0, 1500.0, 1, '505 Cedar Dr', 'Unit 2', 'Cedarville', 'NJ', '00234', 'USA', TIMESTAMP '1992-09-25', 'Female', 'Single', 0) +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO employees VALUES (3, 'Frank Wong', 'frank@example.com', '555-2003', 'Warehouse', 'Operations', TIMESTAMP '2020-06-15', NULL, 40000.0, 0.0, 2, '606 Walnut Ln', NULL, 'Walnut', 'CA', '00345', 'USA', TIMESTAMP '1988-02-14', 'Male', 'Married', 1) +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO suppliers VALUES (1, 'Acme Inc', 'John D.', 'Sales Manager', 'john@acme.com', '555-3001', '555-3002', '123 Main St', NULL, NULL, 'Springfield', 'IL', '12345', 'USA', 'Midwest', 'Widgets, Gadgets', 'https://acme.com', TIMESTAMP '2020-01-01', NULL, TIMESTAMP '2023-01-10', 4.8, true) +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO suppliers VALUES (2, 'Widgets Co', 'Mary K.', 'Customer Success', 'mary@widgets.com', '555-4001', NULL, '456 Elm St', NULL, NULL, 'Oakville', 'CA', '67890', 'USA', 'West', 'Gadgets, Toys', 'https://widgetsco.com', TIMESTAMP '2021-02-01', NULL, TIMESTAMP '2023-02-15', 4.6, true) +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO suppliers VALUES (3, 'Toy Supply', 'Ann T.', 'Director', 'ann@toysupply.com', '555-5001', NULL, '789 Oak St', NULL, NULL, 'Pineville', 'TX', '54321', 'USA', 'South', 'Toys, Games', 'https://toysupply.com', TIMESTAMP '2019-03-01', NULL, TIMESTAMP '2023-03-01', 4.4, true) +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_inventory_threshold INT DEFAULT 20; + DECLARE v_low_stock_products INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Stock error'); END; + main_block: BEGIN + DECLARE v_product_id INT; + DECLARE v_product_name STRING; + DECLARE v_supplier_id INT; + DECLARE v_action_taken STRING; + FOR product AS SELECT p.product_id, p.product_name, p.supplier_id, p.product_quantity FROM products p JOIN suppliers s ON p.supplier_id = s.supplier_id LIMIT 5 DO + SET v_product_id = product.product_id; + SET v_product_name = product.product_name; + SET v_supplier_id = product.supplier_id; + L1: BEGIN + CASE + WHEN product.product_quantity < v_inventory_threshold THEN + SET v_action_taken = 'Restock needed'; + SET v_low_stock_products = v_low_stock_products + 1; + INSERT INTO orders (order_id, customer_id, order_date, order_status, order_total, order_tax, order_discount, order_shipping) + VALUES (v_product_id * 1000, (SELECT MIN(customer_id) FROM customers), CURRENT_TIMESTAMP, 'Restock', (SELECT product_cost FROM products WHERE product_id = v_product_id) * 10, 0.0, 0.0, 0.0); + INSERT INTO order_items (order_item_id, order_id, product_id, item_quantity, item_price_per_unit, item_discount, item_tax, item_total) + VALUES (v_product_id * 100 + 1, v_product_id * 1000, v_product_id, 10, (SELECT product_cost FROM products WHERE product_id = v_product_id), 0.0, 0.0, (SELECT product_cost FROM products WHERE product_id = v_product_id) * 10); + ELSE + SET v_action_taken = 'Sufficient stock'; + END CASE; + BEGIN + DECLARE v_supplier_active BOOLEAN; + SET v_supplier_active = (SELECT supplier_active FROM suppliers WHERE supplier_id = v_supplier_id); + IF NOT v_supplier_active THEN + SET v_action_taken = CONCAT(v_action_taken, ' (Supplier inactive)'); + BEGIN + DECLARE v_temp_id INT; + SET v_temp_id = (SELECT COALESCE(MAX(supplier_id), 0) + 1 FROM suppliers); + INSERT INTO suppliers VALUES (v_temp_id, 'Temp Supplier', 'Temp Contact', 'Temp Role', 'temp@temp.com', '555-0000', NULL, 'Temp Address', NULL, NULL, 'Temp City', 'TX', '00000', 'USA', 'South', 'Temporary', 'http://temp.com', CURRENT_TIMESTAMP, NULL, CURRENT_TIMESTAMP, 3.0, true); + END; + END IF; + END; + END L1; + END FOR; + END main_block; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_city_count INT; + DECLARE v_state_count INT; + DECLARE v_city_shortage_found BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Geo error'); END; + city_loop: FOR city AS SELECT DISTINCT customer_city FROM customers LIMIT 3 DO + SET v_city_count = (SELECT COUNT(*) FROM customers WHERE customer_city = city.customer_city); + state_scope: BEGIN + DECLARE v_state STRING; + SET v_state = (SELECT MAX(customer_state) FROM customers WHERE customer_city = city.customer_city); + IF v_state IS NOT NULL THEN + SET v_state_count = (SELECT COUNT(*) FROM customers WHERE customer_state = v_state); + L1: BEGIN + DECLARE v_region_ok BOOLEAN DEFAULT true; + FOR region AS SELECT DISTINCT supplier_region FROM suppliers LIMIT 1 DO + IF region.supplier_region IS NULL THEN + SET v_region_ok = false; + END IF; + END FOR; + IF NOT v_region_ok THEN + SET v_city_shortage_found = true; + END IF; + END L1; + END IF; + END state_scope; + BEGIN + DECLARE v_employee_id INT; + SET v_employee_id = (SELECT MIN(employee_id) FROM employees); + IF v_city_count < 2 AND NOT v_city_shortage_found THEN + BEGIN + DECLARE v_new_customer_id INT; + SET v_new_customer_id = (SELECT COALESCE(MAX(customer_id), 0) + 1 FROM customers); + INSERT INTO customers VALUES (v_new_customer_id, 'New Customer', 'new@customer.com', '555-1111', '555 Place', city.customer_city, (SELECT DISTINCT customer_state FROM customers WHERE customer_city = city.customer_city LIMIT 1), '00000', 'USA', 'Retail', CURRENT_TIMESTAMP, 0.0, NULL, NULL, NULL, true, true, 0.0, NULL, NULL); + END; + END IF; + WHILE v_employee_id < 3 DO + SET v_employee_id = v_employee_id + 1; + BEGIN + DECLARE v_customer_address STRING; + SET v_customer_address = (SELECT customer_address_1 FROM customers WHERE customer_city = city.customer_city LIMIT 1); + IF v_customer_address IS NULL THEN + SET v_customer_address = 'Unknown'; + END IF; + END; + END WHILE; + END; + END FOR city_loop; +END +-- !query schema +struct +-- !query output +Geo error + + +-- !query +BEGIN + DECLARE v_total_orders INT; + DECLARE v_customer_id INT; + DECLARE v_order_id INT; + DECLARE v_last_order_date TIMESTAMP; + DECLARE v_product_count INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Orders processing error'); END; + customer_block: BEGIN + DECLARE v_customer_threshold INT DEFAULT 2; + FOR cust AS SELECT customer_id, customer_name FROM customers LIMIT 5 DO + SET v_customer_id = cust.customer_id; + SET v_total_orders = (SELECT COUNT(*) FROM orders WHERE customer_id = cust.customer_id); + SET v_last_order_date = (SELECT MAX(order_date) FROM orders WHERE customer_id = cust.customer_id); + IF v_total_orders < v_customer_threshold THEN + SET v_order_id = (SELECT COALESCE(MAX(order_id), 0) + 1 FROM orders); + INSERT INTO orders (order_id, customer_id, order_date, order_status, order_total, order_tax, order_discount, order_shipping) + VALUES (v_order_id, v_customer_id, CURRENT_TIMESTAMP, 'New', 10.0, 1.0, 0.0, 2.0); + L1: BEGIN + DECLARE v_item_id INT; + SET v_product_count = (SELECT COUNT(*) FROM products); + IF v_product_count > 0 THEN + FOR prod AS SELECT product_id FROM products LIMIT 3 DO + SET v_item_id = (SELECT COALESCE(MAX(order_item_id), 0) + 1 FROM order_items); + INSERT INTO order_items (order_item_id, order_id, product_id, item_quantity, item_price_per_unit, item_discount, item_tax, item_total) + VALUES (v_item_id, v_order_id, prod.product_id, 1, (SELECT product_price FROM products WHERE product_id = prod.product_id), 0.0, 0.0, (SELECT product_price FROM products WHERE product_id = prod.product_id)); + END FOR; + END IF; + END L1; + ELSE + L2: BEGIN + DECLARE v_days_since_last_order INT; + SET v_days_since_last_order = DATEDIFF(DAY, v_last_order_date, CURRENT_TIMESTAMP); + IF v_days_since_last_order > 30 THEN + L3: BEGIN + DECLARE v_random_product_id INT; + SET v_random_product_id = (SELECT product_id FROM products LIMIT 1); + INSERT INTO order_items (order_item_id, order_id, product_id, item_quantity, item_price_per_unit, item_discount, item_tax, item_total) + VALUES ((SELECT COALESCE(MAX(order_item_id), 0) + 1 FROM order_items), (SELECT MIN(order_id) FROM orders WHERE customer_id = v_customer_id), v_random_product_id, 1, (SELECT product_price FROM products WHERE product_id = v_random_product_id), 0.0, 0.0, (SELECT product_price FROM products WHERE product_id = v_random_product_id)); + END L3; + SET v_last_order_date = CURRENT_TIMESTAMP; + ELSE + BEGIN + DECLARE v_orders_to_delete INT; + SET v_orders_to_delete = (SELECT COUNT(*) FROM orders WHERE order_status = 'Processing' AND customer_id = v_customer_id); + WHILE v_orders_to_delete > 1 DO + DELETE FROM orders WHERE order_id IN (SELECT order_id FROM orders WHERE order_status = 'Processing' AND customer_id = v_customer_id LIMIT 1); + SET v_orders_to_delete = v_orders_to_delete - 1; + END WHILE; + END; + END IF; + END L2; + END IF; + END FOR; + END customer_block; + BEGIN + DECLARE v_max_order_total DOUBLE; + SET v_max_order_total = (SELECT MAX(order_total) FROM orders); + IF v_max_order_total > 200 THEN + L4: BEGIN + DECLARE v_large_orders INT; + SET v_large_orders = (SELECT COUNT(*) FROM orders WHERE order_total > 200); + IF v_large_orders > 1 THEN + REPEAT + UPDATE orders SET order_shipping = order_shipping * 0.9 WHERE order_status = 'Completed' AND order_total > 200; + SET v_large_orders = (SELECT COUNT(*) FROM orders WHERE order_total > 200); + UNTIL v_large_orders < 2 END REPEAT; + END IF; + END L4; + END IF; + END; +END +-- !query schema +struct +-- !query output +Orders processing error + + +-- !query +BEGIN + DECLARE v_first_name STRING; + DECLARE v_last_name STRING; + DECLARE v_employee_name STRING; + DECLARE v_is_manager BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Employee processing error'); END; + staff_scope: BEGIN + DECLARE v_emp_count INT DEFAULT 0; + DECLARE v_manager_id INT; + SET v_manager_id = (SELECT MIN(employee_id) FROM employees WHERE employee_position = 'Manager'); + FOR emp AS SELECT employee_id, employee_name, employee_position FROM employees LIMIT 4 DO + SET v_employee_name = emp.employee_name; + SET v_emp_count = v_emp_count + 1; + L1: BEGIN + DECLARE v_split_result ARRAY; + SET v_split_result = split(v_employee_name, ' '); + CASE v_split_result[0] + WHEN 'Dan' THEN SET v_is_manager = true; + ELSE SET v_is_manager = false; + END CASE; + IF v_is_manager AND v_emp_count > 1 THEN + L2: BEGIN + DECLARE v_subordinates INT; + SET v_subordinates = (SELECT COUNT(*) FROM employees WHERE employee_manager_id = emp.employee_id); + IF v_subordinates > 0 THEN + FOR sub_emp AS SELECT employee_id, employee_name FROM employees WHERE employee_manager_id = emp.employee_id LIMIT 2 DO + L3: BEGIN + DECLARE v_name_part STRING; + SET v_name_part = (SELECT CONCAT(split(sub_emp.employee_name, ' ')[0], '_', ROUND(RANDOM() * 100))); + INSERT INTO customers (customer_id, customer_name, customer_email, customer_phone, customer_address_1, customer_city, customer_state, customer_zip, customer_country, customer_active_status) + VALUES (sub_emp.employee_id + 9999, v_name_part, CONCAT(v_name_part, '@company.com'), '555-8888', '123 HR St', 'HQ City', 'CA', '00000', 'USA', true); + END L3; + END FOR; + END IF; + END L2; + ELSE + REPEAT + SET v_emp_count = v_emp_count + 1; + L4: BEGIN + DECLARE v_todays_date STRING; + SET v_todays_date = DATE_FORMAT(CURRENT_TIMESTAMP, 'yyyy-MM-dd'); + INSERT INTO suppliers (supplier_id, supplier_name, supplier_contact, supplier_contact_role, supplier_contact_email, supplier_contact_phone_1, supplier_address_1, supplier_city, supplier_state, supplier_zip, supplier_country, supplier_region, supplier_main_products, supplier_active) + VALUES (emp.employee_id + 10000, CONCAT('Emp_', emp.employee_id), emp.employee_name, 'Employee', CONCAT(emp.employee_name, '@temp.com'), '555-9999', '123 Emp St', 'Emp City', 'CA', '00001', 'USA', 'West', 'Misc', true); + END L4; + UNTIL v_emp_count > 3 END REPEAT; + END IF; + END L1; + END FOR; + END staff_scope; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_category STRING; + DECLARE v_total_reviews INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product review error'); END; + prod_category: BEGIN + DECLARE v_category_count INT; + SET v_category_count = (SELECT COUNT(DISTINCT product_category) FROM products); + FOR cat AS SELECT DISTINCT product_category FROM products LIMIT 3 DO + SET v_category = cat.product_category; + SET v_total_reviews = (SELECT SUM(product_reviews) FROM products WHERE product_category = cat.product_category); + IF v_total_reviews > 0 THEN + L1: BEGIN + DECLARE v_average_rating DOUBLE; + SET v_average_rating = (SELECT AVG(product_rating) FROM products WHERE product_category = cat.product_category); + BEGIN + DECLARE v_price_range DOUBLE; + SET v_price_range = (SELECT MAX(product_price) - MIN(product_price) FROM products WHERE product_category = cat.product_category); + IF v_average_rating > 4.5 AND v_price_range > 50 THEN + L2: BEGIN + DECLARE v_updated_products INT DEFAULT 0; + FOR prod AS SELECT product_id FROM products WHERE product_category = cat.product_category LIMIT 2 DO + UPDATE products SET product_price = product_price * 0.95, product_description = CONCAT('***Premium*** ', product_description) WHERE product_id = prod.product_id; + SET v_updated_products = v_updated_products + 1; + END FOR; + END L2; + ELSE + BEGIN + DECLARE v_new_product_id INT; + SET v_new_product_id = (SELECT COALESCE(MAX(product_id), 0) + 1 FROM products); + INSERT INTO products VALUES (v_new_product_id, 'New ' || v_category, v_category, 49.99, 39.99, 2, 'Widgets Co', 'Sales', '123 Widget St', 30, 'Black', 'Medium', 1.5, 'New arrival', 5.0, 0, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, true, 0.0, 0.19); + END; + END IF; + END; + END L1; + ELSE + L3: BEGIN + DECLARE v_fake_reviews INT DEFAULT 0; + REPEAT + UPDATE products SET product_reviews = product_reviews + 5, product_rating = LEAST(product_rating + 0.1, 5.0) WHERE product_category = cat.product_category AND product_reviews < 10; + SET v_fake_reviews = v_fake_reviews + 1; + UNTIL v_fake_reviews > 2 END REPEAT; + END L3; + END IF; + END FOR; + END prod_category; + BEGIN + DECLARE v_total_product_types INT; + SET v_total_product_types = (SELECT COUNT(DISTINCT product_name) FROM products); + IF v_total_product_types < 10 THEN + L4: BEGIN + DECLARE v_missing_color STRING; + SET v_missing_color = 'Red'; + IF NOT EXISTS (SELECT 1 FROM products WHERE product_color = v_missing_color) THEN + INSERT INTO products VALUES ((SELECT COALESCE(MAX(product_id), 0) + 1 FROM products), 'Rare ' || v_missing_color, 'Special', 99.99, 69.99, 1, 'Acme Inc', 'Sales', '123 Rare St', 2, v_missing_color, 'Unique', 2.0, 'Extremely rare', 5.0, 0, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, true, 0.0, 0.21); + END IF; + END L4; + END IF; + END; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_hq_state STRING DEFAULT 'CA'; + DECLARE v_regional_office_count INT DEFAULT 0; + DECLARE v_wrong_city_found BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Office location error'); END; + + main_office: BEGIN + DECLARE v_total_offices INT; + SET v_total_offices = (SELECT COUNT(DISTINCT customer_city) FROM customers); + FOR city AS SELECT DISTINCT customer_city FROM customers LIMIT 2 DO + SET v_wrong_city_found = true; + IF city.customer_city LIKE '%ville' THEN + SET v_wrong_city_found = false; + L1: BEGIN + DECLARE v_region_check BOOLEAN DEFAULT true; + FOR supplier_region AS SELECT supplier_region FROM suppliers WHERE supplier_region LIKE '%est%' LIMIT 1 DO + IF supplier_region IS NULL THEN + SET v_region_check = false; + END IF; + END FOR; + IF NOT v_region_check THEN + INSERT INTO suppliers ( + supplier_id, supplier_name, supplier_contact, supplier_contact_role, + supplier_contact_email, supplier_contact_phone_1, supplier_address_1, + supplier_city, supplier_state, supplier_zip, supplier_country, supplier_region + ) VALUES ( + (SELECT MAX(supplier_id) + 1 FROM suppliers), + 'Regional Supplier', + 'Regional Contact', + 'Regional Manager', + 'region@supplier.com', + '555-1212', + '123 Regional St', + city.customer_city, + 'CA', + '00001', + 'USA', + 'West' + ); + END IF; + END L1; + SET v_regional_office_count = v_regional_office_count + 1; + END IF; + END FOR; + END main_office; + BEGIN + DECLARE v_hq_exists BOOLEAN; + SET v_hq_exists = (SELECT COUNT(*) FROM suppliers WHERE supplier_state = v_hq_state); + IF NOT v_hq_exists OR v_wrong_city_found THEN + L2: BEGIN + DECLARE v_emp_in_city INT; + SET v_emp_in_city = (SELECT COUNT(*) FROM employees WHERE employee_state = v_hq_state AND employee_city LIKE '%town%'); + IF v_emp_in_city > 0 THEN + REPEAT + INSERT INTO suppliers ( + supplier_id, supplier_name, supplier_contact, supplier_contact_role, + supplier_contact_email, supplier_contact_phone_1, supplier_address_1, + supplier_city, supplier_state, supplier_zip, supplier_country, supplier_region, supplier_active + ) VALUES ( + (SELECT MAX(supplier_id) + 1 FROM suppliers), + 'Main Office Supplier', + 'HQ Contact', + 'HQ Manager', + 'hq@supplier.com', + '555-1111', + '123 Main St', + (SELECT employee_city FROM employees WHERE employee_state = v_hq_state LIMIT 1), + v_hq_state, + '00000', + 'USA', + 'HQ', + true + ); + SET v_hq_exists = (SELECT COUNT(*) FROM suppliers WHERE supplier_state = v_hq_state); + UNTIL v_hq_exists = 0 OR v_hq_exists > 2 END REPEAT; + END IF; + END L2; + END IF; + END; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_total_orders INT DEFAULT 0; + DECLARE v_order_counter INT DEFAULT 0; + DECLARE v_order_status_count INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order status analysis error'); END; + + BEGIN + DECLARE v_limit_orders INT DEFAULT 3; + FOR status AS SELECT DISTINCT order_status FROM orders LIMIT 2 DO + SET v_order_counter = (SELECT COUNT(*) FROM orders WHERE order_status = status.order_status); + IF v_order_counter > 0 THEN + L1: BEGIN + DECLARE v_avg_order_total DOUBLE; + SET v_avg_order_total = (SELECT AVG(order_total) FROM orders WHERE order_status = status.order_status); + IF v_avg_order_total > 100 THEN + L2: BEGIN + DECLARE v_order_tax_avg DOUBLE; + SET v_order_tax_avg = (SELECT AVG(order_tax) FROM orders WHERE order_status = status.order_status); + IF v_order_tax_avg > 10 THEN + REPEAT + UPDATE orders SET order_tax = order_tax * 0.95 WHERE order_status = status.order_status; + SET v_order_tax_avg = (SELECT AVG(order_tax) FROM orders WHERE order_status = status.order_status); + UNTIL v_order_tax_avg <= 10 END REPEAT; + END IF; + SET v_limit_orders = v_limit_orders + 1; + END L2; + ELSE + BEGIN + DECLARE v_new_order_id INT; + SET v_new_order_id = (SELECT COALESCE(MAX(order_id), 0) + 1 FROM orders); + INSERT INTO orders ( + order_id, customer_id, order_date, order_status, order_total, order_tax, order_discount, order_shipping + ) VALUES ( + v_new_order_id, + (SELECT MAX(customer_id) FROM customers), + CURRENT_TIMESTAMP, + status.order_status, + 100.0, + 10.0, + 0.0, + 2.0 + ); + SET v_limit_orders = v_limit_orders - 1; + END; + END IF; + END L1; + END IF; + SET v_order_status_count = v_order_status_count + 1; + END FOR; + WHILE v_order_status_count < 3 DO + BEGIN + DECLARE v_fake_status STRING; + SET v_fake_status = CONCAT('Fake_Status_', v_order_status_count); + INSERT INTO orders ( + order_id, customer_id, order_date, order_status, order_total, order_tax, order_discount, order_shipping + ) VALUES ( + (SELECT COALESCE(MAX(order_id), 0) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + v_fake_status, + 10.0, + 1.0, + 0.0, + 2.0 + ); + SET v_order_status_count = v_order_status_count + 1; + END; + END WHILE; + END; +END +-- !query schema +struct +-- !query output +Order status analysis error + + +-- !query +BEGIN + DECLARE v_supplier_id INT; + DECLARE v_supplier_active BOOLEAN; + DECLARE v_contact_orders INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier contact management error'); END; + + supplier_loop: FOR supplier AS SELECT supplier_id, supplier_active, supplier_contact FROM suppliers LIMIT 3 DO + SET v_supplier_id = supplier.supplier_id; + SET v_supplier_active = supplier.supplier_active; + IF v_supplier_active THEN + BEGIN + DECLARE v_contact_has_orders BOOLEAN DEFAULT false; + SET v_contact_orders = (SELECT COUNT(*) FROM products WHERE supplier_id = v_supplier_id); + IF v_contact_orders > 0 THEN + SET v_contact_has_orders = true; + L1: BEGIN + DECLARE v_new_product_id INT; + SET v_new_product_id = (SELECT COALESCE(MAX(product_id), 0) + 1 FROM products); + INSERT INTO products VALUES ( + v_new_product_id, + 'Supplementary Item', + 'Accessories', + 19.99, + 12.99, + v_supplier_id, + supplier.supplier_contact, + supplier.supplier_contact, + 'Extra St', + 10, + 'Black', + 'Medium', + 1.2, + 'Supplementary product', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + BEGIN + DECLARE v_days_since_last_order INT; + SET v_days_since_last_order = DATEDIFF(DAY, (SELECT MAX(product_launch_date) FROM products WHERE supplier_id = v_supplier_id), CURRENT_TIMESTAMP); + IF v_days_since_last_order > 30 THEN + L2: BEGIN + DECLARE v_temp_id INT; + REPEAT + SET v_temp_id = (SELECT MIN(supplier_id) FROM suppliers WHERE supplier_active = true AND supplier_id != v_supplier_id); + IF v_temp_id IS NOT NULL THEN + UPDATE products SET supplier_id = v_temp_id WHERE product_id = v_new_product_id; + END IF; + UNTIL v_temp_id IS NULL OR v_days_since_last_order < 20 END REPEAT; + END L2; + END IF; + END; + END L1; + ELSE + L3: BEGIN + DECLARE v_supplier_emails INT; + SET v_supplier_emails = (SELECT COUNT(*) FROM suppliers WHERE supplier_contact_email IS NOT NULL AND supplier_id = v_supplier_id); + IF v_supplier_emails = 0 THEN + BEGIN + DECLARE v_fake_email STRING; + SET v_fake_email = CONCAT(supplier.supplier_contact, '@fake.com'); + INSERT INTO customers ( + customer_id, customer_name, customer_email, customer_phone, + customer_address_1, customer_city, customer_state, customer_zip, + customer_country, customer_active_status + ) VALUES ( + v_supplier_id + 9000, + supplier.supplier_contact, + v_fake_email, + '555-7777', + '123 Fake St', + 'Fakeville', + 'CA', + '00000', + 'USA', + false + ); + END; + END IF; + END L3; + END IF; + BEGIN + DECLARE v_orders_with_supplier INT; + SET v_orders_with_supplier = (SELECT COUNT(*) FROM order_items oi JOIN products p ON oi.product_id = p.product_id WHERE p.supplier_id = v_supplier_id); + IF v_orders_with_supplier > 0 THEN + L4: BEGIN + DECLARE v_total_value DOUBLE; + SET v_total_value = (SELECT SUM(oi.item_total) FROM order_items oi JOIN products p ON oi.product_id = p.product_id WHERE p.supplier_id = v_supplier_id); + IF v_total_value > 200 THEN + BEGIN + DECLARE v_new_discount DOUBLE; + SET v_new_discount = CASE WHEN v_total_value < 500 THEN 0.05 ELSE 0.10 END; + UPDATE suppliers SET supplier_rating = supplier_rating + 0.1 WHERE supplier_id = v_supplier_id; + UPDATE products SET product_discount = product_discount + v_new_discount WHERE supplier_id = v_supplier_id; + END; + END IF; + END L4; + END IF; + END; + END; + ELSE + L5: BEGIN + DECLARE v_inactive_supplier_orders INT; + SET v_inactive_supplier_orders = (SELECT COUNT(*) FROM products p JOIN order_items oi ON p.product_id = oi.product_id WHERE p.supplier_id = v_supplier_id); + IF v_inactive_supplier_orders > 0 THEN + REPEAT + DELETE FROM order_items + WHERE order_item_id IN ( + SELECT oi.order_item_id + FROM order_items oi + JOIN products p ON oi.product_id = p.product_id + WHERE p.supplier_id = v_supplier_id + LIMIT 1 + ); + SET v_inactive_supplier_orders = v_inactive_supplier_orders - 1; + UNTIL v_inactive_supplier_orders = 0 END REPEAT; + END IF; + END L5; + END IF; + END FOR supplier_loop; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_employee_id INT; + DECLARE v_employee_commission DOUBLE; + DECLARE v_employee_total DOUBLE DEFAULT 0.0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Commission calculation error'); END; + + L0: BEGIN + DECLARE v_total_emp INT; + SET v_total_emp = (SELECT COUNT(*) FROM employees); + FOR emp AS SELECT employee_id, employee_commission FROM employees LIMIT 3 DO + SET v_employee_id = emp.employee_id; + SET v_employee_commission = emp.employee_commission; + L1: BEGIN + DECLARE v_order_count INT; + SET v_order_count = (SELECT COUNT(*) FROM orders WHERE customer_id = (SELECT MIN(customer_id) FROM customers)); + IF v_order_count > 0 THEN + L2: BEGIN + DECLARE v_commission_changed BOOLEAN DEFAULT false; + WHILE v_employee_commission > 0 AND v_employee_commission < 2000 DO + UPDATE employees SET employee_commission = employee_commission + 100.0 WHERE employee_id = v_employee_id; + SET v_employee_total = v_employee_total + 100.0; + SET v_employee_commission = (SELECT employee_commission FROM employees WHERE employee_id = v_employee_id); + SET v_commission_changed = true; + END WHILE; + IF v_commission_changed THEN + REPEAT + SET v_employee_total = v_employee_total - 50.0; + UPDATE employees SET employee_commission = employee_commission - 50.0 WHERE employee_id = v_employee_id; + UNTIL v_employee_total <= 1500 END REPEAT; + END IF; + END L2; + END IF; + END L1; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Commission calculation error + + +-- !query +BEGIN + DECLARE v_customer_category STRING; + DECLARE v_order_count INT DEFAULT 0; + DECLARE v_customer_total DOUBLE DEFAULT 0.0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Customer order calculation error'); END; + + customer_category_loop: FOR category AS SELECT DISTINCT customer_type FROM customers LIMIT 2 DO + SET v_customer_category = category.customer_type; + SET v_order_count = (SELECT COUNT(*) FROM orders o JOIN customers c ON o.customer_id = c.customer_id WHERE c.customer_type = v_customer_category); + IF v_order_count > 0 THEN + L1: BEGIN + DECLARE v_average_order DOUBLE; + SET v_average_order = (SELECT AVG(o.order_total) FROM orders o JOIN customers c ON o.customer_id = c.customer_id WHERE c.customer_type = v_customer_category); + L2: BEGIN + IF v_average_order > 100 THEN + SET v_customer_total = v_customer_total + v_average_order; + BEGIN + DECLARE v_order_limit INT DEFAULT 3; + FOR order_row AS SELECT o.order_id FROM orders o JOIN customers c ON o.customer_id = c.customer_id WHERE c.customer_type = v_customer_category LIMIT v_order_limit DO + BEGIN + DECLARE v_order_items_count INT; + SET v_order_items_count = (SELECT COUNT(*) FROM order_items WHERE order_id = order_row.order_id); + IF v_order_items_count < 1 THEN + BEGIN + REPEAT + INSERT INTO order_items (order_item_id, order_id, product_id, item_quantity, item_price_per_unit, item_discount, item_tax, item_total) + VALUES ((SELECT MAX(order_item_id) + 1 FROM order_items), order_row.order_id, (SELECT MIN(product_id) FROM products), 1, 10.0, 0.0, 1.0, 11.0); + SET v_order_items_count = v_order_items_count + 1; + UNTIL v_order_items_count >= 1 END REPEAT; + END; + END IF; + END; + END FOR; + END; + ELSE + L3: BEGIN + REPEAT + SET v_customer_total = v_customer_total + 10.0; + INSERT INTO orders (order_id, customer_id, order_date, order_status, order_total, order_tax, order_discount, order_shipping) + VALUES ((SELECT MAX(order_id) + 1 FROM orders), (SELECT MIN(customer_id) FROM customers WHERE customer_type = v_customer_category), CURRENT_TIMESTAMP, 'Low Value', 10.0, 1.0, 0.0, 2.0); + SET v_order_count = v_order_count + 1; + UNTIL v_customer_total > 100 END REPEAT; + END L3; + END IF; + END L2; + END L1; + END IF; + END FOR customer_category_loop; + L4: BEGIN + DECLARE v_min_orders INT DEFAULT 1; + IF v_order_count < v_min_orders THEN + BEGIN + DECLARE v_new_order_id INT; + SET v_new_order_id = (SELECT MAX(order_id) + 1 FROM orders); + INSERT INTO orders (order_id, customer_id, order_date, order_status, order_total, order_tax, order_discount, order_shipping) + VALUES (v_new_order_id, (SELECT MIN(customer_id) FROM customers), CURRENT_TIMESTAMP, 'Auto Insert', 15.0, 1.5, 0.0, 2.5); + END; + END IF; + END L4; +END +-- !query schema +struct +-- !query output +Customer order calculation error + + +-- !query +BEGIN + DECLARE v_max_manager_id INT DEFAULT 2; + DECLARE v_employee_count INT DEFAULT 0; + DECLARE v_department_levels INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Employee hierarchy error'); END; + + L0: BEGIN + DECLARE v_manager_exists BOOLEAN DEFAULT false; + WHILE v_manager_exists = false AND v_max_manager_id < 4 DO + SET v_manager_exists = (SELECT COUNT(*) > 0 FROM employees WHERE employee_manager_id = v_max_manager_id); + IF v_manager_exists THEN + L1: BEGIN + REPEAT + SET v_department_levels = v_department_levels + 1; + SET v_employee_count = (SELECT COUNT(*) FROM employees WHERE employee_manager_id = v_max_manager_id); + WHILE v_employee_count > 0 AND v_employee_count < 10 DO + BEGIN + DECLARE v_new_id INT; + SET v_new_id = (SELECT COALESCE(MAX(employee_id), 0) + 1 FROM employees); + INSERT INTO employees VALUES (v_new_id, 'New Emp ' || v_new_id, 'new' || v_new_id || '@company.com', '555-0000', 'Intern', 'Ops', CURRENT_TIMESTAMP, NULL, 30000.0, 0.0, v_max_manager_id, '123 New St', NULL, 'Newtown', 'CA', '00000', 'USA', CURRENT_TIMESTAMP, 'Male', 'Single', 0); + SET v_employee_count = v_employee_count + 1; + END; + END WHILE; + SET v_max_manager_id = v_max_manager_id + 1; + SET v_manager_exists = (SELECT COUNT(*) > 0 FROM employees WHERE employee_manager_id = v_max_manager_id); + UNTIL v_max_manager_id >= 4 OR v_department_levels > 2 END REPEAT; + END L1; + ELSE + BEGIN + DECLARE v_temp_id INT; + SET v_temp_id = v_max_manager_id + 1; + INSERT INTO employees VALUES (v_temp_id, 'Manager ' || v_temp_id, 'manager' || v_temp_id || '@company.com', '555-0000', 'Manager', 'HR', CURRENT_TIMESTAMP, NULL, 60000.0, 0.0, NULL, '123 Mgmt St', NULL, 'Newtown', 'CA', '00000', 'USA', CURRENT_TIMESTAMP, 'Male', 'Married', 1); + SET v_manager_exists = true; + SET v_max_manager_id = v_temp_id; + END; + END IF; + END WHILE; + END L0; + L2: BEGIN + DECLARE v_low_level_emp INT DEFAULT 0; + REPEAT + SET v_low_level_emp = v_low_level_emp + 1; + INSERT INTO employees VALUES (v_low_level_emp + 10, 'Temp Emp ' || v_low_level_emp, 'temp' || v_low_level_emp || '@company.com', '555-0000', 'Temp', 'Temp', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 20000.0, 0.0, NULL, '123 Temp St', NULL, 'Temp City', 'TX', '00000', 'USA', CURRENT_TIMESTAMP, 'Female', 'Single', 0); + UNTIL v_low_level_emp > 2 END REPEAT; + END L2; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_shipping_cost DOUBLE DEFAULT 0.0; + DECLARE v_shipping_city STRING; + DECLARE v_shipping_orders INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Shipping analysis error'); END; + + L0: BEGIN + DECLARE v_max_orders INT DEFAULT 3; + FOR city AS SELECT DISTINCT order_shipping_city FROM orders LIMIT 2 DO + SET v_shipping_city = city.order_shipping_city; + SET v_shipping_cost = (SELECT SUM(order_shipping) FROM orders WHERE order_shipping_city = v_shipping_city); + IF v_shipping_cost > 5 THEN + L1: BEGIN + REPEAT + SET v_shipping_cost = v_shipping_cost - 1.0; + UPDATE orders SET order_shipping = order_shipping - 0.5 WHERE order_shipping_city = v_shipping_city; + UNTIL v_shipping_cost < 5 END REPEAT; + END L1; + BEGIN + DECLARE v_customer_in_shipping_city INT; + SET v_customer_in_shipping_city = (SELECT COUNT(*) FROM customers c WHERE c.customer_city = v_shipping_city); + IF v_customer_in_shipping_city = 0 THEN + BEGIN + DECLARE v_new_customer_id INT; + SET v_new_customer_id = (SELECT MAX(customer_id) + 1 FROM customers); + INSERT INTO customers VALUES ( + v_new_customer_id, + 'Local Customer', + 'local@' || v_shipping_city || '.com', + '555-0000', + '123 Main St', + v_shipping_city, + (SELECT DISTINCT order_shipping_state FROM orders WHERE order_shipping_city = v_shipping_city LIMIT 1), + '00000', + 'USA', + 'Retail', + CURRENT_TIMESTAMP, 0.0, NULL, NULL, NULL, true, true, 0.0, NULL, NULL + ); + END; + END IF; + END; + ELSE + L2: BEGIN + SET v_shipment_orders = (SELECT COUNT(*) FROM orders WHERE order_shipping_city = v_shipping_city); + WHILE v_shipping_orders < v_max_orders DO + BEGIN + DECLARE v_new_order_id INT; + SET v_new_order_id = (SELECT MAX(order_id) + 1 FROM orders); + INSERT INTO orders ( + order_id, customer_id, order_date, order_status, order_total, + order_tax, order_discount, order_shipping, order_shipping_city, + order_shipping_state, order_shipping_zip, order_shipping_country + ) VALUES ( + v_new_order_id, + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, 'Local Insert', 10.0, 1.0, 0.0, 2.0, + v_shipping_city, 'TX', '00000', 'USA' + ); + SET v_shipping_orders = v_shipping_orders + 1; + END; + END WHILE; + END L2; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Shipping analysis error + + +-- !query +BEGIN + DECLARE v_supplier_contact_count INT DEFAULT 0; + DECLARE v_supplier_rating_change DOUBLE DEFAULT 0.0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier contact error'); END; + + L0: BEGIN + DECLARE v_supplier_count INT; + SET v_supplier_count = (SELECT COUNT(*) FROM suppliers WHERE supplier_active = true); + FOR supplier AS SELECT supplier_id, supplier_contact, supplier_rating FROM suppliers WHERE supplier_active = true LIMIT 2 DO + SET v_supplier_contact_count = v_supplier_contact_count + 1; + L1: BEGIN + DECLARE v_supplier_orders INT; + SET v_supplier_orders = (SELECT COUNT(*) FROM products p JOIN order_items oi ON p.product_id = oi.product_id WHERE p.supplier_id = supplier.supplier_id); + IF v_supplier_orders > 0 THEN + L2: BEGIN + SET v_supplier_rating_change = 0.1; + REPEAT + SET v_supplier_rating_change = v_supplier_rating_change - 0.01; + UPDATE suppliers SET supplier_rating = supplier_rating + v_supplier_rating_change WHERE supplier_id = supplier.supplier_id; + UNTIL v_supplier_rating_change <= 0.0 END REPEAT; + END L2; + ELSE + BEGIN + DECLARE v_new_product_id INT; + SET v_new_product_id = (SELECT MAX(product_id) + 1 FROM products); + INSERT INTO products VALUES ( + v_new_product_id, + 'New Supplier Product', + 'General', + 39.99, + 29.99, + supplier.supplier_id, + supplier.supplier_contact, + supplier.supplier_contact, + '123 New St', + 5, + 'Blue', + 'M', + 0.9, + 'New supplier item', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + WHILE supplier.supplier_rating < 4.5 DO + UPDATE suppliers SET supplier_rating = supplier_rating + 0.1 WHERE supplier_id = supplier.supplier_id; + SET supplier.supplier_rating = (SELECT MAX(supplier_rating) FROM suppliers WHERE supplier_id = supplier.supplier_id); + END WHILE; + END; + END IF; + END L1; + END FOR; + END L0; + BEGIN + DECLARE v_few_contacts BOOLEAN DEFAULT false; + SET v_few_contacts = (v_supplier_contact_count < 2); + IF v_few_contacts THEN + L3: BEGIN + DECLARE v_new_contact_id INT; + SET v_new_contact_id = (SELECT MAX(supplier_id) + 1 FROM suppliers); + INSERT INTO suppliers VALUES ( + v_new_contact_id, + 'Supplier for Contact', + 'Contact', + 'Contact', + 'contact@supplier.com', + '555-0000', + '123 Contact St', + 'Contact City', + 'CA', + '00000', + 'USA', + 'West', + 'Contacts only', + true + ); + SET v_supplier_contact_count = v_supplier_contact_count + 1; + END L3; + END IF; + END; +END +-- !query schema +struct +-- !query output +Supplier contact error + + +-- !query +BEGIN + DECLARE v_employee_hire_year INT; + DECLARE v_employee_tenure_years INT; + DECLARE v_salary_bin INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Tenure analysis error'); END; + + L0: BEGIN + DECLARE v_emp_count INT DEFAULT 0; + FOR emp AS SELECT employee_id, employee_hire_date, employee_salary FROM employees LIMIT 3 DO + SET v_employee_hire_year = YEAR(emp.employee_hire_date); + SET v_employee_tenure_years = DATEDIFF(YEAR, emp.employee_hire_date, CURRENT_TIMESTAMP); + SET v_salary_bin = FLOOR(emp.employee_salary / 20000.0) + 1; + IF v_employee_tenure_years > 1 AND v_employee_tenure_years <= 7 THEN + L1: BEGIN + CASE v_salary_bin + WHEN 1 THEN + UPDATE employees SET employee_salary = employee_salary * 1.1 WHERE employee_id = emp.employee_id; + WHEN 2 THEN + BEGIN + REPEAT + SET v_salary_bin = v_salary_bin + 1; + SET v_emp_count = v_emp_count + 1; + UPDATE employees SET employee_commission = employee_commission * 1.05 WHERE employee_id = emp.employee_id; + UNTIL v_salary_bin > 3 OR v_emp_count > 2 END REPEAT; + END; + ELSE + L2: BEGIN + DECLARE v_hire_month INT; + SET v_hire_month = MONTH(emp.employee_hire_date); + IF v_hire_month % 2 = 0 THEN + BEGIN + SET v_hire_month = v_hire_month + 1; + UPDATE employees SET employee_salary = employee_salary * 0.95 WHERE employee_id = emp.employee_id; + END; + END IF; + END L2; + END CASE; + END L1; + SET v_emp_count = v_emp_count + 1; + ELSE + L3: BEGIN + DECLARE v_year_diff INT; + SET v_year_diff = (SELECT DATEDIFF(YEAR, MIN(employee_hire_date), CURRENT_TIMESTAMP) FROM employees); + WHILE v_year_diff > 5 DO + SET v_year_diff = v_year_diff - 1; + INSERT INTO employees VALUES ( + (SELECT MAX(employee_id) + 1 FROM employees), + 'Tenure Fill ' || v_year_diff, + 'tenure' || v_year_diff || '@company.com', + '555-0000', + 'Tenure', + 'Tenure', + CURRENT_TIMESTAMP, + NULL, + 35000.0, + 0.0, + NULL, + '123 Tenure St', + NULL, + 'Tenureville', + 'CA', + '00000', + 'USA', + CURRENT_TIMESTAMP, + 'Male', + 'Single', + 0 + ); + END WHILE; + END L3; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Tenure analysis error + + +-- !query +BEGIN + DECLARE v_order_source STRING; + DECLARE v_order_total DOUBLE; + DECLARE v_order_date TIMESTAMP; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order source analysis error'); END; + + L0: BEGIN + DECLARE v_order_source_count INT DEFAULT 0; + FOR source AS SELECT DISTINCT order_source FROM orders LIMIT 2 DO + SET v_order_source = source.order_source; + SET v_order_total = (SELECT SUM(order_total) FROM orders WHERE order_source = source.order_source); + IF v_order_source = 'Web' OR v_order_source = 'Mobile' THEN + L1: BEGIN + REPEAT + SET v_order_source_count = v_order_source_count + 1; + SET v_order_date = (SELECT MAX(order_date) FROM orders WHERE order_source = source.order_source); + IF v_order_date < DATEADD(DAY, -30, CURRENT_TIMESTAMP) THEN + BEGIN + INSERT INTO orders ( + order_id, customer_id, order_date, order_status, order_total, + order_tax, order_discount, order_shipping, order_source + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Recent Web', + 50.0, + 5.0, + 0.0, + 5.0, + source.order_source + ); + SET v_order_date = CURRENT_TIMESTAMP; + END; + END IF; + UNTIL v_order_source_count > 1 OR v_order_date > DATEADD(DAY, -30, CURRENT_TIMESTAMP) END REPEAT; + END L1; + ELSE + BEGIN + DECLARE v_fake_source STRING DEFAULT CONCAT('Fake ', source.order_source); + INSERT INTO orders ( + order_id, customer_id, order_date, order_status, order_total, + order_tax, order_discount, order_shipping, order_source + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Generated', + 30.0, + 3.0, + 0.0, + 3.0, + v_fake_source + ); + END; + END IF; + END FOR; + END L0; + BEGIN + DECLARE v_source_total DOUBLE; + SET v_source_total = (SELECT SUM(order_total) FROM orders WHERE order_source LIKE 'Fake%'); + IF v_source_total < 100 THEN + REPEAT + INSERT INTO orders ( + order_id, customer_id, order_date, order_status, order_total, + order_tax, order_discount, order_shipping, order_source + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Fake Source', + 15.0, + 1.5, + 0.0, + 1.5, + 'Fake Source' + ); + SET v_source_total = (SELECT SUM(order_total) FROM orders WHERE order_source LIKE 'Fake%'); + UNTIL v_source_total >= 100 END REPEAT; + END IF; + END; +END +-- !query schema +struct +-- !query output +Order source analysis error + + +-- !query +BEGIN + DECLARE v_customer_active BOOLEAN; + DECLARE v_customer_lifetime_value DOUBLE DEFAULT 0.0; + DECLARE v_customer_order_count INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Customer profitability error'); END; + + L0: BEGIN + DECLARE v_target_value DOUBLE DEFAULT 500.0; + FOR cust AS SELECT customer_id, customer_active_status FROM customers LIMIT 3 DO + SET v_customer_active = cust.customer_active_status; + SET v_customer_lifetime_value = (SELECT SUM(order_total) FROM orders WHERE customer_id = cust.customer_id); + SET v_customer_order_count = (SELECT COUNT(*) FROM orders WHERE customer_id = cust.customer_id); + IF v_customer_active = true AND v_customer_lifetime_value > 0.0 THEN + L1: BEGIN + IF v_customer_lifetime_value < v_target_value THEN + L2: BEGIN + REPEAT + INSERT INTO orders ( + order_id, customer_id, order_date, order_status, + order_total, order_tax, order_discount, order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + cust.customer_id, + CURRENT_TIMESTAMP, + 'LTV Boost', + 40.0, + 4.0, + 0.0, + 4.0 + ); + SET v_customer_lifetime_value = (SELECT SUM(order_total) FROM orders WHERE customer_id = cust.customer_id); + UNTIL v_customer_lifetime_value >= v_target_value OR v_customer_order_count > 5 END REPEAT; + END L2; + END IF; + BEGIN + DECLARE v_discount_to_apply DOUBLE; + CASE v_customer_order_count + WHEN 1 THEN SET v_discount_to_apply = 0.10; + WHEN 2 THEN SET v_discount_to_apply = 0.05; + ELSE SET v_discount_to_apply = 0.0; + END CASE; + IF v_discount_to_apply > 0 THEN + L3: BEGIN + REPEAT + UPDATE customers SET customer_discount_percentage = v_discount_to_apply WHERE customer_id = cust.customer_id; + SET v_discount_to_apply = v_discount_to_apply - 0.01; + UNTIL v_discount_to_apply <= 0.0 END REPEAT; + END L3; + END IF; + END; + END L1; + ELSE + BEGIN + DECLARE v_inactive_customer_count INT; + SET v_inactive_customer_count = (SELECT COUNT(*) FROM customers WHERE customer_active_status = false); + IF v_inactive_customer_count > 0 THEN + L4: BEGIN + WHILE v_inactive_customer_count > 0 AND v_customer_lifetime_value < 200 DO + SET v_inactive_customer_count = v_inactive_customer_count - 1; + INSERT INTO orders ( + order_id, customer_id, order_date, order_status, + order_total, order_tax, order_discount, order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers WHERE customer_active_status = false), + CURRENT_TIMESTAMP, + 'Reactivation', + 20.0, + 2.0, + 0.0, + 2.0 + ); + SET v_customer_lifetime_value = (SELECT SUM(order_total) FROM orders WHERE customer_id = cust.customer_id); + END WHILE; + END L4; + END IF; + END; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Customer profitability error + + +-- !query +BEGIN + DECLARE v_supplier_region_count INT DEFAULT 0; + DECLARE v_supplier_rating_change DOUBLE DEFAULT 0.0; + DECLARE v_region_to_boost STRING; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier region analysis error'); END; + + L0: BEGIN + DECLARE v_min_supplier_count INT DEFAULT 2; + FOR region AS SELECT DISTINCT supplier_region FROM suppliers LIMIT 2 DO + SET v_region_to_boost = region.supplier_region; + SET v_supplier_region_count = (SELECT COUNT(*) FROM suppliers WHERE supplier_region = v_region_to_boost); + IF v_supplier_region_count > v_min_supplier_count THEN + L1: BEGIN + REPEAT + SET v_supplier_rating_change = 0.05; + REPEAT + UPDATE suppliers SET supplier_rating = supplier_rating + v_supplier_rating_change WHERE supplier_region = v_region_to_boost; + SET v_supplier_rating_change = v_supplier_rating_change - 0.01; + UNTIL v_supplier_rating_change <= 0.0 END REPEAT; + SET v_min_supplier_count = v_min_supplier_count + 1; + UNTIL v_min_supplier_count > 4 END REPEAT; + END L1; + BEGIN + DECLARE v_products_in_region INT; + SET v_products_in_region = (SELECT COUNT(*) FROM products p JOIN suppliers s ON p.supplier_id = s.supplier_id WHERE s.supplier_region = v_region_to_boost); + IF v_products_in_region < 3 THEN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Region Product', + 'General', + 39.99, + 29.99, + (SELECT MIN(supplier_id) FROM suppliers WHERE supplier_region = v_region_to_boost), + 'Region Contact', + 'Region Role', + '123 Main St', + 10, + 'Blue', + 'M', + 1.0, + 'Region product', + 3.5, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + UNTIL (SELECT COUNT(*) FROM products p JOIN suppliers s ON p.supplier_id = s.supplier_id WHERE s.supplier_region = v_region_to_boost) >= 3 END REPEAT; + END IF; + END; + ELSE + L2: BEGIN + DECLARE v_new_supplier_id INT; + SET v_new_supplier_id = (SELECT MAX(supplier_id) + 1 FROM suppliers); + INSERT INTO suppliers VALUES ( + v_new_supplier_id, + 'Region ' || v_region_to_boost, + 'Regional Contact', + 'Regional Contact', + 'contact@regional.com', + '555-0000', + '123 Regional St', + 'Regional City', + 'CA', + '00000', + 'USA', + v_region_to_boost, + 'Regional', + true + ); + SET v_supplier_region_count = v_supplier_region_count + 1; + END L2; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Supplier region analysis error + + +-- !query +BEGIN + DECLARE v_employee_birth_year INT; + DECLARE v_employee_age INT; + DECLARE v_employee_city STRING; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Employee demographics error'); END; + + L0: BEGIN + DECLARE v_emp_count INT DEFAULT 0; + FOR emp AS SELECT employee_id, employee_birth_date, employee_city FROM employees LIMIT 3 DO + SET v_employee_birth_year = YEAR(emp.employee_birth_date); + SET v_employee_age = DATEDIFF(YEAR, emp.employee_birth_date, CURRENT_TIMESTAMP); + SET v_employee_city = emp.employee_city; + IF v_employee_age < 30 THEN + L1: BEGIN + DECLARE v_city_emp_count INT; + SET v_city_emp_count = (SELECT COUNT(*) FROM employees WHERE employee_city = v_employee_city); + IF v_city_emp_count < 2 THEN + REPEAT + SET v_emp_count = v_emp_count + 1; + INSERT INTO employees VALUES ( + (SELECT MAX(employee_id) + 1 FROM employees), + 'Young Emp ' || v_emp_count, + 'emp' || v_emp_count || '@company.com', + '555-0000', + 'Junior', + 'Ops', + CURRENT_TIMESTAMP, + NULL, + 35000.0, + 0.0, + NULL, + '123 Jun St', + NULL, + v_employee_city, + (SELECT DISTINCT employee_state FROM employees WHERE employee_city = v_employee_city LIMIT 1), + '00000', + 'USA', + DATEADD(YEAR, -(FLOOR(RAND() * 10) + 20), CURRENT_TIMESTAMP), + 'Male', + 'Single', + 0 + ); + UNTIL v_emp_count > 1 END REPEAT; + END IF; + END L1; + ELSE + BEGIN + DECLARE v_birth_month INT; + SET v_birth_month = MONTH(emp.employee_birth_date); + CASE v_birth_month + WHEN 1 THEN + UPDATE employees SET employee_commission = employee_commission + 100.0 WHERE employee_id = emp.employee_id; + WHEN 6 THEN + BEGIN + WHILE v_employee_age < 40 DO + SET v_employee_age = v_employee_age + 1; + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Age Group Customer', + 'age@group.com', + '555-0001', + '123 Age St', + v_employee_city, + (SELECT DISTINCT employee_state FROM employees WHERE employee_city = v_employee_city LIMIT 1), + '00000', + 'USA', + 'Senior', + CURRENT_TIMESTAMP, + 0.0, + NULL, + NULL, + NULL, + true, + true, + 0.0, + NULL, + NULL + ); + END WHILE; + END; + ELSE + L2: BEGIN + DECLARE v_new_birth_year INT; + SET v_new_birth_year = v_employee_birth_year - (FLOOR(RAND() * 5) + 1); + INSERT INTO employees VALUES ( + (SELECT MAX(employee_id) + 1 FROM employees), + 'Filler Emp', + 'filler@company.com', + '555-0000', + 'Filler', + 'Ops', + CURRENT_TIMESTAMP, + NULL, + 30000.0, + 0.0, + NULL, + '123 Filler St', + NULL, + v_employee_city, + (SELECT DISTINCT employee_state FROM employees WHERE employee_city = v_employee_city LIMIT 1), + '00000', + 'USA', + MAKE_DATE(v_new_birth_year, MONTH(CURRENT_TIMESTAMP), DAY(CURRENT_TIMESTAMP)), + 'Female', + 'Single', + 0 + ); + END L2; + END CASE; + END; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Employee demographics error + + +-- !query +BEGIN + DECLARE v_product_launch_year INT; + DECLARE v_active_product_count INT DEFAULT 0; + DECLARE v_new_composite_id INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product cohort error'); END; + + L0: BEGIN + FOR product AS SELECT product_id, product_launch_date, product_name, product_is_active FROM products LIMIT 3 DO + SET v_product_launch_year = YEAR(product.product_launch_date); + L1: BEGIN + IF product.product_is_active = true THEN + SET v_active_product_count = v_active_product_count + 1; + IF v_product_launch_year < 2023 THEN + L2: BEGIN + REPEAT + SET v_new_composite_id = product.product_id * 100 + (SELECT COUNT(*) FROM products WHERE YEAR(product_launch_date) = v_product_launch_year); + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total + ) VALUES ( + v_new_composite_id, + (SELECT MIN(order_id) FROM orders), + product.product_id, + 1, + (SELECT product_price FROM products WHERE product_id = product.product_id), + 0.0, + 0.0, + (SELECT product_price FROM products WHERE product_id = product.product_id) + ); + SET v_active_product_count = v_active_product_count - 1; + UNTIL v_active_product_count < 1 END REPEAT; + END L2; + END IF; + ELSE + BEGIN + DECLARE v_launch_month INT; + SET v_launch_month = MONTH(product.product_launch_date); + WHILE v_launch_month < 12 DO + SET v_launch_month = v_launch_month + 1; + BEGIN + DECLARE v_new_product_id INT; + SET v_new_product_id = (SELECT MAX(product_id) + 1 FROM products); + INSERT INTO products VALUES ( + v_new_product_id, + 'Covert ' || product.product_name, + 'Specialty', + 49.99, + 34.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Stealth Contact', + 'Cloaked Role', + '123 Cloak St', + 2, + 'Black', + 'Medium', + 1.1, + 'Hidden product', + 0.0, + 0, + MAKE_DATE(v_product_launch_year, v_launch_month, 1), + CURRENT_TIMESTAMP, + true, + 0.0, + 0.21 + ); + END; + END WHILE; + END; + END IF; + END L1; + END FOR; + END L0; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_product_cost_change DOUBLE DEFAULT 0.0; + DECLARE v_last_update_days INT; + DECLARE v_product_is_active BOOLEAN; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Cost adjustment error'); END; + + L0: BEGIN + FOR product AS SELECT product_id, product_cost, product_last_update, product_is_active FROM products LIMIT 3 DO + SET v_last_update_days = DATEDIFF(DAY, product.product_last_update, CURRENT_TIMESTAMP); + SET v_product_is_active = product.product_is_active; + L1: BEGIN + IF v_product_is_active = true AND v_last_update_days > 60 THEN + L2: BEGIN + REPEAT + SET v_product_cost_change = v_product_cost_change + 0.05; + UPDATE products SET product_cost = product_cost * (1.0 + v_product_cost_change), product_last_update = CURRENT_TIMESTAMP WHERE product_id = product.product_id; + SET v_last_update_days = DATEDIFF(DAY, product.product_last_update, CURRENT_TIMESTAMP); + UNTIL v_product_cost_change > 0.15 OR v_last_update_days < 10 END REPEAT; + END L2; + ELSE + BEGIN + DECLARE v_min_cost DOUBLE; + SET v_min_cost = (SELECT MIN(product_cost) FROM products WHERE product_is_active = true); + IF v_min_cost > 10 THEN + L3: BEGIN + REPEAT + SET v_product_cost_change = v_product_cost_change - 0.02; + UPDATE products SET product_cost = product_cost * (1.0 + v_product_cost_change) WHERE product_id = product.product_id; + UNTIL v_product_cost_change < -0.10 OR (SELECT MIN(product_cost) FROM products WHERE product_is_active = true) <= 10 END REPEAT; + END L3; + END IF; + IF v_product_is_active = false THEN + BEGIN + DECLARE v_active_product_count INT; + SET v_active_product_count = (SELECT COUNT(*) FROM products WHERE product_is_active = true); + IF v_active_product_count < 5 THEN + UPDATE products SET product_is_active = true WHERE product_id = (SELECT MIN(product_id) FROM products WHERE product_is_active = false); + END IF; + END; + END IF; + END; + END IF; + END L1; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Cost adjustment error + + +-- !query +BEGIN + DECLARE v_order_shipping_cost DOUBLE; + DECLARE v_region STRING; + DECLARE v_region_shipping_changed BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Shipping region logic error'); END; + + L0: BEGIN + DECLARE v_order_limit INT DEFAULT 3; + FOR region AS SELECT DISTINCT order_shipping_region FROM orders LIMIT 2 DO + SET v_region = region.order_shipping_region; + SET v_order_shipping_cost = (SELECT SUM(order_shipping) FROM orders WHERE order_shipping_region = v_region); + IF v_order_shipping_cost > 10 THEN + L1: BEGIN + REPEAT + SET v_order_shipping_cost = v_order_shipping_cost - 1.0; + SET v_region_shipping_changed = true; + UPDATE orders SET order_shipping = order_shipping - 0.5 WHERE order_shipping_region = v_region; + UNTIL v_order_shipping_cost < 10 END REPEAT; + END L1; + END IF; + BEGIN + IF v_region_shipping_changed THEN + L2: BEGIN + DECLARE v_supplier_in_region INT; + SET v_supplier_in_region = (SELECT COUNT(*) FROM suppliers WHERE supplier_region = v_region); + IF v_supplier_in_region = 0 THEN + INSERT INTO suppliers VALUES ( + (SELECT MAX(supplier_id) + 1 FROM suppliers), + 'Region Supplier', + 'Region Contact', + 'Region Manager', + 'region@supplier.com', + '555-0000', + '123 Region St', + 'Region City', + 'CA', + '00000', + 'USA', + v_region, + 'General', + true + ); + END IF; + END L2; + END IF; + END; + END FOR; + END L0; + BEGIN + DECLARE v_nonexistent_orders INT; + SET v_nonexistent_orders = (SELECT COUNT(*) FROM orders o LEFT JOIN customers c ON o.customer_id = c.customer_id WHERE c.customer_id IS NULL); + IF v_nonexistent_orders > 0 THEN + L3: BEGIN + WHILE v_nonexistent_orders > 0 DO + DELETE FROM orders WHERE order_id = (SELECT MIN(order_id) FROM orders o LEFT JOIN customers c ON o.customer_id = c.customer_id WHERE c.customer_id IS NULL); + SET v_nonexistent_orders = v_nonexistent_orders - 1; + END WHILE; + END L3; + END IF; + END; +END +-- !query schema +struct +-- !query output +Shipping region logic error + + +-- !query +BEGIN + DECLARE v_product_color STRING; + DECLARE v_color_count INT; + DECLARE v_max_price_flag BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product color error'); END; + + L0: BEGIN + DECLARE v_min_products_per_color INT DEFAULT 2; + FOR color AS SELECT DISTINCT product_color FROM products LIMIT 3 DO + SET v_product_color = color.product_color; + SET v_color_count = (SELECT COUNT(*) FROM products WHERE product_color = v_product_color); + IF v_color_count < v_min_products_per_color THEN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Extra ' || v_product_color, + 'Accessory', + 19.99, + 12.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Color Contact', + 'Color Role', + '123 Color St', + 5, + v_product_color, + 'Small', + 0.5, + 'Extra color', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_color_count = v_color_count + 1; + UNTIL v_color_count >= v_min_products_per_color END REPEAT; + END IF; + BEGIN + DECLARE v_max_color_price DOUBLE; + SET v_max_color_price = (SELECT MAX(product_price) FROM products WHERE product_color = v_product_color); + IF v_max_color_price > 100 THEN + SET v_max_price_flag = true; + UPDATE products SET product_price = product_price * 0.85 WHERE product_color = v_product_color AND product_price > 100; + END IF; + END; + IF v_max_price_flag THEN + BEGIN + DECLARE v_products_updated INT; + SET v_products_updated = (SELECT COUNT(*) FROM products WHERE product_color = v_product_color AND product_price < 50); + IF v_products_updated = 0 THEN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Low Price ' || v_product_color, + 'Budget', + 29.99, + 19.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Budget Contact', + 'Budget Role', + '123 Budget St', + 10, + v_product_color, + 'Medium', + 0.8, + 'Low price option', + 3.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.05, + 0.19 + ); + UNTIL (SELECT COUNT(*) FROM products WHERE product_color = v_product_color AND product_price < 50) > 0 END REPEAT; + END IF; + END; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Product color error + + +-- !query +BEGIN + DECLARE v_order_total_tax DOUBLE; + DECLARE v_order_date_month INT; + DECLARE v_status_changed BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order tax logic error'); END; + + L0: BEGIN + DECLARE v_min_tax_month DOUBLE DEFAULT 100.0; + FOR order_row AS SELECT order_id, order_total, order_tax, order_date, order_status FROM orders LIMIT 3 DO + SET v_order_total_tax = order_row.order_total + order_row.order_tax; + SET v_order_date_month = MONTH(order_row.order_date); + IF v_order_date_month % 2 = 0 THEN + L1: BEGIN + IF order_row.order_status = 'Completed' THEN + SET v_status_changed = true; + UPDATE orders SET order_status = 'Closed' WHERE order_id = order_row.order_id; + END IF; + BEGIN + DECLARE v_adj_tax DOUBLE; + SET v_adj_tax = order_row.order_tax * 1.1; + SET v_order_total_tax = v_order_total_tax + (v_adj_tax - order_row.order_tax); + UPDATE orders SET order_tax = v_adj_tax WHERE order_id = order_row.order_id; + IF v_order_total_tax > v_min_tax_month THEN + L2: BEGIN + REPEAT + SET v_min_tax_month = v_min_tax_month + 10.0; + UNTIL v_min_tax_month > v_order_total_tax END REPEAT; + END L2; + END IF; + END; + END L1; + ELSE + L3: BEGIN + DECLARE v_order_items_added INT DEFAULT 0; + WHILE v_order_items_added < 2 DO + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + order_row.order_id, + (SELECT MIN(product_id) FROM products), + 1, + 10.0, + 0.0, + 1.0, + 11.0 + ); + SET v_order_items_added = v_order_items_added + 1; + END WHILE; + END L3; + END IF; + END FOR; + END L0; + BEGIN + DECLARE v_completed_orders INT; + SET v_completed_orders = (SELECT COUNT(*) FROM orders WHERE order_status = 'Completed'); + IF v_completed_orders = 0 THEN + L4: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Completed', + 50.0, + 5.0, + 0.0, + 5.0 + ); + UNTIL (SELECT COUNT(*) FROM orders WHERE order_status = 'Completed') > 1 END REPEAT; + END L4; + END IF; + END; +END +-- !query schema +struct +-- !query output +Order tax logic error + + +-- !query +BEGIN + DECLARE v_product_size STRING; + DECLARE v_size_count INT; + DECLARE v_min_size_count INT DEFAULT 2; + DECLARE v_size_has_price_flag BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product size error'); END; + + L0: BEGIN + FOR size AS SELECT DISTINCT product_size FROM products LIMIT 3 DO + SET v_product_size = size.product_size; + SET v_size_count = (SELECT COUNT(*) FROM products WHERE product_size = v_product_size); + IF v_size_count < v_min_size_count THEN + L1: BEGIN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Extra ' || v_product_size, + 'General', + 24.99, + 15.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Size Contact', + 'Size Role', + '123 Size St', + 5, + 'Black', + v_product_size, + 0.6, + 'Extra ' || v_product_size || ' product', + 3.5, + 8, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_size_count = v_size_count + 1; + SET v_size_has_price_flag = true; + UNTIL v_size_count >= v_min_size_count END REPEAT; + END L1; + END IF; + IF v_size_has_price_flag THEN + BEGIN + DECLARE v_avg_size_price DOUBLE; + SET v_avg_size_price = (SELECT AVG(product_price) FROM products WHERE product_size = v_product_size); + IF v_avg_size_price > 30 THEN + REPEAT + UPDATE products SET product_discount = product_discount + 0.05 WHERE product_size = v_product_size AND product_discount < 0.15; + SET v_avg_size_price = (SELECT AVG(product_price) FROM products WHERE product_size = v_product_size); + UNTIL v_avg_size_price <= 30 END REPEAT; + END IF; + END; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Product size error + + +-- !query +BEGIN + DECLARE v_department STRING; + DECLARE v_dept_emp_count INT; + DECLARE v_dept_avg_salary DOUBLE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Department error'); END; + + L0: BEGIN + FOR dept AS SELECT DISTINCT employee_department FROM employees LIMIT 3 DO + SET v_department = dept.employee_department; +SET v_dept_emp_count = (SELECT COUNT(*) FROM employees WHERE employee_department = v_department); + SET v_dept_avg_salary = (SELECT AVG(employee_salary) FROM employees WHERE employee_department = v_department); + IF v_dept_emp_count < 2 THEN + L1: BEGIN + REPEAT + INSERT INTO employees VALUES ( + (SELECT MAX(employee_id) + 1 FROM employees), + v_department || ' Emp ' || v_dept_emp_count, + 'emp' || v_dept_emp_count || '@' || LOWER(v_department) || '.com', + '555-0000', + 'Member', + v_department, + CURRENT_TIMESTAMP, + NULL, + 35000.0, + 0.0, + NULL, + '123 Dept St', + NULL, + 'Dept City', + 'CA', + '00000', + 'USA', + CURRENT_TIMESTAMP, + 'Female', + 'Single', + 0 + ); + SET v_dept_emp_count = v_dept_emp_count + 1; + UNTIL v_dept_emp_count >= 2 END REPEAT; +END L1; +END IF; + IF v_dept_avg_salary > 40000 AND v_dept_emp_count >= 2 THEN +BEGIN + DECLARE v_salary_decrease DOUBLE; + SET v_salary_decrease = 0.95; + REPEAT +UPDATE employees SET employee_salary = employee_salary * v_salary_decrease WHERE employee_department = v_department; +SET v_dept_avg_salary = (SELECT AVG(employee_salary) FROM employees WHERE employee_department = v_department); + UNTIL v_dept_avg_salary <= 40000 END REPEAT; +END; + ELSEIF v_dept_avg_salary < 30000 AND v_dept_emp_count >= 2 THEN + REPEAT +UPDATE employees SET employee_salary = employee_salary * 1.05 WHERE employee_department = v_department AND employee_salary < 30000; +SET v_dept_avg_salary = (SELECT AVG(employee_salary) FROM employees WHERE employee_department = v_department); + UNTIL v_dept_avg_salary >= 30000 OR v_dept_avg_salary > 50000 END REPEAT; +END IF; +END FOR; +END L0; +END +-- !query schema +struct +-- !query output +Department error + + +-- !query +BEGIN + DECLARE v_product_rating DOUBLE; + DECLARE v_max_reviews INT DEFAULT 100; + DECLARE v_min_reviews_flag BOOLEAN DEFAULT true; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product review analysis error'); END; + + L0: BEGIN + FOR product AS SELECT product_id, product_rating, product_reviews FROM products LIMIT 3 DO + SET v_product_rating = product.product_rating; + IF product.product_reviews < 10 THEN + REPEAT + SET v_min_reviews_flag = true; + UPDATE products SET product_reviews = product_reviews + 5, product_rating = LEAST(product_rating + 0.1, 5.0) WHERE product_id = product.product_id; + UNTIL product.product_reviews >= 10 END REPEAT; + END IF; + BEGIN + IF v_min_reviews_flag = true AND v_product_rating < 4.5 THEN + REPEAT + SET v_product_rating = (SELECT product_rating FROM products WHERE product_id = product.product_id); + UPDATE products SET product_rating = product_rating + 0.1 WHERE product_id = product.product_id; + UNTIL (SELECT product_rating FROM products WHERE product_id = product.product_id) >= 4.5 END REPEAT; + END IF; + END; + IF product.product_rating > 4.5 AND product.product_reviews > v_max_reviews THEN + BEGIN + REPEAT + UPDATE products SET product_reviews = product_reviews + 1 WHERE product_id = product.product_id; + SET v_max_reviews = v_max_reviews + 1; + UNTIL product.product_reviews > v_max_reviews * 2 END REPEAT; + END; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Product review analysis error + + +-- !query +BEGIN + DECLARE v_order_shipping_city STRING; + DECLARE v_shipping_fee_min DOUBLE DEFAULT 2.0; + DECLARE v_order_volume INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('City shipping error'); END; + + L0: BEGIN + FOR city AS SELECT DISTINCT order_shipping_city FROM orders LIMIT 3 DO + SET v_order_shipping_city = city.order_shipping_city; + SET v_order_volume = (SELECT COUNT(*) FROM orders WHERE order_shipping_city = v_order_shipping_city); + IF v_order_volume > 1 THEN + L1: BEGIN + REPEAT + SET v_shipping_fee_min = v_shipping_fee_min + 0.1; + UPDATE orders SET order_shipping = order_shipping + 0.2 WHERE order_shipping_city = v_order_shipping_city AND order_shipping < v_shipping_fee_min; + UNTIL v_shipping_fee_min > 5.0 END REPEAT; + END L1; + BEGIN + DECLARE v_order_tax_avg DOUBLE; + SET v_order_tax_avg = (SELECT AVG(order_tax) FROM orders WHERE order_shipping_city = v_order_shipping_city); + IF v_order_tax_avg > 10 THEN + L2: BEGIN + REPEAT + SET v_order_tax_avg = v_order_tax_avg - 1.0; + UPDATE orders SET order_tax = order_tax * 0.9 WHERE order_shipping_city = v_order_shipping_city; + UNTIL v_order_tax_avg <= 10 END REPEAT; + END L2; + END IF; + END; + ELSE + L3: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping, + order_shipping_city + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Volume Insert', + 12.0, + 1.2, + 0.0, + 2.0, + v_order_shipping_city + ); + SET v_order_volume = (SELECT COUNT(*) FROM orders WHERE order_shipping_city = v_order_shipping_city); + UNTIL v_order_volume > 1 END REPEAT; + END L3; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +City shipping error + + +-- !query +BEGIN + DECLARE v_employee_salary DOUBLE; + DECLARE v_employee_manager_id INT; + DECLARE v_manager_has_subordinates BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Employee hierarchy error'); END; + + L0: BEGIN + FOR emp AS SELECT employee_id, employee_salary, employee_manager_id FROM employees LIMIT 3 DO + SET v_employee_salary = emp.employee_salary; + SET v_employee_manager_id = emp.employee_manager_id; + IF v_employee_manager_id IS NOT NULL THEN + L1: BEGIN + SET v_manager_has_subordinates = (SELECT COUNT(*) > 0 FROM employees WHERE employee_manager_id = v_employee_manager_id); + IF v_manager_has_subordinates THEN + L2: BEGIN + BEGIN + DECLARE v_min_salary DOUBLE DEFAULT 0.0; + SET v_min_salary = (SELECT MIN(employee_salary) FROM employees WHERE employee_manager_id = v_employee_manager_id); + WHILE v_min_salary < 30000 DO + UPDATE employees SET employee_salary = employee_salary + 1000.0 WHERE employee_id = emp.employee_id; + SET v_employee_salary = v_employee_salary + 1000.0; + SET v_min_salary = (SELECT MIN(employee_salary) FROM employees WHERE employee_manager_id = v_employee_manager_id); + END WHILE; + END; + END L2; + ELSE + L3: BEGIN + REPEAT + SET v_employee_salary = v_employee_salary * 1.01; + UPDATE employees SET employee_salary = v_employee_salary WHERE employee_id = emp.employee_id; + UNTIL (SELECT COUNT(*) FROM employees WHERE employee_manager_id = emp.employee_id) > 0 OR v_employee_salary > 50000 END REPEAT; + END L3; + END IF; + END L1; + ELSE + BEGIN + DECLARE v_lowest_salary DOUBLE; + SET v_lowest_salary = (SELECT MIN(employee_salary) FROM employees WHERE employee_manager_id IS NULL); + IF v_lowest_salary < 40000 THEN + REPEAT + INSERT INTO employees VALUES ( + (SELECT MAX(employee_id) + 1 FROM employees), + 'Subordinate_' || v_lowest_salary, + 'subord' || v_lowest_salary || '@company.com', + '555-0000', + 'Subordinate', + 'HR', + CURRENT_TIMESTAMP, + NULL, + 30000.0, + 0.0, + emp.employee_id, + '123 Sub St', + NULL, + 'Sub City', + 'CA', + '00000', + 'USA', + CURRENT_TIMESTAMP, + 'Male', + 'Single', + 0 + ); + SET v_manager_has_subordinates = (SELECT COUNT(*) > 0 FROM employees WHERE employee_manager_id = emp.employee_id); + UNTIL v_manager_has_subordinates OR v_lowest_salary > 35000 END REPEAT; + END IF; + END; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Employee hierarchy error + + +-- !query +BEGIN + DECLARE v_order_creation_date TIMESTAMP; + DECLARE v_order_status STRING; + DECLARE v_order_days_pending INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order backlog error'); END; + + L0: BEGIN + FOR order_row AS SELECT order_id, order_date, order_status FROM orders LIMIT 3 DO + SET v_order_creation_date = order_row.order_date; + SET v_order_status = order_row.order_status; + SET v_order_days_pending = DATEDIFF(DAY, v_order_creation_date, CURRENT_TIMESTAMP); + IF v_order_days_pending > 5 AND v_order_status = 'Processing' THEN + L1: BEGIN + REPEAT + UPDATE orders SET order_status = 'Pending', order_shipping = order_shipping + 1.0 WHERE order_id = order_row.order_id; + SET v_order_creation_date = (SELECT order_date FROM orders WHERE order_id = order_row.order_id); + SET v_order_days_pending = DATEDIFF(DAY, v_order_creation_date, CURRENT_TIMESTAMP); + UNTIL v_order_days_pending < 3 END REPEAT; + END L1; + ELSEIF v_order_days_pending > 30 AND v_order_status = 'Pending' THEN + L2: BEGIN + WHILE v_order_days_pending > 10 DO + SET v_order_status = 'Cancelled'; + UPDATE orders SET order_status = v_order_status, order_shipping = 0.0 WHERE order_id = order_row.order_id; + SET v_order_days_pending = DATEDIFF(DAY, (SELECT order_date FROM orders WHERE order_id = order_row.order_id), CURRENT_TIMESTAMP); + END WHILE; + END L2; + ELSE + BEGIN + DECLARE v_backlog_order_count INT; + SET v_backlog_order_count = (SELECT COUNT(*) FROM orders WHERE order_status = 'Processing' AND DATEDIFF(DAY, order_date, CURRENT_TIMESTAMP) > 5); + IF v_backlog_order_count > 0 THEN + L3: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Escalated', + 20.0, + 2.0, + 0.0, + 0.0 + ); + SET v_backlog_order_count = v_backlog_order_count - 1; + UNTIL v_backlog_order_count = 0 END REPEAT; + END L3; + END IF; + END; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Order backlog error + + +-- !query +BEGIN + DECLARE v_order_item_id INT; + DECLARE v_order_item_status STRING; + DECLARE v_shipped_item_count INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order item error'); END; + + L0: BEGIN + FOR order_item AS SELECT order_item_id, item_status FROM order_items LIMIT 3 DO + SET v_order_item_id = order_item.order_item_id; + SET v_order_item_status = order_item.item_status; + IF v_order_item_status = 'Shipped' THEN + SET v_shipped_item_count = v_shipped_item_count + 1; + L1: BEGIN + DECLARE v_item_shipping_delay INT; + SET v_item_shipping_delay = (SELECT DATEDIFF(DAY, (SELECT item_shipping_date FROM order_items WHERE order_item_id = v_order_item_id), CURRENT_TIMESTAMP)); + IF v_item_shipping_delay > 7 THEN + REPEAT + UPDATE order_items SET item_discount = item_discount + 0.05 WHERE order_item_id = v_order_item_id; + SET v_item_shipping_delay = (SELECT DATEDIFF(DAY, (SELECT item_shipping_date FROM order_items WHERE order_item_id = v_order_item_id), CURRENT_TIMESTAMP)); + UNTIL v_item_shipping_delay < 4 END REPEAT; + END IF; + END L1; + END IF; + END FOR; + BEGIN + IF v_shipped_item_count < 1 THEN + L2: BEGIN + REPEAT + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total, + item_status, + item_shipping_date + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MIN(order_id) FROM orders), + (SELECT MIN(product_id) FROM products), + 1, + 10.0, + 0.0, + 1.0, + 11.0, + 'Shipped', + CAST(CURRENT_TIMESTAMP AS DATE) + ); + SET v_shipped_item_count = v_shipped_item_count + 1; + UNTIL v_shipped_item_count > 0 END REPEAT; + END L2; + END IF; + END; + END L0; +END +-- !query schema +struct +-- !query output +Order item error + + +-- !query +BEGIN + DECLARE v_supplier_contact_emails INT DEFAULT 0; + DECLARE v_active_supplier_count INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier contact error'); END; + + L0: BEGIN + FOR supplier AS SELECT supplier_id, supplier_active, supplier_contact_email FROM suppliers LIMIT 3 DO + IF supplier.supplier_active = true AND supplier.supplier_contact_email IS NOT NULL THEN + SET v_active_supplier_count = v_active_supplier_count + 1; + L1: BEGIN + REPEAT + SET v_supplier_contact_emails = v_supplier_contact_emails + 1; + UPDATE suppliers SET supplier_contact_email = 'new_' || supplier.supplier_contact_email WHERE supplier_id = supplier.supplier_id; + UNTIL v_supplier_contact_emails > 1 END REPEAT; + END L1; + L2: BEGIN + DECLARE v_supplier_products INT; + SET v_supplier_products = (SELECT COUNT(*) FROM products WHERE supplier_id = supplier.supplier_id); + IF v_supplier_products = 0 THEN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'New Supplier Item', + 'Specialty', + 35.99, + 25.99, + supplier.supplier_id, + 'New Contact', + 'New Role', + '123 New St', + 3, + 'Red', + 'Small', + 0.7, + 'New supplier item', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + UNTIL (SELECT COUNT(*) FROM products WHERE supplier_id = supplier.supplier_id) > 0 END REPEAT; + END IF; + END L2; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Supplier contact error + + +-- !query +BEGIN + DECLARE v_product_discount_avg DOUBLE; + DECLARE v_max_discount_products INT DEFAULT 2; + DECLARE v_discount_changed BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product price error'); END; + + L0: BEGIN + DECLARE v_discount_category STRING DEFAULT 'GENERAL'; + FOR category AS SELECT DISTINCT product_category FROM products LIMIT 2 DO + SET v_product_discount_avg = (SELECT AVG(product_discount) FROM products WHERE product_category = category.product_category); + IF v_product_discount_avg > 0.1 THEN + L1: BEGIN + REPEAT + SET v_product_discount_avg = v_product_discount_avg - 0.01; + UPDATE products SET product_discount = product_discount - 0.01 WHERE product_category = category.product_category; + SET v_discount_changed = true; + UNTIL v_product_discount_avg <= 0.1 END REPEAT; + END L1; + END IF; + IF v_discount_changed = false THEN + L2: BEGIN + REPEAT + INSERT INTO products VALUES ( + (SELECT COALESCE(MAX(product_id), 0) + 1 FROM products), + v_discount_category, + 'Discount', + 49.99, + 39.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Discounter', + 'Discount Role', + '123 Discount St', + 5, + 'Blue', + 'Large', + 1.2, + 'Maximum discount', + 0.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.9, + 0.19 + ); + SET v_discount_category = v_discount_category || '_EXTRA'; + SET v_max_discount_products = v_max_discount_products - 1; + UNTIL v_max_discount_products < 0 END REPEAT; + END L2; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Product price error + + +-- !query +BEGIN + DECLARE v_employee_gender STRING; + DECLARE v_gender_count INT DEFAULT 0; + DECLARE v_min_gender_emp INT DEFAULT 1; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Employee diversity error'); END; + + L0: BEGIN + FOR gender AS SELECT DISTINCT employee_gender FROM employees LIMIT 2 DO + SET v_employee_gender = gender.employee_gender; + SET v_gender_count = (SELECT COUNT(*) FROM employees WHERE employee_gender = v_employee_gender); + IF v_gender_count < v_min_gender_emp THEN + L1: BEGIN + REPEAT + INSERT INTO employees VALUES ( + (SELECT COALESCE(MAX(employee_id), 0) + 1 FROM employees), + v_employee_gender || ' Equality', + 'diverse@' || LOWER(v_employee_gender) || '.com', + '555-0000', + 'Balancer', + 'HR', + CURRENT_TIMESTAMP, + NULL, + 40000.0, + 0.0, + NULL, + '123 Balancer St', + NULL, + 'Balancer City', + 'CA', + '00000', + 'USA', + CURRENT_TIMESTAMP, + v_employee_gender, + 'Single', + 0 + ); + SET v_gender_count = v_gender_count + 1; + UNTIL v_gender_count >= v_min_gender_emp END REPEAT; + END L1; + END IF; + END FOR; + END L0; + L2: BEGIN + DECLARE v_fill_role STRING; + SET v_fill_role = 'Filler'; + REPEAT + INSERT INTO employees VALUES ( + (SELECT COALESCE(MAX(employee_id), 0) + 1 FROM employees), + v_fill_role, + 'fill@company.com', + '555-0000', + v_fill_role, + v_fill_role, + CURRENT_TIMESTAMP, + NULL, + 30000.0, + 0.0, + NULL, + '123 Filler St', + NULL, + v_fill_role || 'ville', + 'CA', + '00000', + 'USA', + CURRENT_TIMESTAMP, + 'Female', + 'Married', + 1 + ); + SET v_fill_role = v_fill_role || '_R'; + UNTIL (SELECT COUNT(*) FROM employees WHERE employee_position = 'Filler') > 1 END REPEAT; + END L2; +END +-- !query schema +struct +-- !query output +Employee diversity error + + +-- !query +BEGIN + DECLARE v_order_channel STRING; + DECLARE v_channel_orders INT DEFAULT 0; + DECLARE v_channel_returns INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Channel analysis error'); END; + + L0: BEGIN + FOR channel AS SELECT DISTINCT order_channel FROM orders LIMIT 3 DO + SET v_order_channel = channel.order_channel; + SET v_channel_orders = (SELECT COUNT(*) FROM orders WHERE order_channel = v_order_channel); + SET v_channel_returns = (SELECT COUNT(*) FROM orders o JOIN order_items oi ON o.order_id = oi.order_id WHERE o.order_channel = v_order_channel AND oi.item_status = 'Returned'); + IF v_channel_orders > 0 THEN + L1: BEGIN + IF v_channel_returns > 0 THEN + REPEAT + UPDATE orders + SET order_status = 'Processing', + order_tax = order_tax * 0.9 + WHERE order_id IN ( + SELECT o.order_id + FROM orders o + JOIN order_items oi ON o.order_id = oi.order_id + WHERE o.order_channel = v_order_channel + AND oi.item_status = 'Returned' + ); + SET v_channel_returns = v_channel_returns - 1; + UNTIL v_channel_returns = 0 END REPEAT; + END IF; + BEGIN + DECLARE v_low_revenue_orders INT; + SET v_low_revenue_orders = (SELECT COUNT(*) FROM orders WHERE order_channel = v_order_channel AND order_total < 25); + IF v_low_revenue_orders > 1 THEN + L2: BEGIN + REPEAT + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MIN(order_id) FROM orders WHERE order_channel = v_order_channel AND order_total < 25), + (SELECT MIN(product_id) FROM products), + 1, + 10.0, + 0.0, + 1.0, + 11.0 + ); + SET v_low_revenue_orders = v_low_revenue_orders - 1; + UNTIL v_low_revenue_orders < 1 END REPEAT; + END L2; + END IF; + END; + END L1; + ELSE + L3: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping, + order_channel + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Channel Fill', + 15.0, + 1.5, + 0.0, + 2.0, + v_order_channel + ); + SET v_channel_orders = v_channel_orders + 1; + UNTIL v_channel_orders > 0 END REPEAT; + END L3; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Channel analysis error + + +-- !query +BEGIN + DECLARE v_customer_type STRING; + DECLARE v_type_order_count INT; + DECLARE v_type_customer_count INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Customer type error'); END; + + L0: BEGIN + DECLARE v_min_orders_per_type INT DEFAULT 2; +FOR customer_type AS SELECT DISTINCT customer_type FROM customers LIMIT 3 DO + SET v_customer_type = customer_type.customer_type; +SET v_type_order_count = (SELECT COUNT(*) FROM orders o JOIN customers c ON o.customer_id = c.customer_id WHERE c.customer_type = v_customer_type); + SET v_type_customer_count = (SELECT COUNT(*) FROM customers WHERE customer_type = v_customer_type); + IF v_type_order_count < v_min_orders_per_type AND v_type_customer_count > 0 THEN + L1: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers WHERE customer_type = v_customer_type), + CURRENT_TIMESTAMP, + 'Type Fill', + 18.0, + 1.8, + 0.0, + 2.2 + ); + SET v_type_order_count = v_type_order_count + 1; + UNTIL v_type_order_count >= v_min_orders_per_type OR v_type_customer_count = 0 END REPEAT; +END L1; + ELSEIF v_type_customer_count = 0 THEN + L2: BEGIN + REPEAT + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Type ' || v_customer_type, + 'type_' || LOWER(v_customer_type) || '@example.com', + '555-0000', + '123 Type St', + 'Type City', + 'CA', + '00000', + 'USA', + v_customer_type, + CURRENT_TIMESTAMP, + 0.0, + NULL, + NULL, + NULL, + true, + true, + 0.0, + NULL, + NULL + ); + SET v_type_customer_count = v_type_customer_count + 1; + UNTIL v_type_customer_count > 0 END REPEAT; +END L2; +END IF; +END FOR; +END L0; +END +-- !query schema +struct +-- !query output +Customer type error + + +-- !query +BEGIN + DECLARE v_zip_code STRING; + DECLARE v_zip_orders INT DEFAULT 0; + DECLARE v_zip_customers INT DEFAULT 0; + DECLARE v_zip_customer_total DOUBLE DEFAULT 0.0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Zip code analysis error'); END; + + L0: BEGIN + DECLARE v_min_zip_orders INT DEFAULT 3; + FOR zip AS SELECT DISTINCT customer_zip FROM customers LIMIT 2 DO + SET v_zip_code = zip.customer_zip; + SET v_zip_orders = (SELECT COUNT(*) FROM orders o JOIN customers c ON o.customer_id = c.customer_id WHERE c.customer_zip = v_zip_code); + SET v_zip_customers = (SELECT COUNT(*) FROM customers WHERE customer_zip = v_zip_code); + IF v_zip_orders < v_min_zip_orders AND v_zip_customers > 0 THEN + L1: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers WHERE customer_zip = v_zip_code), + CURRENT_TIMESTAMP, + 'Zip Fill', + 20.0, + 2.0, + 0.0, + 3.0 + ); + SET v_zip_orders = v_zip_orders + 1; + UNTIL v_zip_orders >= v_min_zip_orders END REPEAT; + END L1; + ELSEIF v_zip_customers = 0 THEN + L2: BEGIN + REPEAT + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Zip Filler ' || v_zip_code, + 'zip_' || v_zip_code || '@example.com', + '555-0000', + '123 Zip St', + 'Zip City', + 'CA', + v_zip_code, + 'USA', + 'Retail', + CURRENT_TIMESTAMP, + 0.0, + NULL, + NULL, + NULL, + true, + true, + 0.0, + NULL, + NULL + ); + SET v_zip_customers = v_zip_customers + 1; + UNTIL v_zip_customers > 0 END REPEAT; + END L2; + END IF; + SET v_zip_customer_total = (SELECT SUM(customer_total_spent) FROM customers WHERE customer_zip = v_zip_code); + IF v_zip_customer_total > 200.0 AND v_zip_customers > 0 THEN + L3: BEGIN + REPEAT + UPDATE customers + SET customer_discount_percentage = customer_discount_percentage + 0.05 + WHERE customer_zip = v_zip_code + AND customer_discount_percentage < 0.2; + SET v_zip_customer_total = (SELECT SUM(customer_total_spent) FROM customers WHERE customer_zip = v_zip_code); + UNTIL v_zip_customer_total <= 200.0 OR v_zip_customers = 0 END REPEAT; + END L3; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Zip code analysis error + + +-- !query +BEGIN + DECLARE v_order_shipping_region STRING; + DECLARE v_region_shipping_total DOUBLE; + DECLARE v_region_discount_offered BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Shipping region error'); END; + + L0: BEGIN + DECLARE v_max_discount_region_order DOUBLE DEFAULT 100.0; + FOR shipping_region AS SELECT DISTINCT order_shipping_region FROM orders LIMIT 2 DO + SET v_order_shipping_region = shipping_region.order_shipping_region; + SET v_region_shipping_total = (SELECT SUM(order_shipping) FROM orders WHERE order_shipping_region = v_order_shipping_region); + IF v_region_shipping_total > 20 AND v_region_shipping_total < 50 THEN + L1: BEGIN + REPEAT + SET v_region_discount_offered = true; + UPDATE orders SET order_shipping = order_shipping - 0.5 WHERE order_shipping_region = v_order_shipping_region; + SET v_region_shipping_total = (SELECT SUM(order_shipping) FROM orders WHERE order_shipping_region = v_order_shipping_region); + UNTIL v_region_shipping_total <= 15 OR v_region_discount_offered = false END REPEAT; + END L1; + IF v_region_discount_offered = true THEN + BEGIN + DECLARE v_low_region_products INT; + SET v_low_region_products = (SELECT COUNT(*) FROM order_items oi JOIN orders o ON oi.order_id = o.order_id JOIN products p ON oi.product_id = p.product_id WHERE o.order_shipping_region = v_order_shipping_region AND p.product_discount > 0.1); + IF v_low_region_products < 1 THEN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Region Special', + v_order_shipping_region, + 44.99, + 29.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Region Contact', + 'Region Role', + '123 Region St', + 3, + 'Blue', + 'Medium', + 0.9, + 'Region special', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.15, + 0.19 + ); + UNTIL (SELECT COUNT(*) FROM order_items oi JOIN orders o ON oi.order_id = o.order_id JOIN products p ON oi.product_id = p.product_id WHERE o.order_shipping_region = v_order_shipping_region AND p.product_discount > 0.1) > 0 END REPEAT; + END IF; + END; + END IF; + ELSE + L2: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping, + order_shipping_region + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Region Fill', + 22.0, + 2.2, + 0.0, + 5.0, + v_order_shipping_region + ); + SET v_region_shipping_total = (SELECT SUM(order_shipping) FROM orders WHERE order_shipping_region = v_order_shipping_region); + UNTIL v_region_shipping_total > 10 END REPEAT; + END L2; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Shipping region error + + +-- !query +BEGIN + DECLARE v_customer_email_domain STRING; + DECLARE v_domain_customer_count INT; + DECLARE v_domain_order_count INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Email domain error'); END; + + L0: BEGIN + DECLARE v_min_orders_per_domain INT DEFAULT 1; + FOR customer AS SELECT SUBSTRING(customer_email, POSITION('@' IN customer_email)) AS domain, customer_id FROM customers LIMIT 3 DO + SET v_customer_email_domain = customer.domain; + SET v_domain_customer_count = (SELECT COUNT(*) FROM customers WHERE customer_email LIKE '%' || v_customer_email_domain); + SET v_domain_order_count = (SELECT COUNT(*) FROM orders WHERE customer_id IN (SELECT customer_id FROM customers WHERE customer_email LIKE '%' || v_customer_email_domain)); + IF v_domain_order_count < v_min_orders_per_domain AND v_domain_customer_count > 0 THEN + L1: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + customer.customer_id, + CURRENT_TIMESTAMP, + 'Domain Fill', + 15.0, + 1.5, + 0.0, + 2.0 + ); + SET v_domain_order_count = v_domain_order_count + 1; + UNTIL v_domain_order_count >= v_min_orders_per_domain END REPEAT; + END L1; + END IF; + END FOR; + END L0; + BEGIN + DECLARE v_empty_domain_count INT; + SET v_empty_domain_count = (SELECT COUNT(*) FROM customers WHERE customer_email IS NULL OR customer_email = ''); + IF v_empty_domain_count > 0 THEN + L2: BEGIN + REPEAT + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MIN(order_id) FROM orders), + (SELECT MIN(product_id) FROM products), + 1, + 10.0, + 0.0, + 1.0, + 11.0 + ); + SET v_empty_domain_count = v_empty_domain_count - 1; + UNTIL v_empty_domain_count = 0 END REPEAT; + END L2; + END IF; + END; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_department_emp_count INT; + DECLARE v_department_avg_yearly_salary DOUBLE; + DECLARE v_salary_change_needed BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Department salary error'); END; + + L0: BEGIN + DECLARE v_min_dept_size INT DEFAULT 2; + FOR department AS SELECT DISTINCT employee_department FROM employees LIMIT 3 DO + SET v_department_emp_count = (SELECT COUNT(*) FROM employees WHERE employee_department = department.employee_department); + SET v_department_avg_yearly_salary = (SELECT AVG(employee_salary) FROM employees WHERE employee_department = department.employee_department); + IF v_department_emp_count > v_min_dept_size THEN + L1: BEGIN + IF v_department_avg_yearly_salary > 60000 THEN + L2: BEGIN + SET v_salary_change_needed = true; + REPEAT + UPDATE employees SET employee_salary = employee_salary * 0.97 WHERE employee_department = department.employee_department AND employee_salary > 40000; + SET v_department_avg_yearly_salary = (SELECT AVG(employee_salary) FROM employees WHERE employee_department = department.employee_department); + UNTIL v_department_avg_yearly_salary < 60000 OR v_salary_change_needed = false END REPEAT; + END L2; + END IF; + END L1; + ELSE + L3: BEGIN + DECLARE v_new_emp_id INT; + SET v_new_emp_id = (SELECT MAX(employee_id) + 1 FROM employees); + INSERT INTO employees VALUES ( + v_new_emp_id, + 'Dept Filler', + 'dept_' || LOWER(department.employee_department) || '@company.com', + '555-0000', + 'Member', + department.employee_department, + CURRENT_TIMESTAMP, + NULL, + 45000.0, + 0.0, + NULL, + '123 Dept St', + NULL, + 'Dept City', + 'CA', + '00000', + 'USA', + CURRENT_TIMESTAMP, + 'Female', + 'Single', + 0 + ); + SET v_department_emp_count = v_department_emp_count + 1; + END L3; + END IF; + END FOR; + END L0; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_order_status STRING; + DECLARE v_status_count INT; + DECLARE v_status_order_total DOUBLE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order status error'); END; + + L0: BEGIN + DECLARE v_min_status_orders INT DEFAULT 2; + FOR order_stat AS SELECT DISTINCT order_status FROM orders LIMIT 3 DO + SET v_order_status = order_stat.order_status; + SET v_status_count = (SELECT COUNT(*) FROM orders WHERE order_status = v_order_status); + SET v_status_order_total = (SELECT SUM(order_total) FROM orders WHERE order_status = v_order_status); + IF v_status_count < v_min_status_orders THEN + L1: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + v_order_status, + 15.0, + 1.5, + 0.0, + 2.0 + ); + SET v_status_count = (SELECT COUNT(*) FROM orders WHERE order_status = v_order_status); + UNTIL v_status_count >= v_min_status_orders END REPEAT; + END L1; + END IF; + IF v_status_order_total > 200 AND v_status_count > 1 THEN + L2: BEGIN + REPEAT + SET v_status_order_total = v_status_order_total - 10.0; + UPDATE orders + SET order_total = order_total - 10.0 + WHERE order_status = v_order_status + AND order_total > 30.0; + UNTIL v_status_order_total <= 200 OR v_status_count < 2 END REPEAT; + END L2; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Order status error + + +-- !query +BEGIN + DECLARE v_emp_department_size_counts INT; + DECLARE v_dept_name STRING; + DECLARE v_dept_average_age INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Department diversity error'); END; + + L0: BEGIN + DECLARE v_min_dept_diversity INT DEFAULT 2; + FOR dept AS SELECT DISTINCT employee_department FROM employees LIMIT 3 DO + SET v_dept_name = dept.employee_department; + SET v_emp_department_size_counts = (SELECT COUNT(*) FROM employees WHERE employee_department = v_dept_name); + IF v_emp_department_size_counts < v_min_dept_diversity THEN + L1: BEGIN + REPEAT + INSERT INTO employees VALUES ( + (SELECT MAX(employee_id) + 1 FROM employees), + 'Diverse Dept ' || v_dept_name, + 'diverse_' || LOWER(v_dept_name) || '@company.com', + '555-0000', + 'Balancer', + v_dept_name, + CURRENT_TIMESTAMP, + NULL, + 35000.0, + 0.0, + NULL, + '123 Balance St', + NULL, + 'Balance City', + 'CA', + '00000', + 'USA', + CASE WHEN MOD((SELECT COUNT(*) FROM employees WHERE employee_department = v_dept_name), 2) = 0 THEN 'Male' ELSE 'Female' END, + 'Single', + 0 + ); + SET v_emp_department_size_counts = v_emp_department_size_counts + 1; + UNTIL v_emp_department_size_counts >= v_min_dept_diversity END REPEAT; + END L1; + END IF; + SET v_dept_average_age = (SELECT AVG(DATEDIFF(YEAR, employee_birth_date, CURRENT_TIMESTAMP)) FROM employees WHERE employee_department = v_dept_name); + IF v_dept_average_age IS NULL THEN + L2: BEGIN + REPEAT + INSERT INTO employees VALUES ( + (SELECT MAX(employee_id) + 1 FROM employees), + 'Age Dept ' || v_dept_name, + 'age_' || LOWER(v_dept_name) || '@company.com', + '555-0000', + 'Age', + v_dept_name, + CURRENT_TIMESTAMP, + NULL, + 30000.0, + 0.0, + NULL, + '123 Age St', + NULL, + 'Age City', + 'CA', + '00000', + 'USA', + DATEADD(YEAR, -30, CURRENT_TIMESTAMP), + 'Female', + 'Married', + 1 + ); + SET v_dept_average_age = (SELECT AVG(DATEDIFF(YEAR, employee_birth_date, CURRENT_TIMESTAMP)) FROM employees WHERE employee_department = v_dept_name); + UNTIL v_dept_average_age IS NOT NULL END REPEAT; + END L2; + ELSEIF v_dept_average_age < 30 THEN + L3: BEGIN + REPEAT + INSERT INTO employees VALUES ( + (SELECT MAX(employee_id) + 1 FROM employees), + 'Mature ' || v_dept_name, + 'mature_' || LOWER(v_dept_name) || '@company.com', + '555-0000', + 'Senior', + v_dept_name, + CURRENT_TIMESTAMP, + NULL, + 55000.0, + 0.0, + NULL, + '123 Senior St', + NULL, + 'Senior City', + 'CA', + '00000', + 'USA', + DATEADD(YEAR, -40, CURRENT_TIMESTAMP), + 'Male', + 'Married', + 3 + ); + SET v_dept_average_age = (SELECT AVG(DATEDIFF(YEAR, employee_birth_date, CURRENT_TIMESTAMP)) FROM employees WHERE employee_department = v_dept_name); + UNTIL v_dept_average_age > 30 END REPEAT; + END L3; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Department diversity error + + +-- !query +BEGIN + DECLARE v_supplier_type STRING; + DECLARE v_supplier_product_count INT; + DECLARE v_products_per_type_min INT DEFAULT 3; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier product error'); END; + + L0: BEGIN + FOR supplier AS SELECT supplier_id, supplier_main_products FROM suppliers LIMIT 3 DO + SET v_supplier_type = supplier.supplier_main_products; + SET v_supplier_product_count = (SELECT COUNT(*) FROM products WHERE supplier_id = supplier.supplier_id AND product_category = v_supplier_type); + IF v_supplier_product_count < v_products_per_type_min THEN + L1: BEGIN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Type ' || v_supplier_type, + v_supplier_type, + 39.99, + 29.99, + supplier.supplier_id, + supplier.supplier_main_products || ' Contact', + supplier.supplier_main_products || ' Role', + '123 Type St', + 7, + 'Mixed', + 'Standard', + 0.8, + 'Type product', + 3.5, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_supplier_product_count = v_supplier_product_count + 1; + UNTIL v_supplier_product_count >= v_products_per_type_min END REPEAT; + END L1; + END IF; + END FOR; + END L0; + BEGIN + DECLARE v_no_match_product_count INT; + SET v_no_match_product_count = ( + SELECT COUNT(*) + FROM products p + JOIN suppliers s + ON p.supplier_id = s.supplier_id + WHERE p.product_category != s.supplier_main_products + ); + IF v_no_match_product_count > 0 THEN + L2: BEGIN + REPEAT + UPDATE products + SET product_category = ( + SELECT supplier_main_products + FROM suppliers + WHERE supplier_id = products.supplier_id + LIMIT 1 + ) + WHERE product_id = ( + SELECT MIN(product_id) + FROM products p + JOIN suppliers s + ON p.ssupplier_id = s.supplier_id + WHERE p.product_category != s.supplier_main_products + LIMIT 1 + ); + SET v_no_match_product_count = ( + SELECT COUNT(*) + FROM products p + JOIN suppliers s + ON p.supplier_id = s.supplier_id + WHERE p.product_category != s.supplier_main_products + ); + UNTIL v_no_match_product_count = 0 END REPEAT; + END L2; + END IF; + END; +END +-- !query schema +struct +-- !query output +Supplier product error + + +-- !query +BEGIN + DECLARE v_customer_zip_orders_total DOUBLE; + DECLARE v_zip_code STRING; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Customer zip order error'); END; + + L0: BEGIN + DECLARE v_zip_min_orders_total DOUBLE DEFAULT 100.0; + FOR zip AS SELECT DISTINCT customer_zip FROM customers LIMIT 3 DO + SET v_zip_code = zip.customer_zip; + SET v_customer_zip_orders_total = ( + SELECT SUM(order_total) + FROM orders + WHERE customer_id IN ( + SELECT customer_id + FROM customers + WHERE customer_zip = v_zip_code + ) + ); + IF v_customer_zip_orders_total < v_zip_min_orders_total THEN + L1: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers WHERE customer_zip = v_zip_code), + CURRENT_TIMESTAMP, + 'Zip Revenue', + 20.0, + 2.0, + 0.0, + 2.0 + ); + SET v_customer_zip_orders_total = ( + SELECT SUM(order_total) + FROM orders + WHERE customer_id IN ( + SELECT customer_id + FROM customers + WHERE customer_zip = v_zip_code + ) + ); + UNTIL v_customer_zip_orders_total >= v_zip_min_orders_total END REPEAT; + END L1; + END IF; + END FOR; + END L0; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_order_device_type STRING; + DECLARE v_device_order_count INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order device error'); END; + + L0: BEGIN + DECLARE v_min_device_orders INT DEFAULT 1; + FOR device AS SELECT DISTINCT order_device FROM orders LIMIT 3 DO + SET v_order_device_type = device.order_device; + SET v_device_order_count = (SELECT COUNT(*) FROM orders WHERE order_device = v_order_device_type); + IF v_device_order_count < v_min_device_orders THEN + L1: BEGIN + REPEAT + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping, + order_device + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Device Fill', + 15.0, + 1.5, + 0.0, + 2.0, + v_order_device_type + ); + SET v_device_order_count = v_device_order_count + 1; + UNTIL v_device_order_count >= v_min_device_orders END REPEAT; + END L1; + END IF; + END FOR; + END L0; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_product_cost DOUBLE; + DECLARE v_product_discount DOUBLE; + DECLARE v_low_margin_flag BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product margin error'); END; + + L0: BEGIN + DECLARE v_min_products_margin_check INT DEFAULT 2; + FOR product AS SELECT product_id, product_cost, product_discount FROM products LIMIT 3 DO + SET v_product_cost = product.product_cost; + SET v_product_discount = product.product_discount; + L1: BEGIN + DECLARE v_sale_price DOUBLE; + SET v_sale_price = (SELECT product_price FROM products WHERE product_id = product.product_id); + IF v_sale_price - v_product_cost < 10 THEN + SET v_low_margin_flag = true; + L2: BEGIN + REPEAT + UPDATE products + SET product_price = product_price * 1.05 + WHERE product_id = product.product_id; + SET v_sale_price = (SELECT product_price FROM products WHERE product_id = product.product_id); + UNTIL v_sale_price - v_product_cost >= 10 OR v_low_margin_flag = false END REPEAT; + END L2; + END IF; + IF v_product_discount > 0.1 AND v_low_margin_flag = true THEN + REPEAT + UPDATE products + SET product_discount = product_discount - 0.02 + WHERE product_id = product.product_id; + SET v_product_discount = (SELECT product_discount FROM products WHERE product_id = product.product_id); + UNTIL v_product_discount <= 0.1 END REPEAT; + END IF; + END L1; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Product margin error + + +-- !query +BEGIN + DECLARE v_order_item_count INT; + DECLARE v_order_id INT; + DECLARE v_order_total DOUBLE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order item counting error'); END; + + L0: BEGIN + FOR order_id_row AS SELECT order_id FROM orders LIMIT 3 DO + SET v_order_id = order_id_row.order_id; + SET v_order_total = (SELECT order_total FROM orders WHERE order_id = v_order_id); + SET v_order_item_count = (SELECT COUNT(*) FROM order_items WHERE order_id = v_order_id); + IF v_order_item_count = 0 THEN + L1: BEGIN + REPEAT + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + v_order_id, + (SELECT MIN(product_id) FROM products), + 1, + 10.0, + 0.0, + 1.0, + 11.0 + ); + SET v_order_item_count = (SELECT COUNT(*) FROM order_items WHERE order_id = v_order_id); + UNTIL v_order_item_count > 0 END REPEAT; + END L1; + END IF; + IF v_order_total < 10 AND v_order_item_count > 0 THEN + L2: BEGIN + REPEAT + UPDATE orders + SET order_total = order_total + 5.0 + WHERE order_id = v_order_id; + SET v_order_total = (SELECT order_total FROM orders WHERE order_id = v_order_id); + UNTIL v_order_total >= 10 END REPEAT; + END L2; + END IF; + END FOR; + END L0; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_order_payment_balance DOUBLE; + DECLARE v_payment_status STRING; + DECLARE v_unpaid_orders INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order payment error'); END; + + L0: BEGIN + DECLARE v_payment_update_needed BOOLEAN DEFAULT false; + FOR payment_row AS SELECT order_id, order_total, order_tax, order_payment_status FROM orders LIMIT 3 DO + SET v_order_payment_balance = payment_row.order_total + payment_row.order_tax; + SET v_payment_status = payment_row.order_payment_status; + IF v_payment_status = 'Pending' AND v_order_payment_balance > 20 THEN + L1: BEGIN + SET v_payment_update_needed = true; + REPEAT + UPDATE orders + SET order_payment_status = 'Paid' + WHERE order_id = payment_row.order_id; + SET v_payment_status = (SELECT order_payment_status FROM orders WHERE order_id = payment_row.order_id); + UNTIL v_payment_status != 'Pending' OR v_payment_update_needed = false END REPEAT; + END L1; + END IF; + END FOR; + END L0; + BEGIN + SET v_unpaid_orders = (SELECT COUNT(*) FROM orders WHERE order_payment_status = 'Pending' AND (order_total + order_tax) > 20); + IF v_unpaid_orders > 0 THEN + L2: BEGIN + REPEAT + INSERT INTO customers ( + customer_id, + customer_name, + customer_email, + customer_phone, + customer_address_1, + customer_city, + customer_state, + customer_zip, + customer_country, + customer_type, + customer_total_spent, + customer_active_status + ) VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Pending Payee', + 'pending@payment.com', + '555-0000', + '123 Pending St', + 'Paymentville', + 'CA', + '00000', + 'USA', + 'Wholesale', + 0.0, + true + ); + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping, + order_payment_status + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MAX(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Generated', + 25.0, + 2.5, + 0.0, + 3.0, + 'Pending' + ); + SET v_unpaid_orders = v_unpaid_orders - 1; + UNTIL v_unpaid_orders = 0 END REPEAT; + END L2; + END IF; + END; +END +-- !query schema +struct +-- !query output +Order payment error + + +-- !query +BEGIN + DECLARE v_supplier_active BOOLEAN; + DECLARE v_suppliers_per_region_target INT DEFAULT 2; + DECLARE v_region_suppliers_current INT; + DECLARE v_region_to_balance STRING; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier region error'); END; + + L0: BEGIN + FOR region AS SELECT DISTINCT supplier_region FROM suppliers LIMIT 3 DO + SET v_region_to_balance = region.supplier_region; + SET v_region_suppliers_current = (SELECT COUNT(*) FROM suppliers WHERE supplier_active = true AND supplier_region = v_region_to_balance); + IF v_region_suppliers_current < v_suppliers_per_region_target THEN + L1: BEGIN + REPEAT + INSERT INTO suppliers VALUES ( + (SELECT MAX(supplier_id) + 1 FROM suppliers), + 'Regional Filler', + 'Regional Manager', + 'Contact Role', + 'region_' || v_region_to_balance || '@example.com', + '555-0001', + '123 Regional St', + 'Regional City', + 'CA', + '00000', + 'USA', + v_region_to_balance, + 'Diverse', + 'http://regional.com', + CURRENT_TIMESTAMP, + NULL, + NULL, + 4.0, + true + ); + SET v_region_suppliers_current = (SELECT COUNT(*) FROM suppliers WHERE supplier_active = true AND supplier_region = v_region_to_balance); + UNTIL v_region_suppliers_current >= v_suppliers_per_region_target END REPEAT; + END L1; + END IF; + END FOR; + END L0; + BEGIN + DECLARE v_no_region_suppliers_count INT; + SET v_no_region_suppliers_count = (SELECT COUNT(DISTINCT supplier_region) FROM suppliers); + IF v_no_region_suppliers_count < 5 THEN + L2: BEGIN + REPEAT + INSERT INTO suppliers VALUES ( + (SELECT MAX(supplier_id) + 1 FROM suppliers), + 'New Region Corp', + 'Region Manager', + 'Contact', + 'newregion@example.com', + '555-0002', + '123 Main St', + 'New City', + 'CA', + '00001', + 'USA', + CONCAT('Region_', v_no_region_suppliers_count + 1), + 'General', + 'http://newregion.com', + CURRENT_TIMESTAMP, + NULL, + NULL, + 4.5, + true + ); + SET v_no_region_suppliers_count = (SELECT COUNT(DISTINCT supplier_region) FROM suppliers); + UNTIL v_no_region_suppliers_count >= 5 END REPEAT; + END L2; + END IF; + END; +END +-- !query schema +struct +-- !query output +Supplier region error + + +-- !query +BEGIN + DECLARE v_product_color_diversity INT; + DECLARE v_color_product_count INT; + DECLARE v_color_to_boost STRING; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Color diversity error'); END; + + L0: BEGIN + DECLARE v_min_color_products INT DEFAULT 2; + FOR color AS SELECT DISTINCT product_color FROM products LIMIT 3 DO + SET v_color_to_boost = color.product_color; + SET v_color_product_count = (SELECT COUNT(*) FROM products WHERE product_color = v_color_to_boost); + IF v_color_product_count < v_min_color_products THEN + L1: BEGIN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Boost ' || v_color_to_boost, + 'Diverse', + 29.99, + 19.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Color Contact', + 'Color Role', + '123 Color St', + 5, + v_color_to_boost, + 'Standard', + 0.7, + 'Diverse color', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.05, + 0.19 + ); + SET v_color_product_count = (SELECT COUNT(*) FROM products WHERE product_color = v_color_to_boost); + UNTIL v_color_product_count >= v_min_color_products END REPEAT; + END L1; + END IF; + END FOR; + END L0; + BEGIN + SET v_product_color_diversity = (SELECT COUNT(DISTINCT product_color) FROM products); + IF v_product_color_diversity < 6 THEN + L2: BEGIN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Colorful New', + 'General', + 24.99, + 14.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Diverse Contact', + 'Diverse Role', + '123 Diverse St', + 8, + CASE v_product_color_diversity + WHEN 0 THEN 'Red' + WHEN 1 THEN 'Green' + WHEN 2 THEN 'Blue' + WHEN 3 THEN 'Yellow' + WHEN 4 THEN 'Purple' + ELSE 'Orange' + END, + 'Small', + 0.5, + 'Expanding diversity', + 3.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_product_color_diversity = (SELECT COUNT(DISTINCT product_color) FROM products); + UNTIL v_product_color_diversity >= 6 END REPEAT; + END L2; + END IF; + END; +END +-- !query schema +struct +-- !query output +Color diversity error + + +-- !query +BEGIN + DECLARE v_product_origin_diversity INT; + DECLARE v_origin_supplier_pairs INT; + DECLARE v_origin_to_activate STRING; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product origin error'); END; + + L0: BEGIN + DECLARE v_min_origin_types INT DEFAULT 3; + SET v_product_origin_diversity = (SELECT COUNT(DISTINCT supplier_country) FROM products p JOIN suppliers s ON p.supplier_id = s.supplier_id); + IF v_product_origin_diversity < v_min_origin_types THEN + L1: BEGIN + REPEAT + SET v_origin_to_activate = CASE v_product_origin_diversity + WHEN 0 THEN 'Canada' + WHEN 1 THEN 'Mexico' + WHEN 2 THEN 'UK' + ELSE 'Australia' + END; + INSERT INTO suppliers VALUES ( + (SELECT MAX(supplier_id) + 1 FROM suppliers), + v_origin_to_activate || ' Exports', + 'Export Manager', + 'Contact', + 'exports@' || LOWER(v_origin_to_activate) || '.com', + '555-0003', + '123 Export St', + v_origin_to_activate || ' City', + v_origin_to_activate, + '00000', + v_origin_to_activate, + v_origin_to_activate, + 'General', + 'http://exports.com', + CURRENT_TIMESTAMP, + NULL, + NULL, + 4.0, + true + ); + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + v_origin_to_activate || ' Import', + 'Specialty', + 34.99, + 24.99, + (SELECT MAX(supplier_id) FROM suppliers WHERE supplier_country = v_origin_to_activate), + 'Importer', + 'Import Role', + '123 Import St', + 4, + 'Any', + 'Medium', + 0.6, + 'Imported', + 4.5, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_product_origin_diversity = (SELECT COUNT(DISTINCT supplier_country) FROM products p JOIN suppliers s ON p.supplier_id = s.supplier_id); + UNTIL v_product_origin_diversity >= v_min_origin_types END REPEAT; + END L1; + END IF; + SET v_origin_supplier_pairs = (SELECT COUNT(*) FROM products p JOIN suppliers s ON p.supplier_id = s.supplier_id WHERE p.product_category = 'Specialty'); + IF v_origin_supplier_pairs < 2 THEN + L2: BEGIN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Diverse Import', + 'Specialty', + 39.99, + 29.99, + (SELECT MIN(supplier_id) FROM suppliers WHERE supplier_country != 'USA'), + 'Diverse Contact', + 'Diverse Role', + '123 Diverse St', + 5, + 'Multi', + 'Large', + 0.8, + 'Diverse', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_origin_supplier_pairs = (SELECT COUNT(*) FROM products p JOIN suppliers s ON p.supplier_id = s.supplier_id WHERE p.product_category = 'Specialty'); + UNTIL v_origin_supplier_pairs >= 2 END REPEAT; + END L2; + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Product origin error + + +-- !query +BEGIN + DECLARE v_customer_city STRING; + DECLARE v_city_order_count INT; + DECLARE v_city_supplier_count INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('City order diversity error'); END; + + L0: BEGIN + DECLARE v_min_orders_per_city INT DEFAULT 1; + DECLARE v_min_suppliers_per_city INT DEFAULT 1; + FOR city AS SELECT DISTINCT customer_city FROM customers LIMIT 3 DO + SET v_customer_city = city.customer_city; + SET v_city_order_count = (SELECT COUNT(*) FROM orders WHERE customer_id IN (SELECT customer_id FROM customers WHERE customer_city = v_customer_city)); + IF v_city_order_count = 0 THEN + L1: BEGIN + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers WHERE customer_city = v_customer_city), + CURRENT_TIMESTAMP, + 'City Fill', + 25.0, + 2.5, + 0.0, + 2.5 + ); + SET v_city_order_count = (SELECT COUNT(*) FROM orders WHERE customer_id IN (SELECT customer_id FROM customers WHERE customer_city = v_customer_city)); + END L1; + L2: BEGIN + SET v_city_supplier_count = (SELECT COUNT(*) FROM suppliers WHERE supplier_city = v_customer_city); + IF v_city_supplier_count = 0 THEN + INSERT INTO suppliers VALUES ( + (SELECT MAX(supplier_id) + 1 FROM suppliers), + 'City ' || v_customer_city, + 'City Contact', + 'City Role', + 'city@example.com', + '555-0000', + '123 City St', + v_customer_city, + 'CA', + '00000', + 'USA', + v_customer_city, + 'General', + 'http://city.com', + CURRENT_TIMESTAMP, + NULL, + NULL, + 4.0, + true + ); + SET v_city_supplier_count = v_city_supplier_count + 1; + END IF; + END L2; + END IF; + IF EXISTS (SELECT 1 FROM customers WHERE customer_city = v_customer_city) THEN + L3: BEGIN + CASE + WHEN v_city_order_count % 2 = 0 THEN + UPDATE customers + SET customer_active_status = true + WHERE customer_city = v_customer_city; + ELSE + UPDATE customers + SET customer_active_status = false + WHERE customer_city = v_customer_city + AND customer_id = ( + SELECT MIN(customer_id) + FROM customers + WHERE customer_city = v_customer_city + ); + END CASE; + END L3; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +City order diversity error + + +-- !query +BEGIN + DECLARE v_product_size STRING; + DECLARE v_size_variety INT; + DECLARE v_new_sizes_to_add INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product size error'); END; + + L0: BEGIN + SET v_size_variety = (SELECT COUNT(DISTINCT product_size) FROM products); + SET v_new_sizes_to_add = 5 - v_size_variety; + IF v_new_sizes_to_add > 0 THEN + L1: BEGIN + WHILE v_new_sizes_to_add > 0 DO + SET v_product_size = CASE v_new_sizes_to_add + WHEN 5 THEN 'XS' + WHEN 4 THEN 'S' + WHEN 3 THEN 'M' + WHEN 2 THEN 'L' + WHEN 1 THEN 'XL' + END; + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Size Booster ' || v_product_size, + 'Diverse', + 24.99, + 14.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Diverse Contact', + 'Size Role', + '123 Size St', + 6, + 'Blue', + v_product_size, + 0.6, + 'Size variety', + 3.5, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.05, + 0.19 + ); + SET v_new_sizes_to_add = v_new_sizes_to_add - 1; + SET v_size_variety = (SELECT COUNT(DISTINCT product_size) FROM products); + END WHILE; + END L1; + END IF; + L2: BEGIN + FOR size AS SELECT DISTINCT product_size FROM products LIMIT 1 DO + SET v_product_size = size.product_size; + IF (SELECT COUNT(*) FROM products WHERE product_size = v_product_size) < 2 THEN + BEGIN + SET v_new_sizes_to_add = 2 - (SELECT COUNT(*) FROM products WHERE product_size = v_product_size); + WHILE v_new_sizes_to_add > 0 DO + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Extra ' || v_product_size, + 'General', + 29.99, + 19.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Extra Contact', + 'Extra Role', + '123 Extra St', + 4, + 'Red', + v_product_size, + 0.5, + 'Extra size', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_new_sizes_to_add = v_new_sizes_to_add - 1; + END WHILE; + END; + END IF; + END FOR; + END L2; + END L0; +END +-- !query schema +struct +-- !query output +Product size error + + +-- !query +BEGIN + DECLARE v_customer_country STRING; + DECLARE v_country_order_count INT; + DECLARE v_country_supplier_count INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Country diversity error'); END; + + L0: BEGIN + DECLARE v_min_orders_per_country INT DEFAULT 1; + DECLARE v_min_suppliers_per_country INT DEFAULT 1; + FOR country AS SELECT DISTINCT customer_country FROM customers LIMIT 3 DO + SET v_customer_country = country.customer_country; + SET v_country_order_count = (SELECT COUNT(*) FROM orders WHERE customer_id IN (SELECT customer_id FROM customers WHERE customer_country = v_customer_country)); + IF v_country_order_count < v_min_orders_per_country THEN + L1: BEGIN + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers WHERE customer_country = v_customer_country), + CURRENT_TIMESTAMP, + 'Country Fill', + 20.0, + 2.0, + 0.0, + 2.0 + ); + END L1; + END IF; + BEGIN + DECLARE v_country_customer_count INT; + SET v_country_customer_count = (SELECT COUNT(*) FROM customers WHERE customer_country = v_customer_country); + IF v_country_customer_count < 2 THEN + L2: BEGIN + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Country ' || v_customer_country, + 'country_' || LOWER(v_customer_country) || '@example.com', + '555-0000', + '123 Country St', + 'Country City', + v_customer_country, + '00000', + v_customer_country, + 'Retail', + CURRENT_TIMESTAMP, + 0.0, + NULL, + NULL, + NULL, + true, + true, + 0.0, + NULL, + NULL + ); + END L2; + END IF; + END; + SET v_country_supplier_count = (SELECT COUNT(*) FROM suppliers WHERE supplier_country = v_customer_country); + IF v_country_supplier_count < v_min_suppliers_per_country THEN + L3: BEGIN + INSERT INTO suppliers VALUES ( + (SELECT MAX(supplier_id) + 1 FROM suppliers), + v_customer_country || ' Supplier', + 'Supplier Contact', + 'Supplier Role', + 'supplier@' || LOWER(v_customer_country) || '.com', + '555-0001', + '123 Supplier St', + 'Supplier City', + v_customer_country, + '00000', + v_customer_country, + v_customer_country, + 'General', + 'http://supplier.com', + CURRENT_TIMESTAMP, + NULL, + NULL, + 4.0, + true + ); + END L3; + END IF; + END FOR; + END L0; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_product_weight DOUBLE; + DECLARE v_product_category STRING; + DECLARE v_category_weights INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Category weight error'); END; + + L0: BEGIN + DECLARE v_min_category_weight_count INT DEFAULT 3; + FOR category AS SELECT DISTINCT product_category FROM products LIMIT 3 DO + SET v_product_category = category.product_category; + SET v_category_weights = (SELECT COUNT(*) FROM products WHERE product_category = v_product_category AND product_weight IS NOT NULL); + IF v_category_weights < v_min_category_weight_count THEN + L1: BEGIN + BEGIN + DECLARE v_weight_to_set DOUBLE; + SET v_weight_to_set = 0.5 + (SELECT COUNT(*) FROM products WHERE product_category = v_product_category); + WHILE v_weight_to_set < 2.5 DO + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + v_product_category || ' Weight', + v_product_category, + 39.99, + 29.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Weight Contact', + 'Weight Role', + '123 Weight St', + 4, + CASE WHEN MOD((SELECT COUNT(*) FROM products WHERE product_category = v_product_category), 2) = 0 THEN 'Black' ELSE 'Gray' END, + 'Standard', + v_weight_to_set, + 'Weighted item', + 3.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_weight_to_set = v_weight_to_set + 0.2; + SET v_category_weights = v_category_weights + 1; + END WHILE; + END; + END L1; + END IF; + END FOR; + END L0; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_customer_opt_in BOOLEAN; + DECLARE v_opt_in_count INT; + DECLARE v_no_opt_in_count INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Opt-in error'); END; + + L0: BEGIN + SET v_opt_in_count = (SELECT COUNT(*) FROM customers WHERE customer_opt_in_newsletter = true); + SET v_no_opt_in_count = (SELECT COUNT(*) FROM customers WHERE customer_opt_in_newsletter = false); + IF v_no_opt_in_count > v_opt_in_count THEN + L1: BEGIN + FOR customer AS SELECT customer_id FROM customers WHERE customer_opt_in_newsletter = false LIMIT 2 DO + IF v_no_opt_in_count > v_opt_in_count THEN + BEGIN + UPDATE customers + SET customer_opt_in_newsletter = true + WHERE customer_id = customer.customer_id; + SET v_opt_in_count = v_opt_in_count + 1; + SET v_no_opt_in_count = v_no_opt_in_count - 1; + END; + ELSE + BEGIN + DECLARE v_new_customer_id INT; + SET v_new_customer_id = (SELECT MAX(customer_id) + 1 FROM customers); + INSERT INTO customers VALUES ( + v_new_customer_id, + 'New Subscriber', + 'subscriber@example.com', + '555-0002', + '123 Subscriber St', + 'Newsletterville', + 'CA', + '00000', + 'USA', + 'Retail', + CURRENT_TIMESTAMP, + 0.0, + NULL, + NULL, + NULL, + true, + true, + 0.0, + NULL, + NULL + ); + SET v_opt_in_count = v_opt_in_count + 1; + END; + END IF; + END FOR; + END L1; + END IF; + END L0; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_customer_city STRING; + DECLARE v_city_customer_age INT; + DECLARE v_average_customer_age DOUBLE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Customer age diversity error'); END; + + L0: BEGIN + DECLARE v_min_cities_for_age_diversity INT DEFAULT 3; + FOR city AS SELECT DISTINCT customer_city FROM customers LIMIT v_min_cities_for_age_diversity DO + SET v_customer_city = city.customer_city; + BEGIN + SET v_average_customer_age = (SELECT AVG(DATEDIFF(YEAR, customer_birth_date, CURRENT_TIMESTAMP)) FROM customers WHERE customer_city = v_customer_city); + IF v_average_customer_age IS NULL THEN + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Balanced City Customer', + 'balanced@city.com', + '555-0001', + '123 Balance St', + v_customer_city, + 'CA', + '00000', + 'USA', + 'Retail', + CURRENT_TIMESTAMP, + 0.0, + NULL, + DATEADD(YEAR, -35, CURRENT_TIMESTAMP), + NULL, + true, + true, + 0.0, + NULL, + NULL + ); + SET v_average_customer_age = (SELECT AVG(DATEDIFF(YEAR, customer_birth_date, CURRENT_TIMESTAMP)) FROM customers WHERE customer_city = v_customer_city); + END IF; + IF v_average_customer_age < 25 THEN + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Older City Customer', + 'older@city.com', + '555-0002', + '123 Senior St', + v_customer_city, + 'CA', + '00000', + 'USA', + 'Retail', + CURRENT_TIMESTAMP, + 0.0, + NULL, + DATEADD(YEAR, -50, CURRENT_TIMESTAMP), + NULL, + true, + true, + 0.0, + NULL, + NULL + ); + SET v_average_customer_age = (SELECT AVG(DATEDIFF(YEAR, customer_birth_date, CURRENT_TIMESTAMP)) FROM customers WHERE customer_city = v_customer_city); + END IF; + IF v_average_customer_age > 40 THEN + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Younger City Customer', + 'younger@city.com', + '555-0003', + '123 Junior St', + v_customer_city, + 'CA', + '00000', + 'USA', + 'Retail', + CURRENT_TIMESTAMP, + 0.0, + NULL, + DATEADD(YEAR, -20, CURRENT_TIMESTAMP), + NULL, + true, + true, + 0.0, + NULL, + NULL + ); + SET v_average_customer_age = (SELECT AVG(DATEDIFF(YEAR, customer_birth_date, CURRENT_TIMESTAMP)) FROM customers WHERE customer_city = v_customer_city); + END IF; + END; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Customer age diversity error + + +-- !query +BEGIN + DECLARE v_product_review DOUBLE; + DECLARE v_product_rating DOUBLE; + DECLARE v_reviews_per_category INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product review/rating error'); END; + + L0: BEGIN + DECLARE v_min_reviews_per_category INT DEFAULT 1; + FOR category AS SELECT DISTINCT product_category FROM products LIMIT 3 DO + SET v_reviews_per_category = (SELECT SUM(product_reviews) FROM products WHERE product_category = category.product_category); + SET v_product_rating = (SELECT AVG(product_rating) FROM products WHERE product_category = category.product_category); + L1: BEGIN + IF v_reviews_per_category < v_min_reviews_per_category THEN + BEGIN + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Review Filler', + category.product_category, + 39.99, + 29.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Review Contact', + 'Review Role', + '123 Reviews St', + 6, + 'Blue', + 'Large', + 1.2, + 'Filled with reviews', + 4.0, + 25, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_reviews_per_category = v_reviews_per_category + 25; + END; + END IF; + IF v_product_rating IS NULL OR v_product_rating < 3.0 THEN + BEGIN + UPDATE products + SET product_rating = 4.0 + WHERE product_category = category.product_category AND product_reviews > 0; + SET v_product_rating = (SELECT AVG(product_rating) FROM products WHERE product_category = category.product_category); + END; + END IF; + END L1; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Product review/rating error + + +-- !query +BEGIN + DECLARE v_product_id INT; + DECLARE v_product_description STRING; + DECLARE v_description_length INT; + DECLARE v_descriptive_product_count INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Description diversity error'); END; + + L0: BEGIN + DECLARE v_min_description_length INT DEFAULT 20; + DECLARE v_max_description_length INT DEFAULT 100; + DECLARE v_target_descriptive_products INT DEFAULT 5; + FOR product AS SELECT product_id, product_description FROM products LIMIT 3 DO + SET v_product_id = product.product_id; + SET v_product_description = product.product_description; + SET v_description_length = LENGTH(v_product_description); + CASE + WHEN v_description_length < v_min_description_length THEN + L1: BEGIN + DECLARE v_word_count INT DEFAULT v_min_description_length - v_description_length; + DECLARE v_new_description STRING; + REPEAT + SET v_new_description = CONCAT(v_product_description, ' detail'); + SET v_word_count = v_word_count - 1; + UNTIL v_word_count <= 0 + END REPEAT; + UPDATE products + SET product_description = v_new_description + WHERE product_id = v_product_id; + SET v_descriptive_product_count = v_descriptive_product_count + 1; + END L1; + WHEN v_description_length > v_max_description_length THEN + BEGIN + UPDATE products + SET product_description = SUBSTRING(product_description, 1, v_max_description_length) + WHERE product_id = v_product_id; + END; + ELSE + SET v_descriptive_product_count = v_descriptive_product_count + 1; + END CASE; + END FOR; + IF v_descriptive_product_count < v_target_descriptive_products THEN + L2: BEGIN + DECLARE v_new_product_num INT DEFAULT v_target_descriptive_products - v_descriptive_product_count; + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Item with Long Description', + 'General', + 29.99, + 19.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Description Contact', + 'Description Role', + '123 Desc St', + 4, + 'Blue', + 'Medium', + 0.8, + 'This product has a long, detailed, and diverse description to maintain variability in the dataset.', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_new_product_num = v_new_product_num - 1; + UNTIL v_new_product_num <= 0 + END REPEAT; + END L2; + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Description diversity error + + +-- !query +BEGIN + DECLARE v_order_item_status_nulls INT DEFAULT 0; + DECLARE v_order_id INT; + DECLARE v_order_item_id INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order item status error'); END; + + L0: BEGIN + SET v_order_item_status_nulls = (SELECT COUNT(*) FROM order_items WHERE item_status IS NULL); + IF v_order_item_status_nulls > 0 THEN + L1: BEGIN + FOR order_item AS SELECT order_id, order_item_id FROM order_items WHERE item_status IS NULL LIMIT 2 DO + SET v_order_id = order_item.order_id; + SET v_order_item_id = order_item.order_item_id; + BEGIN + DECLARE v_order_status STRING; + SET v_order_status = (SELECT order_status FROM orders WHERE order_id = v_order_id); + CASE v_order_status + WHEN 'Completed' THEN + UPDATE order_items + SET item_status = 'Shipped' + WHERE order_item_id = v_order_item_id AND order_id = v_order_id; + WHEN 'Processing' THEN + UPDATE order_items + SET item_status = 'Preparing' + WHERE order_item_id = v_order_item_id AND order_id = v_order_id; + ELSE + UPDATE order_items + SET item_status = 'Received' + WHERE order_item_id = v_order_item_id AND order_id = v_order_id; + END CASE; + END; + END FOR; + SET v_order_item_status_nulls = (SELECT COUNT(*) FROM order_items WHERE item_status IS NULL); + IF v_order_item_status_nulls > 1 THEN + REPEAT + UPDATE order_items + SET item_status = 'Cancelled' + WHERE order_item_id = (SELECT MIN(order_item_id) FROM order_items WHERE item_status IS NULL); + SET v_order_item_status_nulls = (SELECT COUNT(*) FROM order_items WHERE item_status IS NULL); + UNTIL v_order_item_status_nulls <= 1 + END REPEAT; + END IF; + END L1; + END IF; + END L0; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_customer_is_prime BOOLEAN DEFAULT false; + DECLARE v_prime_customer_count INT; + DECLARE v_min_prime_customers INT DEFAULT 2; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Prime customer error'); END; + + L0: BEGIN + SET v_prime_customer_count = (SELECT COUNT(*) FROM customers WHERE customer_is_prime_member = true); + IF v_prime_customer_count < v_min_prime_customers THEN + FOR cust AS SELECT customer_id FROM customers WHERE customer_is_prime_member IS NULL LIMIT v_min_prime_customers DO + UPDATE customers + SET customer_is_prime_member = true, + customer_prime_customer_since = CURRENT_TIMESTAMP + WHERE customer_id = cust.customer_id; + SET v_customer_is_prime = true; + END FOR; + IF v_customer_is_prime = false AND v_prime_customer_count < v_min_prime_customers THEN + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Prime Customer', + 'prime@example.com', + '555-0000', + '123 Prime St', + 'Prime City', + 'CA', + '00000', + 'USA', + 'Retail', + CURRENT_TIMESTAMP, + 0.0, + NULL, + NULL, + NULL, + true, + true, + 0.0, + CURRENT_TIMESTAMP, + NULL, + true + ); + SET v_customer_is_prime = true; + END IF; + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Prime customer error + + +-- !query +BEGIN + DECLARE v_employee_department STRING; + DECLARE v_department_commission_total DOUBLE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Department commission error'); END; + + L0: BEGIN + FOR dept AS SELECT DISTINCT employee_department FROM employees LIMIT 2 DO + SET v_employee_department = dept.employee_department; + SET v_department_commission_total = (SELECT SUM(employee_commission) FROM employees WHERE employee_department = v_employee_department); + BEGIN + DECLARE v_commission_threshold DOUBLE DEFAULT 2000; + IF v_department_commission_total > v_commission_threshold THEN + L1: BEGIN + DECLARE v_commission_excess DOUBLE; + SET v_commission_excess = v_department_commission_total - v_commission_threshold; + WHILE v_commission_excess > 0 DO + SET v_commission_threshold = v_commission_threshold + 100; + UPDATE employees + SET employee_commission = employee_commission * 0.9 + WHERE employee_department = v_employee_department; + SET v_department_commission_total = (SELECT SUM(employee_commission) FROM employees WHERE employee_department = v_employee_department); + SET v_commission_excess = v_department_commission_total - v_commission_threshold; + END WHILE; + END L1; + END IF; + END; + END FOR; + BEGIN + DECLARE v_no_commission_employees INT; + SET v_no_commission_employees = (SELECT COUNT(*) FROM employees WHERE employee_commission IS NULL OR employee_commission = 0); + IF v_no_commission_employees > 0 THEN + REPEAT + UPDATE employees + SET employee_commission = 100 + WHERE employee_id = (SELECT MIN(employee_id) FROM employees WHERE employee_commission IS NULL OR employee_commission = 0); + SET v_no_commission_employees = v_no_commission_employees - 1; + UNTIL v_no_commission_employees <= 1 + END REPEAT; + END IF; + END; + END L0; +END +-- !query schema +struct +-- !query output +Department commission error + + +-- !query +BEGIN + DECLARE v_order_item_customizable_flag BOOLEAN DEFAULT false; + DECLARE v_customizable_order_items_count INT; + DECLARE v_min_customizable_items INT DEFAULT 2; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Customizable item error'); END; + + L0: BEGIN + SET v_customizable_order_items_count = (SELECT COUNT(*) FROM order_items WHERE item_customization IS NOT NULL); + IF v_customizable_order_items_count < v_min_customizable_items THEN + FOR oi AS SELECT order_item_id FROM order_items WHERE item_customization IS NULL LIMIT v_min_customizable_items DO + UPDATE order_items + SET item_customization = CASE + WHEN MOD(oi.order_item_id, 2) = 0 THEN 'Engraved' + ELSE 'Monogrammed' + END + WHERE order_item_id = oi.order_item_id; + SET v_order_item_customizable_flag = true; + END FOR; + IF v_order_item_customizable_flag = false AND v_customizable_order_items_count < v_min_customizable_items THEN + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total, + item_customization + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MIN(order_id) FROM orders), + (SELECT MIN(product_id) FROM products), + 1, + 10.0, + 0.0, + 1.0, + 11.0, + 'Engraved' + ); + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total, + item_customization + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MIN(order_id) FROM orders), + (SELECT MIN(product_id) FROM products), + 1, + 10.0, + 0.0, + 1.0, + 11.0, + 'Monogrammed' + ); + END IF; + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Customizable item error + + +-- !query +BEGIN + DECLARE v_order_status STRING; + DECLARE v_orders_with_items INT; + DECLARE v_empty_orders INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order-item linkage error'); END; + + L0: BEGIN + SET v_orders_with_items = (SELECT COUNT(DISTINCT oi.order_id) FROM order_items oi); + SET v_empty_orders = (SELECT COUNT(*) FROM orders o WHERE NOT EXISTS (SELECT 1 FROM order_items oi WHERE oi.order_id = o.order_id)); + IF v_empty_orders > 0 THEN + L1: BEGIN + FOR empty_order AS SELECT order_id FROM orders o WHERE NOT EXISTS (SELECT 1 FROM order_items oi WHERE oi.order_id = o.order_id) LIMIT 2 DO + SET v_order_status = (SELECT order_status FROM orders WHERE order_id = empty_order.order_id); + L2: BEGIN + CASE + WHEN v_order_status = 'Completed' THEN + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + empty_order.order_id, + (SELECT MIN(product_id) FROM products), + 1, + 10.0, + 0.0, + 1.0, + 11.0 + ); + WHEN v_order_status = 'Processing' THEN + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total, + item_status + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + empty_order.order_id, + (SELECT MIN(product_id) FROM products), + 1, + 10.0, + 0.0, + 1.0, + 11.0, + 'Preparing' + ); + ELSE + BEGIN + DECLARE v_product_id INT; + SET v_product_id = (SELECT product_id FROM products WHERE product_category = 'Specialty' LIMIT 1); + IF v_product_id IS NULL THEN + SET v_product_id = (SELECT MIN(product_id) FROM products); + END IF; + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total, + item_status + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + empty_order.order_id, + v_product_id, + 1, + 20.0, + 0.0, + 2.0, + 22.0, + CASE + WHEN RANDOM() > 0.5 THEN 'Shipped' + ELSE 'Processing' + END + ); + END; + END CASE; + END L2; + SET v_empty_orders = v_empty_orders - 1; + END FOR; + END L1; + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Order-item linkage error + + +-- !query +BEGIN + DECLARE v_supplier_site_count INT; + DECLARE v_site_char_length INT; + DECLARE v_min_site_length INT DEFAULT 8; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier site error'); END; + + L0: BEGIN + SET v_supplier_site_count = (SELECT COUNT(*) FROM suppliers WHERE supplier_website IS NOT NULL); + IF v_supplier_site_count < 5 THEN + L1: BEGIN + FOR s1 AS SELECT supplier_id FROM suppliers WHERE supplier_website IS NULL OR supplier_website = '' LIMIT 3 DO + SET v_site_char_length = (SELECT LENGTH(supplier_website) FROM suppliers WHERE supplier_id = s1.supplier_id); + IF v_site_char_length < v_min_site_length THEN + L2: BEGIN + IF EXISTS (SELECT 1 FROM suppliers WHERE supplier_id = s1.supplier_id) THEN + UPDATE suppliers + SET supplier_website = CONCAT('https://', REPLACE(LOWER(supplier_name), ' ', ''), '.com') + WHERE supplier_id = s1.supplier_id; + END IF; + END L2; + END IF; + SET v_supplier_site_count = (SELECT COUNT(*) FROM suppliers WHERE supplier_website IS NOT NULL); + IF v_supplier_site_count >= 5 THEN + LEAVE L1; + END IF; + END FOR; + END L1; + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Supplier site error + + +-- !query +BEGIN + DECLARE v_product_units_sold DOUBLE; + DECLARE v_category_products_sold INT; + DECLARE v_sale_regrowth BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Inventory movement error'); END; + + L0: BEGIN + FOR cat AS SELECT DISTINCT product_category FROM products LIMIT 3 DO + SET v_product_units_sold = (SELECT SUM(oi.item_quantity) FROM order_items oi JOIN products p ON oi.product_id = p.product_id WHERE p.product_category = cat.product_category); + SET v_category_products_sold = (SELECT COUNT(DISTINCT p.product_id) FROM order_items oi JOIN products p ON oi.product_id = p.product_id WHERE p.product_category = cat.product_category); + IF v_product_units_sold < 10 THEN + L1: BEGIN + WHILE v_product_units_sold < 20 AND v_category_products_sold < 2 DO + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Fast-Moving ' || cat.product_category, + cat.product_category, + 35.99, + 25.99, + (SELECT MIN(supplier_id) FROM suppliers WHERE supplier_main_products LIKE '%' || cat.product_category || '%'), + 'Movement Contact', + 'Movement Role', + '123 Moving St', + 8, + 'Any', + 'Any', + 0.7, + 'Fast mover', + 4.5, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_category_products_sold = v_category_products_sold + 1; + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MIN(order_id) FROM orders), + (SELECT MAX(product_id) FROM products WHERE product_category = cat.product_category), + 2, + 35.99, + 0.0, + 2.0, + 37.99 + ); + SET v_product_units_sold = v_product_units_sold + 2; + END WHILE; + SET v_sale_regrowth = true; + END L1; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Inventory movement error + + +-- !query +BEGIN + DECLARE v_supplier_product_match INT; + DECLARE v_is_supplier_core BOOLEAN; + DECLARE v_product_supplier_missing BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier-product match error'); END; + + L0: BEGIN + FOR sup AS SELECT supplier_id, supplier_main_products FROM suppliers LIMIT 2 DO + SET v_supplier_product_match = (SELECT COUNT(*) FROM products p WHERE p.supplier_id = sup.supplier_id AND p.product_category = sup.supplier_main_products); + IF v_supplier_product_match = 0 THEN + L1: BEGIN + SET v_is_supplier_core = (sup.supplier_main_products IS NOT NULL AND sup.supplier_main_products != ''); + IF v_is_supplier_core THEN + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + sup.supplier_main_products || ' Special', + sup.supplier_main_products, + 44.99, + 34.99, + sup.supplier_id, + sup.supplier_name, + 'Product Specialist', + '123 Main St', + 10, + 'Any', + 'Large', + 1.3, + 'Supplier-matched', + 4.2, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + END IF; + END L1; + END IF; + END FOR; + END L0; + + L2: BEGIN + IF EXISTS ( + SELECT 1 + FROM products + WHERE product_category NOT LIKE '%' || ( + SELECT supplier_main_products + FROM suppliers + WHERE supplier_id = products.supplier_id + ) || '%' + AND supplier_id IS NOT NULL + ) THEN + FOR prod AS SELECT product_id, product_category, supplier_id FROM products WHERE product_category NOT LIKE '%' || ( + SELECT supplier_main_products + FROM suppliers + WHERE supplier_id = products.supplier_id + ) || '%' LIMIT 2 DO + IF EXISTS ( + SELECT 1 + FROM suppliers + WHERE supplier_main_products LIKE '%' || prod.product_category || '%' + ) THEN + UPDATE products + SET supplier_id = ( + SELECT MIN(supplier_id) + FROM suppliers + WHERE supplier_main_products LIKE '%' || prod.product_category || '%' + ) + WHERE product_id = prod.product_id; + END IF; + END FOR; + END IF; + END L2; +END +-- !query schema +struct +-- !query output +Supplier-product match error + + +-- !query +BEGIN + DECLARE v_employee_tenure_years INT; + DECLARE v_employee_salary DOUBLE; + DECLARE v_salary_differential DOUBLE DEFAULT 0.1; + DECLARE v_tenure_threshold INT DEFAULT 2; + DECLARE v_tenure_based_adjustments INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Tenure salary error'); END; + + L0: BEGIN + FOR emp AS SELECT employee_id, employee_salary, employee_hire_date FROM employees LIMIT 3 DO + IF emp.employee_hire_date IS NOT NULL THEN + SET v_employee_tenure_years = DATEDIFF(YEAR, emp.employee_hire_date, CURRENT_TIMESTAMP); + SET v_employee_salary = emp.employee_salary; + IF v_employee_tenure_years > v_tenure_threshold THEN + UPDATE employees + SET employee_salary = ROUND(employee_salary * (1.0 + v_salary_differential), 2) + WHERE employee_id = emp.employee_id; + SET v_tenure_based_adjustments = v_tenure_based_adjustments + 1; + END IF; + IF v_employee_tenure_years = v_tenure_threshold THEN + UPDATE employees + SET employee_salary = ROUND(employee_salary * 0.95, 2), + employee_description = CONCAT('Provisional (', v_employee_tenure_years, ' years)') + WHERE employee_id = emp.employee_id; + END IF; + END IF; + END FOR; + IF v_tenure_based_adjustments < 1 THEN + INSERT INTO employees VALUES ( + (SELECT MAX(employee_id) + 1 FROM employees), + 'New Hire', + 'hire@company.com', + '555-0000', + 'Associate', + 'Operations', + CURRENT_TIMESTAMP, + NULL, + 40000.0, + 0.0, + NULL, + '123 Hire St', + NULL, + 'New City', + 'CA', + '00000', + 'USA', + CURRENT_TIMESTAMP, + 'Other', + 'Single', + 0 + ); + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Tenure salary error + + +-- !query +BEGIN + DECLARE v_order_shipping_region STRING; + DECLARE v_region_order_count INT; + DECLARE v_max_isolation_level INT DEFAULT 2; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Region isolation error'); END; + + L0: BEGIN + FOR region AS SELECT DISTINCT order_shipping_region FROM orders LIMIT 3 DO + SET v_order_shipping_region = region.order_shipping_region; + SET v_region_order_count = (SELECT COUNT(*) FROM orders WHERE order_shipping_region = v_order_shipping_region); + IF v_region_order_count < v_max_isolation_level THEN + L1: BEGIN + SET v_region_order_count = (SELECT COUNT(*) FROM customers WHERE customer_country = v_order_shipping_region); + IF v_region_order_count = 0 THEN + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Region ' || v_order_shipping_region, + 'region@regional.com', + '555-0000', + '123 Regional St', + v_order_shipping_region, + v_order_shipping_region, + '00000', + v_order_shipping_region, + 'Wholesale', + CURRENT_TIMESTAMP, + 0.0, + NULL, + NULL, + NULL, + true, + true, + 0.0, + NULL, + NULL + ); + END IF; + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping, + order_shipping_region + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers WHERE customer_country = v_order_shipping_region), + CURRENT_TIMESTAMP, + 'Regional Isolation', + 30.0, + 3.0, + 0.0, + 5.0, + v_order_shipping_region + ); + END L1; + END IF; + END FOR; + END L0; +END +-- !query schema +struct +-- !query output +Region isolation error + + +-- !query +BEGIN + DECLARE v_order_tax_percent DOUBLE; + DECLARE v_country_tax_rates INT; + DECLARE v_tax_exception BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Tax rate diversity error'); END; + + L0: BEGIN + SET v_country_tax_rates = ( + SELECT COUNT(DISTINCT CONCAT(order_tax, order_shipping_country)) + FROM orders + WHERE order_tax != 0 + ); + IF v_country_tax_rates < 4 AND (SELECT COUNT(DISTINCT order_shipping_country) FROM orders) > 2 THEN + L1: BEGIN + FOR country_tax_pair AS SELECT DISTINCT order_shipping_country FROM orders WHERE order_tax = 0 LIMIT 4 DO + SET v_order_tax_percent = CASE + WHEN country_tax_pair.order_shipping_country = 'USA' THEN 0.08 + WHEN country_tax_pair.order_shipping_country = 'UK' THEN 0.20 + WHEN country_tax_pair.order_shipping_country = 'CA' THEN 0.05 + WHEN country_tax_pair.order_shipping_country = 'AU' THEN 0.10 + ELSE 0.19 + END; + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping, + order_shipping_country + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Tax Diversity', + 50.0, + ROUND(50.0 * v_order_tax_percent, 2), + 0.0, + 2.0, + country_tax_pair.order_shipping_country + ); + END FOR; + SET v_tax_exception = true; + END L1; + END IF; + END L0; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_product_id INT; + DECLARE v_product_reviews INT; + DECLARE v_products_without_reviews INT; + DECLARE v_review_threshold INT DEFAULT 5; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Review coverage error'); END; + + L0: BEGIN + SET v_products_without_reviews = (SELECT COUNT(*) FROM products WHERE product_reviews = 0 OR product_reviews IS NULL); + IF v_products_without_reviews > 0 THEN + FOR product_no_reviews AS SELECT product_id FROM products WHERE product_reviews = 0 OR product_reviews IS NULL LIMIT 3 DO + SET v_product_id = product_no_reviews.product_id; + SET v_product_reviews = (SELECT product_reviews FROM products WHERE product_id = v_product_id); + IF v_product_reviews < v_review_threshold THEN + SET v_product_reviews = v_product_reviews + 5; + UPDATE products + SET product_reviews = v_product_reviews, + product_description = CONCAT(product_description, ' | REVIEWED') + WHERE product_id = v_product_id; + END IF; + END FOR; + ELSE + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Never Reviewed', + 'Misc', + 9.99, + 4.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Noone', + 'NoContact', + '123 No St', + 1, + 'Clear', + 'Small', + 0.1, + 'Waiting for first review', + 0.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Review coverage error + + +-- !query +BEGIN + DECLARE v_customer_active_missing INT; + DECLARE v_temp_active_set BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Active status error'); END; + + L0: BEGIN + SET v_customer_active_missing = (SELECT COUNT(*) FROM customers WHERE customer_active_status IS NULL); + IF v_customer_active_missing > 0 THEN + FOR cust_missing_active AS SELECT customer_id FROM customers WHERE customer_active_status IS NULL LIMIT 3 DO + UPDATE customers + SET customer_active_status = (DATEDIFF(DAY, customer_membership_date, CURRENT_TIMESTAMP) < 365) + WHERE customer_id = cust_missing_active.customer_id; + SET v_temp_active_set = true; + END FOR; + END IF; + IF v_temp_active_set = false THEN + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Unset Active', + 'inactive@example.com', + '555-0000', + '123 Unset St', + 'Unknown', + 'CA', + '00000', + 'USA', + 'Retail', + CURRENT_TIMESTAMP, + 0.0, + NULL, + NULL, + NULL, + NULL, + true, + 0.0, + NULL, + NULL + ); + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Active status error + + +-- !query +BEGIN + DECLARE v_customer_type_count INT; + DECLARE v_low_diversity_type STRING; + DECLARE v_orders_by_type INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Type order diversity error'); END; + + L0: BEGIN + SET v_customer_type_count = (SELECT COUNT(DISTINCT customer_type) FROM customers); + IF v_customer_type_count < 5 THEN + FOR type_boost AS SELECT DISTINCT customer_type FROM customers LIMIT 3 DO + SET v_orders_by_type = (SELECT COUNT(*) FROM orders o JOIN customers c ON o.customer_id = c.customer_id WHERE c.customer_type = type_boost.customer_type); + IF v_orders_by_type < 2 THEN + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers WHERE customer_type = type_boost.customer_type), + CURRENT_TIMESTAMP, + 'Type Filler', + 15.0, + 1.5, + 0.0, + 2.0 + ); + END IF; + END FOR; + ELSE + SET v_low_diversity_type = (SELECT customer_type FROM customers GROUP BY customer_type ORDER BY COUNT(*) LIMIT 1); + IF (SELECT COUNT(*) FROM orders o JOIN customers c ON o.customer_id = c.customer_id WHERE c.customer_type = v_low_diversity_type) < 1 THEN + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers WHERE customer_type = v_low_diversity_type), + CURRENT_TIMESTAMP, + 'Type Revival', + 10.0, + 1.0, + 0.0, + 1.0 + ); + END IF; + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Type order diversity error + + +-- !query +BEGIN + DECLARE v_order_item_offer_count INT; + DECLARE v_offer_code_required BOOLEAN DEFAULT false; + DECLARE v_order_item_missing_offer INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Offer code error'); END; + + L0: BEGIN + SET v_order_item_offer_count = (SELECT COUNT(*) FROM order_items WHERE item_offer_code IS NOT NULL); + IF v_order_item_offer_count < 2 THEN + FOR order_item_no_offer AS SELECT order_item_id FROM order_items WHERE item_offer_code IS NULL LIMIT 2 DO + UPDATE order_items + SET item_offer_code = CASE + WHEN RANDOM() > 0.7 THEN 'SPRING24' + WHEN RANDOM() > 0.3 THEN 'FALLWINTER' + ELSE 'SUMMER2025' + END + WHERE order_item_id = order_item_no_offer.order_item_id; + SET v_order_item_offer_count = v_order_item_offer_count + 1; + END FOR; + END IF; + SET v_order_item_missing_offer = (SELECT COUNT(*) FROM order_items WHERE item_offer_code IS NULL); + IF v_order_item_missing_offer > 5 THEN + UPDATE order_items + SET item_offer_code = 'NOCODE' + WHERE order_item_id = (SELECT MIN(order_item_id) FROM order_items WHERE item_offer_code IS NULL); + END IF; + END L0; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_employee_dept_stagnant INT; + DECLARE v_dept_stagnant_name STRING; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Dept stagnation error'); END; + + L0: BEGIN + SET v_employee_dept_stagnant = ( + SELECT COUNT(*) + FROM employees + WHERE employee_hire_date < DATEADD(YEAR, -5, CURRENT_TIMESTAMP) + AND employee_department = ( + SELECT employee_department + FROM employees + GROUP BY employee_department + ORDER BY AVG(DATEDIFF(YEAR, employee_hire_date, CURRENT_TIMESTAMP)) DESC + LIMIT 1 + ) + ); + IF v_employee_dept_stagnant > 1 THEN + SET v_dept_stagnant_name = ( + SELECT employee_department + FROM employees + GROUP BY employee_department + ORDER BY AVG(DATEDIFF(YEAR, employee_hire_date, CURRENT_TIMESTAMP)) DESC + LIMIT 1 + ); + INSERT INTO employees VALUES ( + (SELECT MAX(employee_id) + 1 FROM employees), + 'Diverse Dept Member', + 'rotate@company.com', + '555-0000', + 'Associate', + v_dept_stagnant_name, + CURRENT_TIMESTAMP, + NULL, + 45000.0, + 0.0, + NULL, + '123 Diversion St', + NULL, + 'New City', + 'CA', + '00000', + 'USA', + CURRENT_TIMESTAMP, + 'Other', + 'Single', + 0 + ); + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Dept stagnation error + + +-- !query +BEGIN + DECLARE v_supplier_product_min INT DEFAULT 2; + DECLARE v_products_per_supplier INT; + DECLARE v_suppliers_with_stock INT DEFAULT 0; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier-product linkage error'); END; + + L0: BEGIN + FOR sup AS SELECT supplier_id FROM suppliers LIMIT 3 DO + SET v_products_per_supplier = (SELECT COUNT(*) FROM products WHERE supplier_id = sup.supplier_id); + IF v_products_per_supplier < v_supplier_product_min THEN + BEGIN + DECLARE v_new_product_id INT; + SET v_new_product_id = (SELECT MAX(product_id) + 1 FROM products); + INSERT INTO products VALUES ( + v_new_product_id, + 'Supplier Stock', + 'Generic', + 24.99, + 19.99, + sup.supplier_id, + 'Stock Contact', + 'Stock Role', + '123 Stock St', + 5, + 'White', + 'Standard', + 0.6, + 'Supplier item', + 3.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_suppliers_with_stock = v_suppliers_with_stock + 1; + END; + END IF; + END FOR; + END L0; + BEGIN + IF v_suppliers_with_stock < 2 AND (SELECT COUNT(*) FROM products WHERE supplier_id IS NULL) > 0 THEN + UPDATE products + SET supplier_id = (SELECT MIN(supplier_id) FROM suppliers) + WHERE product_id = (SELECT MIN(product_id) FROM products WHERE supplier_id IS NULL); + END IF; + END; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_product_discount_high INT; + DECLARE v_product_discount_low INT; + DECLARE v_discount_skew_ratio DOUBLE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Discount balancing error'); END; + + L0: BEGIN + SET v_product_discount_high = (SELECT COUNT(*) FROM products WHERE product_discount > 0.2); + SET v_product_discount_low = (SELECT COUNT(*) FROM products WHERE product_discount > 0 AND product_discount <= 0.2); + SET v_discount_skew_ratio = v_product_discount_high / GREATEST(v_product_discount_low, 1.0); + IF v_discount_skew_ratio > 2.0 THEN + BEGIN + DECLARE v_over_discounted_product_id INT; + SET v_over_discounted_product_id = (SELECT MIN(product_id) FROM products WHERE product_discount > 0.2 LIMIT 1); + IF v_over_discounted_product_id IS NOT NULL THEN + REPEAT + UPDATE products + SET product_discount = ROUND(product_discount * 0.9, 2) + WHERE product_id = v_over_discounted_product_id; + SET v_product_discount_high = (SELECT COUNT(*) FROM products WHERE product_discount > 0.2); + SET v_discount_skew_ratio = v_product_discount_high / GREATEST(v_product_discount_low, 1.0); + UNTIL v_product_discount_high <= 2 OR v_discount_skew_ratio <= 2.0 OR v_over_discounted_product_id IS NULL + END REPEAT; + END IF; + END; + ELSEIF v_discount_skew_ratio < 0.5 AND v_product_discount_high < 2 THEN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Discount Blowout', + 'Sale', + 49.99, + 34.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Sale Contact', + 'Sale Role', + '123 Sale St', + 8, + 'Red', + 'Large', + 1.1, + 'Big sale', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.3, + 0.19 + ); + SET v_product_discount_high = (SELECT COUNT(*) FROM products WHERE product_discount > 0.2); + UNTIL v_product_discount_high >= 2 OR v_discount_skew_ratio >= 0.5 + END REPEAT; + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Discount balancing error + + +-- !query +BEGIN + DECLARE v_last_product_update_days INT; + DECLARE v_products_needing_update INT; + DECLARE v_freshness_target INT DEFAULT 7; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product timestamp error'); END; + + L0: BEGIN + SET v_last_product_update_days = (SELECT MAX(DATEDIFF(DAY, product_last_update, CURRENT_TIMESTAMP)) FROM products); + SET v_products_needing_update = (SELECT COUNT(*) FROM products WHERE product_last_update IS NULL OR DATEDIFF(DAY, product_last_update, CURRENT_TIMESTAMP) > v_freshness_target); + IF v_last_product_update_days > v_freshness_target AND v_products_needing_update > 0 THEN + FOR product_stale AS SELECT product_id FROM products WHERE product_last_update IS NULL OR DATEDIFF(DAY, product_last_update, CURRENT_TIMESTAMP) > v_freshness_target LIMIT 3 DO + UPDATE products + SET product_last_update = CURRENT_TIMESTAMP, + product_description = CONCAT(product_description, ' | Fresh') + WHERE product_id = product_stale.product_id; + END FOR; + END IF; + END L0; + + BEGIN + IF (SELECT COUNT(*) FROM products WHERE product_last_update > DATEADD(DAY, -3, CURRENT_TIMESTAMP)) < 2 THEN + REPEAT + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Just In', + 'New Arrivals', + 59.99, + 49.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'New Contact', + 'New Role', + '123 Fresh St', + 12, + 'Green', + 'Medium', + 0.8, + 'Fresh item', + 4.5, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + UNTIL (SELECT COUNT(*) FROM products WHERE product_last_update > DATEADD(DAY, -3, CURRENT_TIMESTAMP)) >= 2 + END REPEAT; + END IF; + END; +END +-- !query schema +struct +-- !query output +Product timestamp error + + +-- !query +BEGIN + DECLARE v_order_total_min DOUBLE DEFAULT 10.0; + DECLARE v_order_count_low_value INT; + DECLARE v_order_min_value_id INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order value error'); END; + + L0: BEGIN + SET v_order_count_low_value = (SELECT COUNT(*) FROM orders WHERE order_total < v_order_total_min); + IF v_order_count_low_value > 0 THEN + L1: BEGIN + SET v_order_min_value_id = (SELECT MIN(order_id) FROM orders WHERE order_total < v_order_total_min); + REPEAT + UPDATE orders + SET order_total = v_order_total_min, + order_discount = 0.0 + WHERE order_id = v_order_min_value_id; + SET v_order_min_value_id = (SELECT MIN(order_id) FROM orders WHERE order_total < v_order_total_min); + UNTIL v_order_min_value_id IS NULL OR v_order_count_low_value < 2 + END REPEAT; + END L1; + ELSE + L2: BEGIN + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Low Value', + v_order_total_min / 2.0, + 0.0, + 0.0, + 1.0 + ); + END L2; + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Order value error + + +-- !query +BEGIN + DECLARE v_employee_transfers_required INT DEFAULT 2; + DECLARE v_longest_department_employees INT; + DECLARE v_shortest_department_employees INT; + DECLARE v_transfer_employee_id INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Department balance error'); END; + + L0: BEGIN + SET v_longest_department_employees = ( + SELECT COUNT(*) + FROM employees + WHERE employee_department = ( + SELECT employee_department + FROM employees + GROUP BY employee_department + ORDER BY AVG(DATEDIFF(YEAR, employee_hire_date, CURRENT_TIMESTAMP)) DESC + LIMIT 1 + ) + ); + SET v_shortest_department_employees = ( + SELECT COUNT(*) + FROM employees + WHERE employee_department = ( + SELECT employee_department + FROM employees + GROUP BY employee_department + ORDER BY AVG(DATEDIFF(YEAR, employee_hire_date, CURRENT_TIMESTAMP)) ASC + LIMIT 1 + ) + ); + IF v_longest_department_employees > v_shortest_department_employees + 2 THEN + L1: BEGIN + SET v_transfer_employee_id = ( + SELECT MIN(employee_id) + FROM employees + WHERE employee_department = ( + SELECT employee_department + FROM employees + GROUP BY employee_department + ORDER BY AVG(DATEDIFF(YEAR, employee_hire_date, CURRENT_TIMESTAMP)) DESC + LIMIT 1 + ) + ); + IF v_transfer_employee_id IS NOT NULL THEN + UPDATE employees + SET employee_department = ( + SELECT employee_department + FROM employees + GROUP BY employee_department + ORDER BY AVG(DATEDIFF(YEAR, employee_hire_date, CURRENT_TIMESTAMP)) ASC + LIMIT 1 + ) + WHERE employee_id = v_transfer_employee_id; + END IF; + END L1; + END IF; + END L0; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_supplier_region_imbalance INT; + DECLARE v_most_imbalanced_region STRING; + DECLARE v_region_sku_count INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Region sku error'); END; + + L0: BEGIN + SET v_supplier_region_imbalance = ( + SELECT MAX(cnt) - MIN(cnt) + FROM ( + SELECT COUNT(*) AS cnt + FROM products p + JOIN suppliers s ON p.supplier_id = s.supplier_id + GROUP BY s.supplier_region + ) t + ); + IF v_supplier_region_imbalance > 3 THEN + SET v_most_imbalanced_region = ( + SELECT supplier_region + FROM suppliers s + JOIN products p ON s.supplier_id = p.supplier_id + GROUP BY s.supplier_region + HAVING COUNT(*) = ( + SELECT MIN(cnt) + FROM ( + SELECT COUNT(*) AS cnt + FROM products p + JOIN suppliers s ON p.supplier_id = s.supplier_id + GROUP BY s.supplier_region + ) t + ) + ); + IF v_most_imbalanced_region IS NOT NULL THEN + SET v_region_sku_count = ( + SELECT COUNT(*) + FROM products p + JOIN suppliers s ON p.supplier_id = s.supplier_id + WHERE s.supplier_region = v_most_imbalanced_region + ); + WHILE v_region_sku_count < 4 DO + INSERT INTO suppliers VALUES ( + (SELECT MAX(supplier_id) + 1 FROM suppliers), + 'Balancer ' || v_most_imbalanced_region, + 'Balancer Contact', + 'Balancer Role', + 'balancer@regional.com', + '555-0000', + '123 Balance St', + 'Balancer City', + 'CA', + '00000', + 'USA', + v_most_imbalanced_region, + 'Balancer', + 'http://balancer.com', + CURRENT_TIMESTAMP, + NULL, + NULL, + 4.5, + true + ); + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Region SKU', + 'Balancer', + 29.99, + 19.99, + (SELECT MAX(supplier_id) FROM suppliers), + 'Balancer Contact', + 'Balancer Role', + '123 Balance St', + 4, + 'Black', + 'Medium', + 0.6, + 'Region balancer', + 3.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_region_sku_count = v_region_sku_count + 1; + END WHILE; + END IF; + END IF; + END L0; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_order_item_bulk_flag BOOLEAN DEFAULT false; + DECLARE v_large_orders_count INT; + DECLARE v_min_bulk_items INT DEFAULT 2; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Bulk item error'); END; + + L0: BEGIN + SET v_large_orders_count = (SELECT COUNT(*) FROM order_items WHERE item_quantity >= 5); + IF v_large_orders_count < v_min_bulk_items THEN + WHILE v_large_orders_count < v_min_bulk_items DO + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Bulk', + 120.0, + 12.0, + 0.0, + 0.0 + ); + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MAX(order_id) FROM orders), + (SELECT MIN(product_id) FROM products), + 6, + 15.0, + 0.0, + 1.0, + 96.0 + ); + SET v_large_orders_count = v_large_orders_count + 1; + END WHILE; + SET v_order_item_bulk_flag = true; + END IF; + IF v_order_item_bulk_flag = false AND (SELECT COUNT(*) FROM order_items WHERE item_quantity > 1) < 5 THEN + REPEAT + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MIN(order_id) FROM orders), + (SELECT MIN(product_id) FROM products), + 3, + 12.0, + 0.0, + 1.0, + 39.0 + ); + UNTIL (SELECT COUNT(*) FROM order_items WHERE item_quantity > 1) >= 5 + END REPEAT; + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Bulk item error + + +-- !query +BEGIN + DECLARE v_customer_company_flag_count INT; + DECLARE V_COMPANY_FLAG_KEY STRING DEFAULT 'is_company'; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Company customer error'); END; + + L0: BEGIN + SET v_customer_company_flag_count = (SELECT COUNT(*) FROM customers WHERE JSON_EXTRACT(customer_metadata, V_COMPANY_FLAG_KEY) = 'true'); + IF v_customer_company_flag_count < 2 THEN + L1: BEGIN + FOR cust AS SELECT customer_id FROM customers WHERE JSON_EXTRACT(customer_metadata, V_COMPANY_FLAG_KEY) IS NULL OR JSON_EXTRACT(customer_metadata, V_COMPANY_FLAG_KEY) = 'false' LIMIT 2 DO + UPDATE customers + SET customer_metadata = JSON_SET(customer_metadata, '$.' || V_COMPANY_FLAG_KEY, 'true') + WHERE customer_id = cust.customer_id; + SET v_customer_company_flag_count = v_customer_company_flag_count + 1; + END FOR; + IF v_customer_company_flag_count < 1 THEN + INSERT INTO customers (customer_id, customer_name, customer_metadata) + VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'TopLevel Inc.', + JSON_OBJECT(V_COMPANY_FLAG_KEY, 'true') + ); + END IF; + END L1; + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Company customer error + + +-- !query +BEGIN + DECLARE v_order_item_comment_required BOOLEAN DEFAULT false; + DECLARE v_order_item_with_comments INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order item comment error'); END; + + L0: BEGIN + SET v_order_item_with_comments = (SELECT COUNT(*) FROM order_items WHERE item_notes IS NOT NULL AND item_notes != ''); + IF v_order_item_with_comments < 3 THEN + FOR oi AS SELECT order_item_id FROM order_items WHERE item_notes IS NULL OR item_notes = '' LIMIT 3 DO + UPDATE order_items + SET item_notes = CASE + WHEN MOD(oi.order_item_id, 2) = 0 THEN 'Custom request' + WHEN MOD(oi.order_item_id, 3) = 0 THEN 'Special handling' + ELSE 'No comment' + END + WHERE order_item_id = oi.order_item_id; + SET v_order_item_with_comments = v_order_item_with_comments + 1; + SET v_order_item_comment_required = true; + END FOR; + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Order item comment error + + +-- !query +BEGIN + DECLARE v_product_tags_count INT; + DECLARE V_TAG_VALUE STRING DEFAULT 'featured'; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product tag error'); END; + + L0: BEGIN + SET v_product_tags_count = (SELECT COUNT(*) FROM products WHERE JSON_EXTRACT(product_metadata, '$.tags') IS NOT NULL AND JSON_EXTRACT(product_metadata, '$.tags') != '[]'); + IF v_product_tags_count < 3 THEN + L1: BEGIN + FOR prod AS SELECT product_id, product_metadata FROM products LIMIT 3 DO + IF JSON_EXTRACT(prod.product_metadata, '$.tags') IS NULL OR JSON_EXTRACT(prod.product_metadata, '$.tags') = '[]' THEN + UPDATE products + SET product_metadata = JSON_SET( + IFNULL(product_metadata, '{}'), + '$.tags', + JSON_ARRAY( + V_TAG_VALUE, + CASE WHEN MOD(prod.product_id, 2) = 0 THEN 'eco' ELSE 'limited' END + ) + ) + WHERE product_id = prod.product_id; + SET v_product_tags_count = v_product_tags_count + 1; + END IF; + END FOR; + END L1; + END IF; + IF v_product_tags_count < 1 THEN + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Tagged Example', + 'Special', + 29.99, + 19.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Tag Contact', + 'Tag Role', + '123 Tag St', + 5, + 'Yellow', + 'Small', + 0.5, + 'Tagged', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19, + '{"tags": ["featured", "eco"]}' + ); + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Product tag error + + +-- !query +BEGIN + DECLARE v_order_multiple_statuses BOOLEAN DEFAULT false; + DECLARE v_different_workflows INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Order workflow error'); END; + + L0: BEGIN + SET v_different_workflows = (SELECT COUNT(DISTINCT order_workflow_type) FROM orders WHERE order_workflow_type IS NOT NULL); + IF v_different_workflows < 2 THEN + L1: BEGIN + FOR ord AS SELECT order_id FROM orders WHERE order_workflow_type IS NULL LIMIT 2 DO + UPDATE orders + SET order_workflow_type = CASE + WHEN MOD(ord.order_id, 2) = 0 THEN 'fast_track' + ELSE 'standard' + END + WHERE order_id = ord.order_id; + END FOR; + SET v_order_multiple_statuses = true; + END L1; + END IF; + IF v_order_multiple_statuses = false THEN + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping, + order_workflow_type + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Custom Workflow', + 12.0, + 1.2, + 0.0, + 2.0, + 'bulk_processing' + ); + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Order workflow error + + +-- !query +BEGIN + DECLARE v_inactive_supplier_count INT; + DECLARE v_total_products_from_inactive_suppliers INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier inactivity error'); END; + + L0: BEGIN + SET v_inactive_supplier_count = (SELECT COUNT(*) FROM suppliers WHERE supplier_active = false); + SET v_total_products_from_inactive_suppliers = (SELECT COUNT(*) FROM products p JOIN suppliers s ON p.supplier_id = s.supplier_id WHERE s.supplier_active = false); + IF v_inactive_supplier_count > 1 AND v_total_products_from_inactive_suppliers > 1 THEN + L1: BEGIN + DECLARE v_inactive_supplier_id INT; + SET v_inactive_supprier_id = (SELECT MIN(supplier_id) FROM suppliers WHERE supplier_active = false LIMIT 1); + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Clearance', + 'Closeout', + 9.99, + 4.99, + v_inactive_supplier_id, + 'Clearance Contact', + 'Clearance Role', + '123 Clearance St', + 1, + 'Gray', + 'Small', + 0.1, + 'Supplier inactive', + 0.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.5, + 0.19 + ); + SET v_inactive_supplier_count = v_inactive_supplier_count - 1; + SET v_total_products_from_inactive_suppliers = v_total_products_from_inactive_suppliers + 1; + END L1; + ELSE + L2: BEGIN + INSERT INTO suppliers VALUES ( + (SELECT MAX(supplier_id) + 1 FROM suppliers), + 'Inactive Test', + 'Inactive Manager', + 'Inactive Role', + 'inactive@test.com', + '555-0000', + '123 Inactive St', + 'Inactive City', + 'CA', + '00000', + 'USA', + 'Test', + 'General', + NULL, + CURRENT_TIMESTAMP, + NULL, + NULL, + 2.5, + false + ); + SET v_inactive_supplier_count = v_inactive_supplier_count + 1; + END L2; + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Supplier inactivity error + + +-- !query +BEGIN + DECLARE v_order_item_returns BOOLEAN DEFAULT false; + DECLARE v_returns_to_cover INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Return item error'); END; + + L0: BEGIN + SET v_returns_to_cover = (SELECT COUNT(*) FROM order_items WHERE item_status = 'Returned'); + IF v_returns_to_cover < 2 THEN + L1: BEGIN + FOR oi AS SELECT order_item_id FROM order_items WHERE item_status != 'Returned' LIMIT 2 DO + UPDATE order_items + SET item_status = 'Returned', + item_return_date = CURRENT_TIMESTAMP + WHERE order_item_id = oi.order_item_id; + SET v_returns_to_cover = v_returns_to_cover + 1; + END FOR; + SET v_order_item_returns = true; + END L1; + END IF; + IF v_order_item_returns = false AND v_returns_to_cover < 1 THEN + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total, + item_status, + item_return_date + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MIN(order_id) FROM orders), + (SELECT MIN(product_id) FROM products), + 1, + 10.0, + 0.0, + 1.0, + 11.0, + 'Returned', + CURRENT_TIMESTAMP + ); + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Return item error + + +-- !query +BEGIN + DECLARE v_customer_orders_no_discount INT; + DECLARE v_discount_provided BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Discount logic error'); END; + + L0: BEGIN + SET v_customer_orders_no_discount = ( + SELECT COUNT(*) + FROM customers c + JOIN orders o ON c.customer_id = o.customer_id + WHERE o.order_discount = 0 + ); + IF v_customer_orders_no_discount > 2 THEN + L1: BEGIN + FOR cust AS + SELECT c.customer_id + FROM customers c + JOIN orders o ON c.customer_id = o.customer_id + WHERE o.order_discount = 0 + GROUP BY c.customer_id + LIMIT 2 + DO + UPDATE orders + SET order_discount = 0.1, + order_status = 'Discount Applied' + WHERE customer_id = cust.customer_id + AND order_discount = 0; + SET v_discount_provided = true; + END FOR; + END L1; + END IF; + IF v_discount_provided = false AND v_customer_orders_no_discount > 0 THEN + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers WHERE NOT EXISTS (SELECT 1 FROM orders WHERE customer_id = customers.customer_id)), + CURRENT_TIMESTAMP, + 'Discount Provided', + 25.0, + 2.5, + 0.15, + 2.5 + ); + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Discount logic error + + +-- !query +BEGIN + DECLARE v_supplier_product_threshold INT DEFAULT 3; + DECLARE v_critical_category_products INT; + DECLARE v_extra_promos_flag BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Critical category error'); END; + + L0: BEGIN + FOR category AS SELECT DISTINCT product_category FROM products WHERE product_category != 'General' LIMIT 2 DO + SET v_critical_category_products = (SELECT COUNT(*) FROM products WHERE product_category = category.product_category); + IF v_critical_category_products < v_supplier_product_threshold THEN + WHILE v_critical_category_products < v_supplier_product_threshold DO + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Critical ' || category.product_category, + category.product_category, + 34.99, + 24.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Critical Contact', + 'Critical Role', + '123 Critical St', + 7, + 'Silver', + 'Medium', + 0.8, + 'Critical', + 4.5, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_critical_category_products = (SELECT COUNT(*) FROM products WHERE product_category = category.product_category); + END WHILE; + SET v_extra_promos_flag = true; + END IF; + END FOR; + IF v_extra_promos_flag = true THEN + FOR category AS SELECT DISTINCT product_category FROM products LIMIT 1 DO + IF NOT EXISTS (SELECT 1 FROM order_items oi JOIN products p ON oi.product_id = p.product_id WHERE p.product_category = category.product_category) THEN + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MIN(order_id) FROM orders), + (SELECT MIN(product_id) FROM products WHERE product_category = category.product_category), + 2, + 30.0, + 0.0, + 3.0, + 66.0 + ); + END IF; + END FOR; + END IF; + END L0; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_order_item_status_aging BOOLEAN DEFAULT false; + DECLARE v_order_item_status_preprocessing INT; + DECLARE v_required_status_transitions INT DEFAULT 2; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Status workflow error'); END; + + L0: BEGIN + SET v_order_item_status_preprocessing = (SELECT COUNT(*) FROM order_items WHERE item_status = 'Preprocessing' AND item_delivery_date IS NULL); + IF v_order_item_status_preprocessing >= 1 THEN + UPDATE order_items + SET item_status = 'Processing', + item_delivery_date = CURRENT_TIMESTAMP + WHERE order_item_id = (SELECT MIN(order_item_id) FROM order_items WHERE item_status = 'Preprocessing'); + SET v_order_item_status_aging = true; + END IF; + IF v_order_item_status_aging = false AND (SELECT COUNT(*) FROM customers WHERE customer_last_order_date > DATEADD(DAY, -7, CURRENT_TIMESTAMP)) < 2 THEN + INSERT INTO orders ( + order_id, + customer_id, + order_date, + order_status, + order_total, + order_tax, + order_discount, + order_shipping + ) VALUES ( + (SELECT MAX(order_id) + 1 FROM orders), + (SELECT MIN(customer_id) FROM customers), + CURRENT_TIMESTAMP, + 'Item Status Flow', + 15.0, + 1.5, + 0.0, + 2.0 + ); + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total, + item_status, + item_delivery_date + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MAX(order_id) FROM orders), + (SELECT MIN(product_id) FROM products), + 1, + 12.0, + 0.0, + 1.0, + 13.0, + 'Preprocessing', + NULL + ); + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Status workflow error + + +-- !query +BEGIN + DECLARE v_product_missing_weight INT; + DECLARE v_product_weight_coverage BOOLEAN DEFAULT false; + DECLARE v_min_weight_products INT DEFAULT 2; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Product weight error'); END; + + L0: BEGIN + SET v_product_missing_weight = (SELECT COUNT(*) FROM products WHERE product_weight IS NULL AND product_category NOT LIKE '%Accessories%'); + IF v_product_missing_weight > 0 THEN + L1: BEGIN + FOR prod AS SELECT product_id FROM products WHERE product_weight IS NULL AND product_category NOT LIKE '%Accessories%' LIMIT v_min_weight_products DO + UPDATE products + SET product_weight = ROUND(RAND() * 2 + 0.2, 2) + WHERE product_id = prod.product_id; + SET v_product_weight_coverage = true; + END FOR; + END L1; + END IF; + IF v_product_weight_coverage = false AND v_product_missing_weight > 0 THEN + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Weighted Product', + 'General', + 29.99, + 19.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Weight Contact', + 'Weight Role', + '123 Weight St', + 6, + 'Black', + 'Medium', + 2.2, + 'Weighted sample', + 3.5, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + END IF; + END L0; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_customer_opt_in_newsletter_count INT; + DECLARE v_opt_in_diversity BOOLEAN DEFAULT false; + DECLARE v_min_opt_in_variety INT DEFAULT 2; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Newsletter opt-in error'); END; + + L0: BEGIN + SET v_customer_opt_in_newsletter_count = (SELECT COUNT(*) FROM customers WHERE customer_opt_in_newsletter = true); + IF v_customer_opt_in_newsletter_count < v_min_opt_in_variety THEN + L1: BEGIN + FOR cust AS SELECT customer_id FROM customers WHERE customer_opt_in_newsletter IS NULL LIMIT v_min_opt_in_variety DO + UPDATE customers + SET customer_opt_in_newsletter = true + WHERE customer_id = cust.customer_id; + SET v_opt_in_diversity = true; + END FOR; + IF v_opt_in_diversity = false AND v_customer_opt_in_newsletter_count < v_min_opt_in_variety THEN + INSERT INTO customers VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'Opt-In Customer', + 'optin@example.com', + '555-0000', + '123 OptIn St', + 'OptIn City', + 'CA', + '00000', + 'USA', + 'Retail', + CURRENT_TIMESTAMP, + 0.0, + NULL, + NULL, + NULL, + true, + true, + 0.0, + NULL, + NULL + ); + END IF; + END L1; + END IF; + END L0; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_supplier_product_diversity_count INT; + DECLARE v_min_supplier_product_diversity INT DEFAULT 2; + DECLARE v_diversity_enforced BOOLEAN DEFAULT false; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Supplier-product diversity error'); END; + + L0: BEGIN + SET v_supplier_product_diversity_count = ( + SELECT COUNT(DISTINCT product_category) + FROM products p + JOIN suppliers s ON p.supplier_id = s.supplier_id + WHERE s.supplier_main_products IS NULL + OR p.product_category NOT LIKE CONCAT('%', s.supplier_main_products, '%') + ); + IF v_supplier_product_diversity_count < v_min_supplier_product_diversity THEN + FOR sup AS + SELECT s.supplier_id, s.supplier_main_products + FROM suppliers s + WHERE s.supplier_main_products IS NOT NULL + AND s.supplier_main_products != 'General' + LIMIT 1 + DO + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Diverse Category Product', + (SELECT MIN(product_category) FROM products + WHERE product_category NOT LIKE CONCAT('%', sup.supplier_main_products, '%') + AND product_category IS NOT NULL), + 29.99, + 19.99, + sup.supplier_id, + 'Diverse Contact', + 'Diverse Role', + '123 Diverse St', + 4, + 'White', + 'Medium', + 0.7, + 'Supplier-product diversity', + 3.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + END FOR; + SET v_diversity_enforced = true; + END IF; + END L0; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +BEGIN + DECLARE v_order_item_bundled_flag BOOLEAN DEFAULT false; + DECLARE v_bundled_item_types_count INT; + DECLARE v_min_bundled_items INT DEFAULT 1; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Bundle error'); END; + + L0: BEGIN + SET v_bundled_item_types_count = (SELECT COUNT(*) FROM products WHERE product_category = 'Bundle'); + IF v_bundled_item_types_count < v_min_bundled_items THEN + INSERT INTO products VALUES ( + (SELECT MAX(product_id) + 1 FROM products), + 'Bundle Starter', + 'Bundle', + 49.99, + 39.99, + (SELECT MIN(supplier_id) FROM suppliers), + 'Bundle Contact', + 'Bundle Role', + '123 Bundle St', + 5, + 'Multi', + 'Set', + 2.0, + 'Bundle to bundle', + 4.0, + 0, + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + true, + 0.0, + 0.19 + ); + SET v_bundled_item_types_count = v_bundled_item_types_count + 1; + SET v_order_item_bundled_flag = true; + END IF; + IF v_order_item_bundled_flag = false THEN + REPEAT + INSERT INTO order_items ( + order_item_id, + order_id, + product_id, + item_quantity, + item_price_per_unit, + item_discount, + item_tax, + item_total, + item_bundle_notes + ) VALUES ( + (SELECT MAX(order_item_id) + 1 FROM order_items), + (SELECT MIN(order_id) FROM orders), + (SELECT MAX(product_id) FROM products WHERE product_category = 'Bundle'), + 1, + 49.99, + 0.0, + 5.0, + 54.99, + 'From bundle logic' + ); + UNTIL (SELECT COUNT(*) FROM order_items WHERE item_bundle_notes IS NOT NULL) >= v_min_bundled_items + END REPEAT; + END IF; + END L0; +END +-- !query schema +struct +-- !query output +Bundle error + + +-- !query +BEGIN + DECLARE v_customer_is_foreign_flag BOOLEAN DEFAULT false; + DECLARE v_foreign_customer_count INT; + DECLARE v_min_foreign_customers INT DEFAULT 2; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN VALUES('Foreign customer error'); END; + + L0: BEGIN + SET v_foreign_customer_count = (SELECT COUNT(*) FROM customers WHERE customer_country != 'USA'); + IF v_foreign_customer_count < v_min_foreign_customers THEN + FOR country AS SELECT DISTINCT supplier_country FROM suppliers WHERE supplier_country != 'USA' LIMIT 2 DO + INSERT INTO customers ( + customer_id, + customer_name, + customer_email, + customer_phone, + customer_address_1, + customer_city, + customer_state, + customer_zip, + customer_country, + customer_type, + customer_total_spent, + customer_active_status, + customer_opt_in_newsletter + ) VALUES ( + (SELECT MAX(customer_id) + 1 FROM customers), + 'International ' || country.supplier_country, + 'intl@' || LOWER(country.supplier_country) || '.com', + '555-0000', + '123 Intl St', + 'International City', + country.supplier_country, + '00000', + country.supplier_country, + 'Retail', + 0.0, + true, + true + ); + SET v_customer_is_foreign_flag = true; + END FOR; + END IF; + END L0; +END +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE products +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE customers +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE orders +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE order_items +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE employees +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE suppliers +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/session-variable-precedence.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/session-variable-precedence.sql.out new file mode 100644 index 00000000000..7c724dbc9d0 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/session-variable-precedence.sql.out @@ -0,0 +1,79 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +CREATE TABLE t1(col1 INT, col2 STRING) +-- !query schema +struct<> +-- !query output + + + +-- !query +DECLARE all = 1 +-- !query schema +struct<> +-- !query output + + + +-- !query +DECLARE a = 1 +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT col1, SUM(col2) FROM t1 GROUP BY ALL +-- !query schema +struct +-- !query output + + + +-- !query +SELECT col1, SUM(col2) FROM t1 GROUP BY ALL ORDER BY ALL +-- !query schema +struct +-- !query output + + + +-- !query +SELECT col1, col2 FROM t1 ORDER BY ALL +-- !query schema +struct +-- !query output + + + +-- !query +SELECT col1 AS a, SUM(col2) FROM t1 GROUP BY a +-- !query schema +struct +-- !query output + + + +-- !query +DROP TEMP VARIABLE a +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TEMP VARIABLE all +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE t1 +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/sql-session-variables.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/sql-session-variables.sql.out index 73d3ec73708..de8d6743fc7 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/sql-session-variables.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/sql-session-variables.sql.out @@ -1369,6 +1369,188 @@ struct<> +-- !query +SET VARIABLE title = 'DECLARE VARIABLE - multiple variables declared at once' +-- !query schema +struct<> +-- !query output + + + +-- !query +DECLARE VARIABLE var1, var2, var3 INT +-- !query schema +struct<> +-- !query output + + + +-- !query +DECLARE VARIABLE var4, var5, var6 INT DEFAULT CAST(RAND(0) * 10 AS INT) +-- !query schema +struct<> +-- !query output + + + +-- !query +DECLARE VARIABLE var7, var8, var9 DEFAULT 5 +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT var4 = var5, var4 = var6, var5 = var6 +-- !query schema +struct<(variablereference(system.session.var4=7) = variablereference(system.session.var5=7)):boolean,(variablereference(system.session.var4=7) = variablereference(system.session.var6=7)):boolean,(variablereference(system.session.var5=7) = variablereference(system.session.var6=7)):boolean> +-- !query output +true true true + + +-- !query +DECLARE OR REPLACE VARIABLE var1, var2, var3 DOUBLE +-- !query schema +struct<> +-- !query output + + + +-- !query +DECLARE OR REPLACE VARIABLE var4, var5, var6 DOUBLE DEFAULT RAND(0) +-- !query schema +struct<> +-- !query output + + + +-- !query +DECLARE OR REPLACE VARIABLE var7, var8, var9 DEFAULT 1.5 +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT var4 = var5, var4 = var6, var5 = var6 +-- !query schema +struct<(variablereference(system.session.var4=0.7604953758285915D) = variablereference(system.session.var5=0.7604953758285915D)):boolean,(variablereference(system.session.var4=0.7604953758285915D) = variablereference(system.session.var6=0.7604953758285915D)):boolean,(variablereference(system.session.var5=0.7604953758285915D) = variablereference(system.session.var6=0.7604953758285915D)):boolean> +-- !query output +true true true + + +-- !query +DROP TEMPORARY VARIABLE var1 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TEMPORARY VARIABLE var2 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TEMPORARY VARIABLE var3 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TEMPORARY VARIABLE var4 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TEMPORARY VARIABLE var5 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TEMPORARY VARIABLE var6 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TEMPORARY VARIABLE var7 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TEMPORARY VARIABLE var8 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TEMPORARY VARIABLE var9 +-- !query schema +struct<> +-- !query output + + + +-- !query +SET VARIABLE title = 'DECLARE VARIABLE - duplicate names' +-- !query schema +struct<> +-- !query output + + + +-- !query +DECLARE VARIABLE var1, var2, vAr1 INT +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "DUPLICATE_VARIABLE_NAME_INSIDE_DECLARE", + "sqlState" : "42734", + "messageParameters" : { + "variableName" : "`system`.`session`.`var1`" + } +} + + +-- !query +DECLARE OR REPLACE VARIABLE var1, var2, vAr1 INT +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "DUPLICATE_VARIABLE_NAME_INSIDE_DECLARE", + "sqlState" : "42734", + "messageParameters" : { + "variableName" : "`system`.`session`.`var1`" + } +} + + -- !query SET VARIABLE title = 'SET VARIABLE - row assignment' -- !query schema diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/sql-udf.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/sql-udf.sql.out index fc76ef810b5..de65b20b140 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/sql-udf.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/sql-udf.sql.out @@ -589,6 +589,44 @@ org.apache.spark.sql.catalyst.parser.ParseException } +-- !query +CREATE FUNCTION foo1g1(x INT, y INT UNIQUE) RETURNS INT RETURN y + 1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "INVALID_SQL_SYNTAX.CREATE_FUNC_WITH_COLUMN_CONSTRAINTS", + "sqlState" : "42000", + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 68, + "fragment" : "CREATE FUNCTION foo1g1(x INT, y INT UNIQUE) RETURNS INT RETURN y + 1" + } ] +} + + +-- !query +CREATE FUNCTION foo1g2(id BIGINT CHECK (true)) RETURNS BIGINT RETURN id + 1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.parser.ParseException +{ + "errorClass" : "INVALID_SQL_SYNTAX.CREATE_FUNC_WITH_COLUMN_CONSTRAINTS", + "sqlState" : "42000", + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 1, + "stopIndex" : 75, + "fragment" : "CREATE FUNCTION foo1g2(id BIGINT CHECK (true)) RETURNS BIGINT RETURN id + 1" + } ] +} + + -- !query CREATE FUNCTION foo2a0() RETURNS TABLE() RETURN SELECT 1 -- !query schema @@ -4137,6 +4175,210 @@ org.apache.spark.sql.AnalysisException } +-- !query +CREATE FUNCTION foo3_12a(x INT) RETURNS INT CONTAINS SQL RETURN x +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE FUNCTION foo3_12b(x INT) RETURNS INT READS SQL DATA RETURN x +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE FUNCTION foo3_12c(x INT) RETURNS INT CONTAINS SQL RETURN (SELECT x) +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE FUNCTION foo3_12d(x INT) RETURNS INT CONTAINS SQL RETURN (SELECT COUNT(*) FROM range(0, 3)) +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE FUNCTION foo3_12e(x INT) RETURNS INT CONTAINS SQL RETURN (SELECT COUNT(*) FROM VALUES (0, 1)) +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE FUNCTION foo3_12f(x INT) RETURNS INT CONTAINS SQL RETURN SELECT SUM(c2) FROM t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_SQL_FUNCTION_DATA_ACCESS", + "sqlState" : "42K0E" +} + + +-- !query +CREATE FUNCTION foo3_12f(x INT) RETURNS INT CONTAINS SQL RETURN foo3_12b(x) + 1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_SQL_FUNCTION_DATA_ACCESS", + "sqlState" : "42K0E" +} + + +-- !query +CREATE FUNCTION foo3_12f(x INT) RETURNS INT CONTAINS SQL RETURN 1 + (SELECT SUM(c2) FROM t1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_SQL_FUNCTION_DATA_ACCESS", + "sqlState" : "42K0E" +} + + +-- !query +CREATE FUNCTION foo3_12g(x INT) RETURNS TABLE (a INT, b INT) CONTAINS SQL RETURN SELECT x, x + 1 +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE FUNCTION foo3_12h(x INT) RETURNS TABLE (a INT, b INT) READS SQL DATA RETURN SELECT x, x + 1 +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE FUNCTION foo3_12i(x INT) RETURNS TABLE (a INT, b INT) CONTAINS SQL RETURN SELECT * FROM VALUES (0, 1) +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE FUNCTION foo3_12j(x INT) RETURNS TABLE (a INT, b INT) CONTAINS SQL RETURN SELECT id, id + 1 FROM RANGE(3) +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE FUNCTION foo3_12k(x INT) RETURNS TABLE (a INT, b INT) RETURN SELECT c1, c2 FROM t1 +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE FUNCTION foo3_12f(x INT) RETURNS TABLE (a INT, b INT) CONTAINS SQL RETURN SELECT c1, c2 FROM t1 +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_SQL_FUNCTION_DATA_ACCESS", + "sqlState" : "42K0E" +} + + +-- !query +CREATE FUNCTION foo3_12f(x INT) RETURNS TABLE (a INT, b INT) CONTAINS SQL RETURN SELECT foo3_12b(x), x +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_SQL_FUNCTION_DATA_ACCESS", + "sqlState" : "42K0E" +} + + +-- !query +CREATE FUNCTION foo3_12f(x INT) RETURNS TABLE (a INT, b INT) CONTAINS SQL RETURN SELECT * FROM foo3_12h(x) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_SQL_FUNCTION_DATA_ACCESS", + "sqlState" : "42K0E" +} + + +-- !query +CREATE FUNCTION foo3_12f(x INT) RETURNS TABLE (a INT, b INT) CONTAINS SQL RETURN SELECT * FROM foo3_12k(x) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_SQL_FUNCTION_DATA_ACCESS", + "sqlState" : "42K0E" +} + + +-- !query +CREATE TABLE tbl USING PARQUET AS SELECT c1 FROM t2 +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE FUNCTION foo3_12f(x INT) RETURNS INT CONTAINS SQL RETURN SELECT SUM(c1) FROM tbl +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_SQL_FUNCTION_DATA_ACCESS", + "sqlState" : "42K0E" +} + + +-- !query +CREATE FUNCTION foo3_12f(x INT) RETURNS TABLE (a INT) CONTAINS SQL RETURN SELECT * FROM tbl +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.AnalysisException +{ + "errorClass" : "INVALID_SQL_FUNCTION_DATA_ACCESS", + "sqlState" : "42K0E" +} + + +-- !query +DROP TABLE tbl +-- !query schema +struct<> +-- !query output + + + -- !query CREATE FUNCTION foo3_14a() RETURNS INT RETURN 1 -- !query schema @@ -5363,6 +5605,94 @@ struct<> +-- !query +DROP FUNCTION IF EXISTS foo3_12a +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP FUNCTION IF EXISTS foo3_12b +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP FUNCTION IF EXISTS foo3_12c +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP FUNCTION IF EXISTS foo3_12d +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP FUNCTION IF EXISTS foo3_12e +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP FUNCTION IF EXISTS foo3_12f +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP FUNCTION IF EXISTS foo3_12g +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP FUNCTION IF EXISTS foo3_12h +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP FUNCTION IF EXISTS foo3_12i +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP FUNCTION IF EXISTS foo3_12j +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP FUNCTION IF EXISTS foo3_12k +-- !query schema +struct<> +-- !query output + + + -- !query DROP FUNCTION IF EXISTS foo4_0 -- !query schema diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/st-functions.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/st-functions.sql.out new file mode 100644 index 00000000000..95e7412bfea --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/st-functions.sql.out @@ -0,0 +1,487 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +DROP TABLE IF EXISTS geodata +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE geodata(wkb BINARY) USING parquet +-- !query schema +struct<> +-- !query output + + + +-- !query +INSERT INTO geodata VALUES +(NULL), +(X'0101000000000000000000F03F0000000000000040') +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040') AS STRING) AS result +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.CAST_WITHOUT_SUGGESTION", + "sqlState" : "42K09", + "messageParameters" : { + "sqlExpr" : "\"CAST(st_geogfromwkb(X'0101000000000000000000F03F0000000000000040') AS STRING)\"", + "srcType" : "\"GEOGRAPHY(4326)\"", + "targetType" : "\"STRING\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 84, + "fragment" : "CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040') AS STRING)" + } ] +} + + +-- !query +SELECT CAST(X'0101000000000000000000f03f0000000000000040' AS GEOMETRY(4326)) AS result +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.CAST_WITHOUT_SUGGESTION", + "sqlState" : "42K09", + "messageParameters" : { + "sqlExpr" : "\"CAST(X'0101000000000000000000F03F0000000000000040' AS GEOMETRY(4326))\"", + "srcType" : "\"BINARY\"", + "targetType" : "\"GEOMETRY(4326)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 76, + "fragment" : "CAST(X'0101000000000000000000f03f0000000000000040' AS GEOMETRY(4326))" + } ] +} + + +-- !query +SELECT hex(ST_AsBinary(CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040') AS GEOGRAPHY(ANY)))) AS result +-- !query schema +struct +-- !query output +0101000000000000000000F03F0000000000000040 + + +-- !query +SELECT CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040')::GEOGRAPHY(ANY) AS GEOGRAPHY(4326)) AS result +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.CAST_WITHOUT_SUGGESTION", + "sqlState" : "42K09", + "messageParameters" : { + "sqlExpr" : "\"CAST(CAST(st_geogfromwkb(X'0101000000000000000000F03F0000000000000040') AS GEOGRAPHY(ANY)) AS GEOGRAPHY(4326))\"", + "srcType" : "\"GEOGRAPHY(ANY)\"", + "targetType" : "\"GEOGRAPHY(4326)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 109, + "fragment" : "CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040')::GEOGRAPHY(ANY) AS GEOGRAPHY(4326))" + } ] +} + + +-- !query +SELECT hex(ST_AsBinary(CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040') AS GEOMETRY(4326)))) AS result +-- !query schema +struct +-- !query output +0101000000000000000000F03F0000000000000040 + + +-- !query +SELECT CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040') AS GEOMETRY(ANY)) AS result +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.CAST_WITHOUT_SUGGESTION", + "sqlState" : "42K09", + "messageParameters" : { + "sqlExpr" : "\"CAST(st_geogfromwkb(X'0101000000000000000000F03F0000000000000040') AS GEOMETRY(ANY))\"", + "srcType" : "\"GEOGRAPHY(4326)\"", + "targetType" : "\"GEOMETRY(ANY)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 91, + "fragment" : "CAST(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040') AS GEOMETRY(ANY))" + } ] +} + + +-- !query +SELECT hex(ST_AsBinary(CAST(ST_GeomFromWKB(X'0101000000000000000000f03f0000000000000040') AS GEOMETRY(ANY)))) AS result +-- !query schema +struct +-- !query output +0101000000000000000000F03F0000000000000040 + + +-- !query +SELECT CAST(ST_GeomFromWKB(X'0101000000000000000000f03f0000000000000040')::GEOMETRY(ANY) AS GEOMETRY(4326)) AS result +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.CAST_WITHOUT_SUGGESTION", + "sqlState" : "42K09", + "messageParameters" : { + "sqlExpr" : "\"CAST(CAST(st_geomfromwkb(X'0101000000000000000000F03F0000000000000040') AS GEOMETRY(ANY)) AS GEOMETRY(4326))\"", + "srcType" : "\"GEOMETRY(ANY)\"", + "targetType" : "\"GEOMETRY(4326)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 107, + "fragment" : "CAST(ST_GeomFromWKB(X'0101000000000000000000f03f0000000000000040')::GEOMETRY(ANY) AS GEOMETRY(4326))" + } ] +} + + +-- !query +SELECT typeof(array(ST_GeogFromWKB(wkb), ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY))) FROM geodata +-- !query schema +struct +-- !query output +array +array + + +-- !query +SELECT typeof(array(ST_GeomFromWKB(wkb), ST_GeomFromWKB(wkb)::GEOMETRY(ANY))) FROM geodata +-- !query schema +struct +-- !query output +array +array + + +-- !query +SELECT typeof(map('a', ST_GeogFromWKB(wkb), 'b', ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY))) FROM geodata +-- !query schema +struct +-- !query output +map +map + + +-- !query +SELECT typeof(map('a', ST_GeomFromWKB(wkb), 'b', ST_GeomFromWKB(wkb)::GEOMETRY(ANY))) FROM geodata +-- !query schema +struct +-- !query output +map +map + + +-- !query +SELECT typeof(array(named_struct('g1', ST_GeogFromWKB(wkb), 'g2', ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY)), named_struct('g1', ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY), 'g2', ST_GeogFromWKB(wkb)))) FROM geodata +-- !query schema +struct +-- !query output +array> +array> + + +-- !query +SELECT typeof(array(named_struct('g1', ST_GeomFromWKB(wkb), 'g2', ST_GeomFromWKB(wkb)::GEOMETRY(ANY)), named_struct('g1', ST_GeomFromWKB(wkb)::GEOMETRY(ANY), 'g2', ST_GeomFromWKB(wkb)))) FROM geodata +-- !query schema +struct +-- !query output +array> +array> + + +-- !query +SELECT typeof(named_struct('a', array(ST_GeogFromWKB(wkb), ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY)), 'b', map('g', ST_GeogFromWKB(wkb), 'h', ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY)))) FROM geodata +-- !query schema +struct +-- !query output +struct,b:map> +struct,b:map> + + +-- !query +SELECT typeof(named_struct('a', array(ST_GeomFromWKB(wkb), ST_GeomFromWKB(wkb)::GEOMETRY(ANY)), 'b', map('g', ST_GeomFromWKB(wkb), 'h', ST_GeomFromWKB(wkb)::GEOMETRY(ANY)))) FROM geodata +-- !query schema +struct +-- !query output +struct,b:map> +struct,b:map> + + +-- !query +SELECT typeof(nvl(ST_GeogFromWKB(wkb), ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY))) FROM geodata +-- !query schema +struct +-- !query output +geography(any) +geography(any) + + +-- !query +SELECT typeof(nvl(ST_GeomFromWKB(wkb), ST_GeomFromWKB(wkb)::GEOMETRY(ANY))) FROM geodata +-- !query schema +struct +-- !query output +geometry(any) +geometry(any) + + +-- !query +SELECT typeof(nvl2(ST_GeogFromWKB(wkb), ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY), ST_GeogFromWKB(wkb))) FROM geodata +-- !query schema +struct +-- !query output +geography(any) +geography(any) + + +-- !query +SELECT typeof(nvl2(ST_GeomFromWKB(wkb), ST_GeomFromWKB(wkb)::GEOMETRY(ANY), ST_GeomFromWKB(wkb))) FROM geodata +-- !query schema +struct +-- !query output +geometry(any) +geometry(any) + + +-- !query +SELECT typeof(CASE WHEN wkb IS NOT NULL THEN ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY) ELSE ST_GeogFromWKB(wkb) END) FROM geodata +-- !query schema +struct +-- !query output +geography(any) +geography(any) + + +-- !query +SELECT typeof(CASE WHEN wkb IS NOT NULL THEN ST_GeomFromWKB(wkb)::GEOMETRY(ANY) ELSE ST_GeomFromWKB(wkb) END) FROM geodata +-- !query schema +struct +-- !query output +geometry(any) +geometry(any) + + +-- !query +SELECT typeof(coalesce(ST_GeogFromWKB(wkb), ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY))) FROM geodata +-- !query schema +struct +-- !query output +geography(any) +geography(any) + + +-- !query +SELECT typeof(coalesce(ST_GeomFromWKB(wkb), ST_GeomFromWKB(wkb)::GEOMETRY(ANY))) FROM geodata +-- !query schema +struct +-- !query output +geometry(any) +geometry(any) + + +-- !query +SELECT typeof(IF(wkb IS NOT NULL, ST_GeogFromWKB(wkb)::GEOGRAPHY(ANY), ST_GeogFromWKB(wkb))) FROM geodata +-- !query schema +struct +-- !query output +geography(any) +geography(any) + + +-- !query +SELECT typeof(IF(wkb IS NOT NULL, ST_GeomFromWKB(wkb)::GEOMETRY(ANY), ST_GeomFromWKB(wkb))) FROM geodata +-- !query schema +struct +-- !query output +geometry(any) +geometry(any) + + +-- !query +SELECT hex(ST_AsBinary(ST_GeogFromWKB(X'0101000000000000000000f03f0000000000000040'))) AS result +-- !query schema +struct +-- !query output +0101000000000000000000F03F0000000000000040 + + +-- !query +SELECT hex(ST_AsBinary(ST_GeomFromWKB(X'0101000000000000000000f03f0000000000000040'))) AS result +-- !query schema +struct +-- !query output +0101000000000000000000F03F0000000000000040 + + +-- !query +SELECT ST_Srid(NULL) +-- !query schema +struct +-- !query output +NULL + + +-- !query +SELECT ST_Srid(ST_GeogFromWKB(X'0101000000000000000000F03F0000000000000040')) +-- !query schema +struct +-- !query output +4326 + + +-- !query +SELECT ST_Srid(ST_GeomFromWKB(X'0101000000000000000000F03F0000000000000040')) +-- !query schema +struct +-- !query output +0 + + +-- !query +SELECT COUNT(*) FROM geodata WHERE ST_Srid(ST_GeogFromWKB(wkb)) <> 4326 +-- !query schema +struct +-- !query output +0 + + +-- !query +SELECT COUNT(*) FROM geodata WHERE ST_Srid(ST_GeomFromWKB(wkb)) <> 0 +-- !query schema +struct +-- !query output +0 + + +-- !query +SELECT ST_Srid(ST_SetSrid(ST_GeogFromWKB(X'0101000000000000000000F03F0000000000000040'), 4326)) +-- !query schema +struct +-- !query output +4326 + + +-- !query +SELECT ST_Srid(ST_SetSrid(ST_GeomFromWKB(X'0101000000000000000000F03F0000000000000040'), 3857)) +-- !query schema +struct +-- !query output +3857 + + +-- !query +SELECT ST_Srid(ST_SetSrid(ST_GeogFromWKB(X'0101000000000000000000F03F0000000000000040'), 3857)) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkIllegalArgumentException +{ + "errorClass" : "ST_INVALID_SRID_VALUE", + "sqlState" : "22023", + "messageParameters" : { + "srid" : "3857" + } +} + + +-- !query +SELECT ST_Srid(ST_SetSrid(ST_GeomFromWKB(X'0101000000000000000000F03F0000000000000040'), 9999)) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkIllegalArgumentException +{ + "errorClass" : "ST_INVALID_SRID_VALUE", + "sqlState" : "22023", + "messageParameters" : { + "srid" : "9999" + } +} + + +-- !query +SELECT COUNT(*) FROM geodata WHERE ST_Srid(ST_SetSrid(ST_GeogFromWKB(wkb), 4326)) <> 4326 +-- !query schema +struct +-- !query output +0 + + +-- !query +SELECT COUNT(*) FROM geodata WHERE ST_Srid(ST_SetSrid(ST_GeomFromWKB(wkb), 3857)) <> 3857 +-- !query schema +struct +-- !query output +0 + + +-- !query +SELECT COUNT(*) FROM geodata WHERE ST_Srid(ST_SetSrid(ST_GeogFromWKB(wkb), 3857)) IS NOT NULL +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkIllegalArgumentException +{ + "errorClass" : "ST_INVALID_SRID_VALUE", + "sqlState" : "22023", + "messageParameters" : { + "srid" : "3857" + } +} + + +-- !query +SELECT COUNT(*) FROM geodata WHERE ST_Srid(ST_SetSrid(ST_GeomFromWKB(wkb), 9999)) IS NOT NULL +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkIllegalArgumentException +{ + "errorClass" : "ST_INVALID_SRID_VALUE", + "sqlState" : "22023", + "messageParameters" : { + "srid" : "9999" + } +} + + +-- !query +DROP TABLE geodata +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/string-functions.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/string-functions.sql.out index 23c59f3111a..1d706cba88c 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/string-functions.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/string-functions.sql.out @@ -181,6 +181,46 @@ struct> ["h","e","l","l","o"] +-- !query +SELECT split('hello', '', 0) +-- !query schema +struct> +-- !query output +["h","e","l","l","o"] + + +-- !query +SELECT split('hello', '', 1) +-- !query schema +struct> +-- !query output +["hello"] + + +-- !query +SELECT split('hello', '', 3) +-- !query schema +struct> +-- !query output +["h","e","llo"] + + +-- !query +SELECT split('hello', '', 5) +-- !query schema +struct> +-- !query output +["h","e","l","l","o"] + + +-- !query +SELECT split('hello', '', 100) +-- !query schema +struct> +-- !query output +["h","e","l","l","o"] + + -- !query SELECT split('', '') -- !query schema @@ -189,6 +229,30 @@ struct> [""] +-- !query +SELECT split('', '', -1) +-- !query schema +struct> +-- !query output +[""] + + +-- !query +SELECT split('', '', 0) +-- !query schema +struct> +-- !query output +[""] + + +-- !query +SELECT split('', '', 1) +-- !query schema +struct> +-- !query output +[""] + + -- !query SELECT split('abc', null) -- !query schema @@ -2345,3 +2409,27 @@ select try_validate_utf8(x'80') struct -- !query output NULL + + +-- !query +select quote('Spark') +-- !query schema +struct +-- !query output +'Spark' + + +-- !query +select quote("Don't") +-- !query schema +struct +-- !query output +'Don\'t' + + +-- !query +select quote(NULL) +-- !query schema +struct +-- !query output +NULL diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/struct.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/struct.sql.out index d642321e218..1fdb8ebaac6 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/struct.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/struct.sql.out @@ -85,3 +85,43 @@ struct 1 delta 2 eta 3 iota + + +-- !query +SELECT STRUCT(1 AS a) AS b, b AS c +-- !query schema +struct,c:struct> +-- !query output +{"a":1} {"a":1} + + +-- !query +SELECT STRUCT(col1 AS a) AS b, b AS c FROM VALUES(1) +-- !query schema +struct,c:struct> +-- !query output +{"a":1} {"a":1} + + +-- !query +SELECT STRUCT(1 AS a) AS b, b AS c GROUP BY b +-- !query schema +struct,c:struct> +-- !query output +{"a":1} {"a":1} + + +-- !query +SELECT STRUCT(col1 AS a) AS b, b AS c FROM VALUES(1) GROUP BY b +-- !query schema +struct,c:struct> +-- !query output +{"a":1} {"a":1} + + +-- !query +SELECT MAX(STRUCT(1 AS a)), 2 AS b, b AS c GROUP BY b +-- !query schema +struct,b:int,c:int> +-- !query output +{"a":1} 2 2 diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/subquery/resolution-edge-cases.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/subquery/resolution-edge-cases.sql.out new file mode 100644 index 00000000000..ba3d2826c38 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/subquery/resolution-edge-cases.sql.out @@ -0,0 +1,179 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +CREATE TABLE t1(col1 INT, col2 STRING) +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE t2(col1 INT) +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE t3(col1 INT, col2 STRING) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT * +FROM ( + SELECT ( + SELECT t1.col1 + FROM t1 + WHERE t3.col1 = t1.col2 + LIMIT 1 + ) + FROM t3 + GROUP BY ( + SELECT t1.col1 + FROM t1 + WHERE t3.col1 = t1.col2 + LIMIT 1 + ) +) +-- !query schema +struct +-- !query output + + + +-- !query +SELECT * +FROM ( + SELECT 1 IN ( + SELECT t1.col1 + FROM t1 + WHERE t3.col1 = t1.col2 + LIMIT 1 + ) + FROM t3 + GROUP BY 1 IN ( + SELECT t1.col1 + FROM t1 + WHERE t3.col1 = t1.col2 + LIMIT 1 + ) +) +-- !query schema +struct<(1 IN (listquery(col1))):boolean> +-- !query output + + + +-- !query +SELECT * +FROM ( + SELECT EXISTS ( + SELECT t1.col1 + FROM t1 + WHERE t3.col1 = t1.col2 + LIMIT 1 + ) + FROM t3 + GROUP BY EXISTS ( + SELECT t1.col1 + FROM t1 + WHERE t3.col1 = t1.col2 + LIMIT 1 + ) +) +-- !query schema +struct +-- !query output + + + +-- !query +SELECT col1 IN (SELECT col1 FROM t2) +FROM t2 +GROUP BY col1 IN (SELECT col1 FROM t2), col1 +ORDER BY col1 IN (SELECT col1 FROM t2) +-- !query schema +struct<(col1 IN (listquery())):boolean> +-- !query output + + + +-- !query +SELECT col1 FROM t2 GROUP BY col1 IN (SELECT col1 FROM t2), col1 ORDER BY col1 IN (SELECT col1 FROM t2) +-- !query schema +struct +-- !query output + + + +-- !query +SELECT col1 FROM t2 GROUP BY col1 ORDER BY 1 IN (SELECT 1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.UNSUPPORTED_IN_EXISTS_SUBQUERY", + "sqlState" : "0A000", + "messageParameters" : { + "treeNode" : "Sort [1 IN (list#x []) ASC NULLS FIRST], true\n: +- Project [1 AS 1#x]\n: +- OneRowRelation\n+- Aggregate [col1#x], [col1#x]\n +- SubqueryAlias spark_catalog.default.t2\n +- Relation spark_catalog.default.t2[col1#x] parquet\n" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 46, + "stopIndex" : 58, + "fragment" : "IN (SELECT 1)" + } ] +} + + +-- !query +SELECT col1 AS a, a + 1 FROM t2 GROUP BY col1 ORDER BY 1 IN (SELECT 1) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.UNSUPPORTED_IN_EXISTS_SUBQUERY", + "sqlState" : "0A000", + "messageParameters" : { + "treeNode" : "Sort [1 IN (list#x []) ASC NULLS FIRST], true\n: +- Project [1 AS 1#x]\n: +- OneRowRelation\n+- Project [a#x, (a#x + 1) AS (lateralAliasReference(a) + 1)#x]\n +- Project [col1#x, col1#x AS a#x]\n +- Aggregate [col1#x], [col1#x]\n +- SubqueryAlias spark_catalog.default.t2\n +- Relation spark_catalog.default.t2[col1#x] parquet\n" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 58, + "stopIndex" : 70, + "fragment" : "IN (SELECT 1)" + } ] +} + + +-- !query +DROP TABLE t1 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE t2 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE t3 +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/subquery/subquery-nested-data.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/subquery/subquery-nested-data.sql.out index e0fd040ca4b..90c59d3aa0d 100644 --- a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/subquery/subquery-nested-data.sql.out +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/subquery/subquery-nested-data.sql.out @@ -252,9 +252,9 @@ org.apache.spark.sql.AnalysisException "queryContext" : [ { "objectType" : "", "objectName" : "", - "startIndex" : 44, - "stopIndex" : 44, - "fragment" : "y" + "startIndex" : 23, + "stopIndex" : 66, + "fragment" : "(select sum(y2) from y where xm[y2] = ym[1])" } ] } @@ -283,9 +283,9 @@ org.apache.spark.sql.AnalysisException "queryContext" : [ { "objectType" : "", "objectName" : "", - "startIndex" : 44, - "stopIndex" : 44, - "fragment" : "y" + "startIndex" : 23, + "stopIndex" : 65, + "fragment" : "(select sum(y2) from y where xm[1] = ym[1])" } ] } diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/thetasketch.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/thetasketch.sql.out new file mode 100644 index 00000000000..685a268b434 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/thetasketch.sql.out @@ -0,0 +1,1356 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +DROP TABLE IF EXISTS t_int_1_5_through_7_11 +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE t_int_1_5_through_7_11 AS +VALUES + (1, 5), (2, 6), (3, 7), (4, 8), (5, 9), (6, 10), (7, 11) AS tab(col1, col2) +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_long_1_5_through_7_11 +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE t_long_1_5_through_7_11 AS +VALUES + (1L, 5L), (2L, 6L), (3L, 7L), (4L, 8L), (5L, 9L), (6L, 10L), (7L, 11L) AS tab(col1, col2) +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_double_1_1_1_4_through_1_5_1_8 +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE t_double_1_1_1_4_through_1_5_1_8 AS +SELECT CAST(col1 AS DOUBLE) AS col1, CAST(col2 AS DOUBLE) AS col2 +FROM VALUES + (1.1, 1.4), (1.2, 1.5), (1.3, 1.6), (1.4, 1.7), (1.5, 1.8) AS tab(col1, col2) +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_float_1_1_1_4_through_1_5_1_8 +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE t_float_1_1_1_4_through_1_5_1_8 AS +SELECT CAST(col1 AS FLOAT) col1, CAST(col2 AS FLOAT) col2 +FROM VALUES + (1.1, 1.4), (1.2, 1.5), (1.3, 1.6), (1.4, 1.7), (1.5, 1.8) AS tab(col1, col2) +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_string_a_d_through_e_h +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE t_string_a_d_through_e_h AS +VALUES + ('a', 'd'), ('b', 'e'), ('c', 'f'), ('d', 'g'), ('e', 'h') AS tab(col1, col2) +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_binary_a_b_through_e_f +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE t_binary_a_b_through_e_f AS +VALUES + (X'A', X'B'), (X'B', X'C'), (X'C', X'D'), (X'D', X'E'), (X'E', X'F') AS tab(col1, col2) +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_array_int_1_3_through_4_6 +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE t_array_int_1_3_through_4_6 AS +VALUES + (ARRAY(1), ARRAY(3)), + (ARRAY(2), ARRAY(4)), + (ARRAY(3), ARRAY(5)), + (ARRAY(4), ARRAY(6)) AS tab(col1, col2) +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_array_long_1_3_through_4_6 +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE t_array_long_1_3_through_4_6 AS +VALUES + (ARRAY(1L), ARRAY(3L)), + (ARRAY(2L), ARRAY(4L)), + (ARRAY(3L), ARRAY(5L)), + (ARRAY(4L), ARRAY(6L)) AS tab(col1, col2) +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_string_collation +-- !query schema +struct<> +-- !query output + + + +-- !query +CREATE TABLE t_string_collation AS +VALUES + (''), (' '), (CAST(X'C1' AS STRING)), (CAST(X'80' AS STRING)), + ('\uFFFD'), ('Ã…'), ('Ã¥'), ('a\u030A'), ('Ã… '), ('Ã¥ '), + ('a\u030A ') AS tab(col1) +-- !query schema +struct<> +-- !query output + + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col1)) AS result FROM t_int_1_5_through_7_11 +-- !query schema +struct +-- !query output +7 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col1)) FROM t_array_int_1_3_through_4_6 +-- !query schema +struct +-- !query output +4 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col2)) FROM t_array_long_1_3_through_4_6 +-- !query schema +struct +-- !query output +4 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col1)) FROM t_binary_a_b_through_e_f +-- !query schema +struct +-- !query output +5 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col1)) FROM t_double_1_1_1_4_through_1_5_1_8 +-- !query schema +struct +-- !query output +5 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col2)) FROM t_float_1_1_1_4_through_1_5_1_8 +-- !query schema +struct +-- !query output +5 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col1, 22)) FROM t_int_1_5_through_7_11 +-- !query schema +struct +-- !query output +7 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col1)) FROM t_long_1_5_through_7_11 +-- !query schema +struct +-- !query output +7 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col1)) FROM t_string_a_d_through_e_h +-- !query schema +struct +-- !query output +5 + + +-- !query +SELECT theta_sketch_estimate( + theta_union( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_int_1_5_through_7_11 +-- !query schema +struct +-- !query output +11 + + +-- !query +SELECT theta_sketch_estimate( + theta_union( + theta_sketch_agg(col1, 15), + theta_sketch_agg(col2))) FROM t_long_1_5_through_7_11 +-- !query schema +struct +-- !query output +11 + + +-- !query +SELECT theta_sketch_estimate( + theta_union( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_double_1_1_1_4_through_1_5_1_8 +-- !query schema +struct +-- !query output +8 + + +-- !query +SELECT theta_sketch_estimate( + theta_union( + theta_sketch_agg(col1, 6), + theta_sketch_agg(col2, 15), 15)) FROM t_float_1_1_1_4_through_1_5_1_8 +-- !query schema +struct +-- !query output +8 + + +-- !query +SELECT theta_sketch_estimate( + theta_union( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_string_a_d_through_e_h +-- !query schema +struct +-- !query output +8 + + +-- !query +SELECT theta_sketch_estimate( + theta_union( + theta_sketch_agg(col1), + theta_sketch_agg(col2), 20)) FROM t_binary_a_b_through_e_f +-- !query schema +struct +-- !query output +6 + + +-- !query +SELECT theta_sketch_estimate( + theta_union( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_array_int_1_3_through_4_6 +-- !query schema +struct +-- !query output +6 + + +-- !query +SELECT theta_sketch_estimate( + theta_union( + theta_sketch_agg(col1), + theta_sketch_agg(col2, 13))) FROM t_array_long_1_3_through_4_6 +-- !query schema +struct +-- !query output +6 + + +-- !query +SELECT theta_sketch_estimate( + theta_intersection( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_int_1_5_through_7_11 +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT theta_sketch_estimate( + theta_intersection( + theta_sketch_agg(col1, 5), + theta_sketch_agg(col2, 12))) FROM t_long_1_5_through_7_11 +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT theta_sketch_estimate( + theta_intersection( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_double_1_1_1_4_through_1_5_1_8 +-- !query schema +struct +-- !query output +2 + + +-- !query +SELECT theta_sketch_estimate( + theta_intersection( + theta_sketch_agg(col1, 5), + theta_sketch_agg(col2))) FROM t_float_1_1_1_4_through_1_5_1_8 +-- !query schema +struct +-- !query output +2 + + +-- !query +SELECT theta_sketch_estimate( + theta_intersection( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_string_a_d_through_e_h +-- !query schema +struct +-- !query output +2 + + +-- !query +SELECT theta_sketch_estimate( + theta_intersection( + theta_sketch_agg(col1), + theta_sketch_agg(col2, 22))) FROM t_binary_a_b_through_e_f +-- !query schema +struct +-- !query output +4 + + +-- !query +SELECT theta_sketch_estimate( + theta_intersection( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_array_int_1_3_through_4_6 +-- !query schema +struct +-- !query output +2 + + +-- !query +SELECT theta_sketch_estimate( + theta_intersection( + theta_sketch_agg(col1), + theta_sketch_agg(col2, 10))) FROM t_array_long_1_3_through_4_6 +-- !query schema +struct +-- !query output +2 + + +-- !query +SELECT theta_sketch_estimate( + theta_difference( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_int_1_5_through_7_11 +-- !query schema +struct +-- !query output +4 + + +-- !query +SELECT theta_sketch_estimate( + theta_difference( + theta_sketch_agg(col1), + theta_sketch_agg(col2, 5))) FROM t_long_1_5_through_7_11 +-- !query schema +struct +-- !query output +4 + + +-- !query +SELECT theta_sketch_estimate( + theta_difference( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_double_1_1_1_4_through_1_5_1_8 +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT theta_sketch_estimate( + theta_difference( + theta_sketch_agg(col1, 12), + theta_sketch_agg(col2))) FROM t_float_1_1_1_4_through_1_5_1_8 +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT theta_sketch_estimate( + theta_difference( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_string_a_d_through_e_h +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT theta_sketch_estimate( + theta_difference( + theta_sketch_agg(col1, 6), + theta_sketch_agg(col2, 8))) FROM t_binary_a_b_through_e_f +-- !query schema +struct +-- !query output +1 + + +-- !query +SELECT theta_sketch_estimate( + theta_difference( + theta_sketch_agg(col1), + theta_sketch_agg(col2))) FROM t_array_int_1_3_through_4_6 +-- !query schema +struct +-- !query output +2 + + +-- !query +SELECT theta_sketch_estimate( + theta_difference( + theta_sketch_agg(col1), + theta_sketch_agg(col2, 4))) FROM t_array_long_1_3_through_4_6 +-- !query schema +struct +-- !query output +2 + + +-- !query +SELECT theta_sketch_estimate(theta_union_agg(sketch, 15)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_int_1_5_through_7_11 + UNION ALL + SELECT theta_sketch_agg(col2, 20) as sketch FROM t_int_1_5_through_7_11) +-- !query schema +struct +-- !query output +11 + + +-- !query +SELECT theta_sketch_estimate(theta_union_agg(sketch, 12)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_double_1_1_1_4_through_1_5_1_8 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_double_1_1_1_4_through_1_5_1_8) +-- !query schema +struct +-- !query output +8 + + +-- !query +SELECT theta_sketch_estimate(theta_union_agg(sketch, 14)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_string_a_d_through_e_h + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_string_a_d_through_e_h) +-- !query schema +struct +-- !query output +8 + + +-- !query +SELECT theta_sketch_estimate(theta_union_agg(sketch, 10)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_long_1_5_through_7_11 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_long_1_5_through_7_11) +-- !query schema +struct +-- !query output +11 + + +-- !query +SELECT theta_sketch_estimate(theta_union_agg(sketch, 6)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_float_1_1_1_4_through_1_5_1_8 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_float_1_1_1_4_through_1_5_1_8) +-- !query schema +struct +-- !query output +8 + + +-- !query +SELECT theta_sketch_estimate(theta_union_agg(sketch)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_binary_a_b_through_e_f + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_binary_a_b_through_e_f) +-- !query schema +struct +-- !query output +6 + + +-- !query +SELECT theta_sketch_estimate(theta_union_agg(sketch, 12)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_array_int_1_3_through_4_6 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_array_int_1_3_through_4_6) +-- !query schema +struct +-- !query output +6 + + +-- !query +SELECT theta_sketch_estimate(theta_union_agg(sketch, 16)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_array_long_1_3_through_4_6 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_array_long_1_3_through_4_6) +-- !query schema +struct +-- !query output +6 + + +-- !query +SELECT theta_sketch_estimate(theta_intersection_agg(sketch)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_int_1_5_through_7_11 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_int_1_5_through_7_11) +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT theta_sketch_estimate(theta_intersection_agg(sketch)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_long_1_5_through_7_11 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_long_1_5_through_7_11) +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT theta_sketch_estimate(theta_intersection_agg(sketch)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_float_1_1_1_4_through_1_5_1_8 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_float_1_1_1_4_through_1_5_1_8) +-- !query schema +struct +-- !query output +2 + + +-- !query +SELECT theta_sketch_estimate(theta_intersection_agg(sketch)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_double_1_1_1_4_through_1_5_1_8 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_double_1_1_1_4_through_1_5_1_8) +-- !query schema +struct +-- !query output +2 + + +-- !query +SELECT theta_sketch_estimate(theta_intersection_agg(sketch)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_string_a_d_through_e_h + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_string_a_d_through_e_h) +-- !query schema +struct +-- !query output +2 + + +-- !query +SELECT theta_sketch_estimate(theta_intersection_agg(sketch)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_binary_a_b_through_e_f + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_binary_a_b_through_e_f) +-- !query schema +struct +-- !query output +4 + + +-- !query +SELECT theta_sketch_estimate(theta_intersection_agg(sketch)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_array_int_1_3_through_4_6 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_array_int_1_3_through_4_6) +-- !query schema +struct +-- !query output +2 + + +-- !query +SELECT theta_sketch_estimate(theta_intersection_agg(sketch)) + FROM (SELECT theta_sketch_agg(col1) as sketch FROM t_array_long_1_3_through_4_6 + UNION ALL + SELECT theta_sketch_agg(col2) as sketch FROM t_array_long_1_3_through_4_6) +-- !query schema +struct +-- !query output +2 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES (1), (null), (2), (null), (3) tab(col) +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES ('test'), (null), ('null'), (null) tab(col) +-- !query schema +struct +-- !query output +2 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES (100L), (null), (200L), (null), (300L) tab(col) +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(CAST(col AS DOUBLE))) +FROM VALUES (1.1), (null), (2.2), (null), (3.3) tab(col) +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(CAST(col AS FLOAT))) +FROM VALUES (1.5), (null), (2.5), (null), (3.5) tab(col) +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES (X'AA'), (null), (X'BB'), (null), (X'CC') tab(col) +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES (ARRAY(1, 2)), (null), (ARRAY(3, 4)), (null), (ARRAY(5, 6)) tab(col) +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES (ARRAY(10L, 20L)), (null), (ARRAY(30L, 40L)), (null), (ARRAY(50L, 60L)) tab(col) +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES (ARRAY(1, null)), (ARRAY(1)), (ARRAY(2, null, 3)), (ARRAY(4)) tab(col) +-- !query schema +struct +-- !query output +4 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES (ARRAY(10L, null)), (ARRAY(10L)), (ARRAY(20L, null, 30L)), (ARRAY(40L)) tab(col) +-- !query schema +struct +-- !query output +4 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES (ARRAY()), (ARRAY(1, 2)), (ARRAY()), (ARRAY(3, 4)) tab(col) +-- !query schema +struct +-- !query output +2 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES (''), ('a'), (''), ('b'), ('c') tab(col) +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col)) +FROM VALUES (X''), (X'01'), (X'02'), (X'03'), (CAST(' ' AS BINARY)), (X'e280'), (X'c1'), (X'c120') tab(col) +-- !query schema +struct +-- !query output +7 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col1)) utf8_b FROM t_string_collation +-- !query schema +struct +-- !query output +10 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col1 COLLATE UTF8_LCASE)) utf8_lc FROM t_string_collation +-- !query schema +struct +-- !query output +7 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col1 COLLATE UNICODE)) unicode FROM t_string_collation +-- !query schema +struct +-- !query output +7 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col1 COLLATE UNICODE_CI)) unicode_ci FROM t_string_collation +-- !query schema +struct +-- !query output +6 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col1 COLLATE UTF8_BINARY_RTRIM)) utf8_b_rt FROM t_string_collation +-- !query schema +struct +-- !query output +6 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col1 COLLATE UTF8_LCASE_RTRIM)) utf8_lc_rt FROM t_string_collation +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col1 COLLATE UNICODE_RTRIM)) unicode_rt FROM t_string_collation +-- !query schema +struct +-- !query output +3 + + +-- !query +SELECT theta_sketch_estimate(theta_sketch_agg(col1 COLLATE UNICODE_CI_RTRIM)) unicode_ci_rt FROM t_string_collation +-- !query schema +struct +-- !query output +2 + + +-- !query +WITH sketches AS ( + SELECT 'int_sketch' as sketch_type, theta_sketch_agg(col1, 12) as sketch FROM t_int_1_5_through_7_11 + UNION ALL + SELECT 'long_sketch' as sketch_type, theta_sketch_agg(col1, 15) as sketch FROM t_long_1_5_through_7_11 + UNION ALL + SELECT 'double_sketch' as sketch_type, theta_sketch_agg(col1, 10) as sketch FROM t_double_1_1_1_4_through_1_5_1_8 + UNION ALL + SELECT 'string_sketch' as sketch_type, theta_sketch_agg(col1, 14) as sketch FROM t_string_a_d_through_e_h +), +union_result AS ( + SELECT theta_union_agg(sketch, 16) as union_sketch FROM sketches +), +individual_sketches AS ( + SELECT theta_sketch_agg(col1, 12) as sketch1, theta_sketch_agg(col2, 12) as sketch2 FROM t_int_1_5_through_7_11 +) +SELECT + theta_sketch_estimate((SELECT union_sketch FROM union_result)) as union_estimate, + theta_sketch_estimate(theta_union(sketch1, sketch2, 15)) as binary_union_estimate, + theta_sketch_estimate(theta_intersection(sketch1, sketch2)) as intersection_estimate, + theta_sketch_estimate(theta_difference(sketch1, sketch2)) as difference_estimate +FROM individual_sketches +-- !query schema +struct +-- !query output +17 11 3 4 + + +-- !query +SELECT theta_sketch_agg(col, 2) +FROM VALUES (50), (60), (60) 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" : "2" + } +} + + +-- !query +SELECT theta_sketch_agg(col, 40) +FROM VALUES (50), (60), (60) 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" : "40" + } +} + + +-- !query +SELECT theta_union_agg(sketch, 3) +FROM (SELECT theta_sketch_agg(col, 12) as sketch + FROM VALUES (1) AS tab(col) + UNION ALL + SELECT theta_sketch_agg(col, 20) as sketch + FROM VALUES (1) AS tab(col)) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "THETA_INVALID_LG_NOM_ENTRIES", + "sqlState" : "22546", + "messageParameters" : { + "function" : "`theta_union_agg`", + "max" : "26", + "min" : "4", + "value" : "3" + } +} + + +-- !query +SELECT theta_union_agg(sketch, 27) +FROM (SELECT theta_sketch_agg(col, 12) as sketch + FROM VALUES (1) AS tab(col) + UNION ALL + SELECT theta_sketch_agg(col, 20) as sketch + FROM VALUES (1) AS tab(col)) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "THETA_INVALID_LG_NOM_ENTRIES", + "sqlState" : "22546", + "messageParameters" : { + "function" : "`theta_union_agg`", + "max" : "26", + "min" : "4", + "value" : "27" + } +} + + +-- !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 + (1, 4), + (2, 5), + (3, 6) AS tab(col1, col2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"1\"", + "inputType" : "\"INT\"", + "paramIndex" : "first", + "requiredType" : "\"BINARY\"", + "sqlExpr" : "\"theta_union(1, 2, 12)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 24, + "fragment" : "theta_union(1, 2)" + } ] +} + + +-- !query +SELECT theta_intersection(1, 2) + FROM VALUES + (1, 4), + (2, 5), + (3, 6) AS tab(col1, col2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"1\"", + "inputType" : "\"INT\"", + "paramIndex" : "first", + "requiredType" : "\"BINARY\"", + "sqlExpr" : "\"theta_intersection(1, 2)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 31, + "fragment" : "theta_intersection(1, 2)" + } ] +} + + +-- !query +SELECT theta_difference(1, 2) + FROM VALUES + (1, 4), + (2, 5), + (3, 6) AS tab(col1, col2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"1\"", + "inputType" : "\"INT\"", + "paramIndex" : "first", + "requiredType" : "\"BINARY\"", + "sqlExpr" : "\"theta_difference(1, 2)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 29, + "fragment" : "theta_difference(1, 2)" + } ] +} + + +-- !query +SELECT theta_union( + theta_sketch_agg(col1), + theta_sketch_agg(col2), 'invalid') + FROM VALUES + (1, 4), + (2, 5), + (3, 6) AS tab(col1, col2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"invalid\"", + "inputType" : "\"STRING\"", + "paramIndex" : "third", + "requiredType" : "\"INT\"", + "sqlExpr" : "\"theta_union(theta_sketch_agg(col1, 12), theta_sketch_agg(col2, 12), invalid)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 86, + "fragment" : "theta_union(\n theta_sketch_agg(col1),\n theta_sketch_agg(col2), 'invalid')" + } ] +} + + +-- !query +SELECT theta_intersection( + theta_sketch_agg(col1), + 'invalid_sketch') + FROM VALUES + (1, 4), + (2, 5), + (3, 6) AS tab(col1, col2) +-- !query schema +struct<> +-- !query output +org.apache.spark.sql.catalyst.ExtendedAnalysisException +{ + "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE", + "sqlState" : "42K09", + "messageParameters" : { + "inputSql" : "\"invalid_sketch\"", + "inputType" : "\"STRING\"", + "paramIndex" : "second", + "requiredType" : "\"BINARY\"", + "sqlExpr" : "\"theta_intersection(theta_sketch_agg(col1, 12), invalid_sketch)\"" + }, + "queryContext" : [ { + "objectType" : "", + "objectName" : "", + "startIndex" : 8, + "stopIndex" : 76, + "fragment" : "theta_intersection(\n theta_sketch_agg(col1),\n 'invalid_sketch')" + } ] +} + + +-- !query +SELECT theta_sketch_estimate(CAST('abc' AS BINARY)) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "THETA_INVALID_INPUT_SKETCH_BUFFER", + "sqlState" : "22546", + "messageParameters" : { + "function" : "`theta_sketch_estimate`" + } +} + + +-- !query +SELECT theta_union(CAST('abc' AS BINARY), CAST('def' AS BINARY)) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "THETA_INVALID_INPUT_SKETCH_BUFFER", + "sqlState" : "22546", + "messageParameters" : { + "function" : "`theta_union`" + } +} + + +-- !query +SELECT theta_intersection(CAST('abc' AS BINARY), CAST('def' AS BINARY)) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "THETA_INVALID_INPUT_SKETCH_BUFFER", + "sqlState" : "22546", + "messageParameters" : { + "function" : "`theta_intersection`" + } +} + + +-- !query +SELECT theta_difference(CAST('abc' AS BINARY), CAST('def' AS BINARY)) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "THETA_INVALID_INPUT_SKETCH_BUFFER", + "sqlState" : "22546", + "messageParameters" : { + "function" : "`theta_difference`" + } +} + + +-- !query +SELECT theta_union_agg(buffer, 15) +FROM (SELECT CAST('abc' AS BINARY) AS buffer) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "THETA_INVALID_INPUT_SKETCH_BUFFER", + "sqlState" : "22546", + "messageParameters" : { + "function" : "`theta_union_agg`" + } +} + + +-- !query +SELECT theta_intersection_agg(buffer) +FROM (SELECT CAST('abc' AS BINARY) AS buffer) +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkRuntimeException +{ + "errorClass" : "THETA_INVALID_INPUT_SKETCH_BUFFER", + "sqlState" : "22546", + "messageParameters" : { + "function" : "`theta_intersection_agg`" + } +} + + +-- !query +DROP TABLE IF EXISTS t_int_1_5_through_7_11 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_long_1_5_through_7_11 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_double_1_1_1_4_through_1_5_1_8 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_float_1_1_1_4_through_1_5_1_8 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_string_a_d_through_e_h +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_binary_a_b_through_e_f +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_array_int_1_3_through_4_6 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_array_long_1_3_through_4_6 +-- !query schema +struct<> +-- !query output + + + +-- !query +DROP TABLE IF EXISTS t_string_collation +-- !query schema +struct<> +-- !query output + diff --git a/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/time.sql.out b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/time.sql.out new file mode 100644 index 00000000000..2908f266dc9 --- /dev/null +++ b/gluten-ut/spark41/src/test/resources/backends-velox/sql-tests/results/time.sql.out @@ -0,0 +1,2379 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +create temporary view timediff_view as select time'01:02:03' time_start, time'04:05:06' time_end, 'SECOND' unit +-- !query schema +struct<> +-- !query output + + + +-- !query +create temporary view time_view as select '11:53:26.038344' time_str, 'HH:mm:ss.SSSSSS' fmt_str +-- !query schema +struct<> +-- !query output + + + +-- !query +create temporary view trunc_time_view as select time'11:53:26.038344' time_val, 'MINUTE' unit +-- !query schema +struct<> +-- !query output + + + +-- !query +select time '16:39:45\t' +-- !query schema +struct