>From Wail Alkowaileet <[email protected]>: Wail Alkowaileet has submitted this change. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17924 )
Change subject: [ASTERIXDB-3300][RT][COMP] Support boolean in range columnar filters ...................................................................... [ASTERIXDB-3300][RT][COMP] Support boolean in range columnar filters - user model changes: no - storage format changes: no - interface changes: no Details: Add support to ramge filter using boolean values. Change-Id: Ib9e68cc2ec2d868c85192c9dc0ed3d6799c54343 Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17924 Integration-Tests: Jenkins <[email protected]> Tested-by: Jenkins <[email protected]> Reviewed-by: Wail Alkowaileet <[email protected]> Reviewed-by: Ali Alsuliman <[email protected]> --- A asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.010.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.040.adm A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.031.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.005.get.http A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.020.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.001.ddl.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.040.query.sqlpp M asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/accessor/ConstantColumnRangeFilterValueAccessorFactory.java M asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ColumnRangeFilterPushdownProcessor.java A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.030.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.011.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.003.regexadm A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.002.update.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.020.adm A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.004.update.sqlpp M asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/filter/ColumnRangeFilterBuilder.java A asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.021.adm M asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/PushdownUtil.java A asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.005.regexadm M asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.003.get.http A asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.030.adm M asterixdb/asterix-app/src/test/java/org/apache/asterix/test/runtime/SqlppAnalyzedExecutionTest.java A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.010.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.021.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.011.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.031.adm 27 files changed, 485 insertions(+), 19 deletions(-) Approvals: Wail Alkowaileet: Looks good to me, but someone else must approve Ali Alsuliman: Looks good to me, approved Jenkins: Verified; Verified Objections: Anon. E. Moose #1000171: Violations found diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ColumnRangeFilterPushdownProcessor.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ColumnRangeFilterPushdownProcessor.java index 65145a6..a9dcfc1 100644 --- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ColumnRangeFilterPushdownProcessor.java +++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ColumnRangeFilterPushdownProcessor.java @@ -18,6 +18,7 @@ */ package org.apache.asterix.optimizer.rules.pushdown.processor; +import static org.apache.asterix.column.filter.range.accessor.ConstantColumnRangeFilterValueAccessorFactory.SUPPORTED_CONSTANT_TYPES; import static org.apache.asterix.metadata.utils.PushdownUtil.RANGE_FILTER_PUSHABLE_FUNCTIONS; import static org.apache.asterix.metadata.utils.PushdownUtil.isConstant; import static org.apache.asterix.metadata.utils.PushdownUtil.isFilterPath; @@ -29,6 +30,7 @@ import org.apache.asterix.common.config.DatasetConfig; import org.apache.asterix.metadata.entities.Dataset; import org.apache.asterix.metadata.utils.DatasetUtil; +import org.apache.asterix.om.base.ABoolean; import org.apache.asterix.om.base.IAObject; import org.apache.asterix.om.constants.AsterixConstantValue; import org.apache.asterix.om.types.ARecordType; @@ -99,10 +101,18 @@ } @Override - protected boolean handlePath(AbstractFunctionCallExpression expression) { + protected boolean handlePath(AbstractFunctionCallExpression expression) throws AlgebricksException { // This means we got something like WHERE $r.getField("isVerified") -- where isVerified is a boolean field. - // Boolean range filters are not supported currently - return false; + AnyExpectedSchemaNode node = getNode(expression); + IAObject constantValue = ABoolean.TRUE; + String functionName = expression.getFunctionIdentifier().getName(); + SourceLocation sourceLocation = expression.getSourceLocation(); + FunctionCallInformation functionCallInfo = new FunctionCallInformation(functionName, sourceLocation, + ProjectionFiltrationWarningFactoryProvider.getIncomparableTypesFactory(false)); + ARecordType path = + pathBuilderVisitor.buildPath(node, constantValue.getType(), sourceInformationMap, functionCallInfo); + paths.put(expression, path); + return true; } @Override @@ -116,14 +126,13 @@ } scanDefineDescriptor.getFilterPaths().putAll(paths); scanDefineDescriptor.getPathLocations().putAll(sourceInformationMap); - } private boolean pushdownRangeFilter(ILogicalExpression pathExpr, ILogicalExpression constExpr, AbstractFunctionCallExpression funcExpr, boolean leftConstant) throws AlgebricksException { AnyExpectedSchemaNode node = getNode(pathExpr); IAObject constantValue = ((AsterixConstantValue) ((ConstantExpression) constExpr).getValue()).getObject(); - if (node == null || constantValue.getType().getTypeTag().isDerivedType()) { + if (node == null || !SUPPORTED_CONSTANT_TYPES.contains(constantValue.getType().getTypeTag())) { return false; } String functionName = funcExpr.getFunctionIdentifier().getName(); diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/runtime/SqlppAnalyzedExecutionTest.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/runtime/SqlppAnalyzedExecutionTest.java index 10a22b4..2f3007d 100644 --- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/runtime/SqlppAnalyzedExecutionTest.java +++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/runtime/SqlppAnalyzedExecutionTest.java @@ -45,7 +45,7 @@ protected static final String TEST_CONFIG_FILE_NAME = "src/test/resources/cc-analyze.conf"; private final String[] denyList = { "synonym: synonym-01", "ddl: analyze-dataset-1", "misc: dump_index", "array-index: composite-index-queries", "filters: upsert", "column: analyze-dataset", - "ddl: analyze-dataset-with-indexes", "warnings: cardinality-hint-warning" }; + "column: filter/boolean", "ddl: analyze-dataset-with-indexes", "warnings: cardinality-hint-warning" }; @BeforeClass public static void setUp() throws Exception { diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.001.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.001.ddl.sqlpp new file mode 100644 index 0000000..a271778 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.001.ddl.sqlpp @@ -0,0 +1,31 @@ +/* + * 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. + */ + +DROP DATAVERSE test if exists; +CREATE DATAVERSE test; +USE test; + +CREATE TYPE ColumnType AS { + id: int +}; + +CREATE DATASET ColumnDataset(ColumnType) +PRIMARY KEY id WITH { + "storage-format": {"format" : "column"} +}; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.002.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.002.update.sqlpp new file mode 100644 index 0000000..cfaea2d --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.002.update.sqlpp @@ -0,0 +1,26 @@ +/* + * 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. + */ + +USE test; + +INSERT INTO ColumnDataset ( + {"id": 1, "a": "1", "array": [10, 20, 30], "myBoolean": false}, + {"id": 2, "a": "2", "array": [40, 50, 60], "myBoolean": false}, + {"id": 3, "a": "3", "array": [70, 80, 90], "myBoolean": false} +); \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.003.get.http b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.003.get.http new file mode 100644 index 0000000..57d830a --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.003.get.http @@ -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. + */ +/connector?dataverseName=test&datasetName=ColumnDataset \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.004.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.004.update.sqlpp new file mode 100644 index 0000000..724aff3 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.004.update.sqlpp @@ -0,0 +1,26 @@ +/* + * 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. + */ + +USE test; + +INSERT INTO ColumnDataset ( + {"id": 4, "a": "1", "array": [10, 20, 30], "myBoolean": true}, + {"id": 5, "a": "2", "array": [40, 50, 60], "myBoolean": true}, + {"id": 6, "a": "3", "array": [70, 80, 90], "myBoolean": true} +); \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.005.get.http b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.005.get.http new file mode 100644 index 0000000..57d830a --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.005.get.http @@ -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. + */ +/connector?dataverseName=test&datasetName=ColumnDataset \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.010.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.010.query.sqlpp new file mode 100644 index 0000000..a1cfa75 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.010.query.sqlpp @@ -0,0 +1,28 @@ +/* + * 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. + */ + +USE test; +SET `compiler.column.filter` "true"; + + + +SELECT VALUE d.id +FROM ColumnDataset d +WHERE d.myBoolean +ORDER BY d.id; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.011.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.011.query.sqlpp new file mode 100644 index 0000000..0c5c396 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.011.query.sqlpp @@ -0,0 +1,28 @@ +/* + * 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. + */ + +USE test; +SET `compiler.column.filter` "true"; +SET `compiler.parallelism` "0"; +SET `compiler.sort.parallel` "false"; +EXPLAIN +SELECT VALUE d.id +FROM ColumnDataset d +WHERE d.myBoolean +ORDER BY d.id; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.020.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.020.query.sqlpp new file mode 100644 index 0000000..40b908c --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.020.query.sqlpp @@ -0,0 +1,28 @@ +/* + * 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. + */ + +USE test; +SET `compiler.column.filter` "true"; + + + +SELECT VALUE d.id +FROM ColumnDataset d +WHERE NOT d.myBoolean +ORDER BY d.id; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.021.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.021.query.sqlpp new file mode 100644 index 0000000..ed4e178 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.021.query.sqlpp @@ -0,0 +1,28 @@ +/* + * 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. + */ + +USE test; +SET `compiler.column.filter` "true"; +SET `compiler.parallelism` "0"; +SET `compiler.sort.parallel` "false"; +EXPLAIN +SELECT VALUE d.id +FROM ColumnDataset d +WHERE NOT d.myBoolean +ORDER BY d.id; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.030.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.030.query.sqlpp new file mode 100644 index 0000000..1e088ae --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.030.query.sqlpp @@ -0,0 +1,28 @@ +/* + * 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. + */ + +USE test; +SET `compiler.column.filter` "true"; + + + +SELECT VALUE d.id +FROM ColumnDataset d +WHERE d.myBoolean = true +ORDER BY d.id; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.031.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.031.query.sqlpp new file mode 100644 index 0000000..a854a9f --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.031.query.sqlpp @@ -0,0 +1,28 @@ +/* + * 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. + */ + +USE test; +SET `compiler.column.filter` "true"; +SET `compiler.parallelism` "0"; +SET `compiler.sort.parallel` "false"; +EXPLAIN +SELECT VALUE d.id +FROM ColumnDataset d +WHERE d.myBoolean = true +ORDER BY d.id; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.040.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.040.query.sqlpp new file mode 100644 index 0000000..15eaa2e --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/boolean/boolean.040.query.sqlpp @@ -0,0 +1,28 @@ +/* + * 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. + */ +// param max-warnings:json=1 +USE test; +SET `compiler.column.filter` "true"; + + + +SELECT VALUE d.id +FROM ColumnDataset d +WHERE d.array +ORDER BY d.id; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.003.regexadm b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.003.regexadm new file mode 100644 index 0000000..81882d4 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.003.regexadm @@ -0,0 +1 @@ +\Q{"keys":"id","type":{"type":"org.apache.asterix.om.types.ARecordType","name":"ColumnType","open":true,"fields":[{"id":{"type":"AInt64"}}]},"splits":[\E.*\Q]}\E \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.005.regexadm b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.005.regexadm new file mode 100644 index 0000000..81882d4 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.005.regexadm @@ -0,0 +1 @@ +\Q{"keys":"id","type":{"type":"org.apache.asterix.om.types.ARecordType","name":"ColumnType","open":true,"fields":[{"id":{"type":"AInt64"}}]},"splits":[\E.*\Q]}\E \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.010.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.010.adm new file mode 100644 index 0000000..4578bc1 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.010.adm @@ -0,0 +1,3 @@ +4 +5 +6 diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.011.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.011.adm new file mode 100644 index 0000000..7a91cf0 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.011.adm @@ -0,0 +1,20 @@ +distribute result [$$17] [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] +-- DISTRIBUTE_RESULT |PARTITIONED| + exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- SORT_MERGE_EXCHANGE [$$17(ASC) ] |PARTITIONED| + order (ASC, $$17) [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- STABLE_SORT [$$17(ASC)] |PARTITIONED| + exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + project ([$$17]) [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- STREAM_PROJECT |PARTITIONED| + select ($$d.getField("myBoolean")) [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- STREAM_SELECT |PARTITIONED| + exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + data-scan []<-[$$17, $$d] <- test.ColumnDataset project ({myBoolean:any}) filter on: $$d.getField("myBoolean") range-filter on: $$d.getField("myBoolean") [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- DATASOURCE_SCAN |PARTITIONED| + exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + empty-tuple-source [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- EMPTY_TUPLE_SOURCE |PARTITIONED| diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.020.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.020.adm new file mode 100644 index 0000000..01e79c3 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.020.adm @@ -0,0 +1,3 @@ +1 +2 +3 diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.021.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.021.adm new file mode 100644 index 0000000..69a65e1 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.021.adm @@ -0,0 +1,20 @@ +distribute result [$$18] [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] +-- DISTRIBUTE_RESULT |PARTITIONED| + exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- SORT_MERGE_EXCHANGE [$$18(ASC) ] |PARTITIONED| + order (ASC, $$18) [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- STABLE_SORT [$$18(ASC)] |PARTITIONED| + exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + project ([$$18]) [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- STREAM_PROJECT |PARTITIONED| + select (not($$d.getField("myBoolean"))) [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- STREAM_SELECT |PARTITIONED| + exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + data-scan []<-[$$18, $$d] <- test.ColumnDataset project ({myBoolean:any}) filter on: not($$d.getField("myBoolean")) range-filter on: not($$d.getField("myBoolean")) [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- DATASOURCE_SCAN |PARTITIONED| + exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + empty-tuple-source [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- EMPTY_TUPLE_SOURCE |PARTITIONED| diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.030.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.030.adm new file mode 100644 index 0000000..4578bc1 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.030.adm @@ -0,0 +1,3 @@ +4 +5 +6 diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.031.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.031.adm new file mode 100644 index 0000000..a6cf89a --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.031.adm @@ -0,0 +1,20 @@ +distribute result [$$18] [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] +-- DISTRIBUTE_RESULT |PARTITIONED| + exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- SORT_MERGE_EXCHANGE [$$18(ASC) ] |PARTITIONED| + order (ASC, $$18) [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- STABLE_SORT [$$18(ASC)] |PARTITIONED| + exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + project ([$$18]) [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- STREAM_PROJECT |PARTITIONED| + select (eq($$d.getField("myBoolean"), true)) [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- STREAM_SELECT |PARTITIONED| + exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + data-scan []<-[$$18, $$d] <- test.ColumnDataset project ({myBoolean:any}) filter on: eq($$d.getField("myBoolean"), true) range-filter on: eq($$d.getField("myBoolean"), true) [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- DATASOURCE_SCAN |PARTITIONED| + exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + empty-tuple-source [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- EMPTY_TUPLE_SOURCE |PARTITIONED| diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.040.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.040.adm new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/boolean/boolean.040.adm diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml index ef4a09b..b82481d 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml @@ -16311,6 +16311,12 @@ <output-dir compare="Text">filter/007</output-dir> </compilation-unit> </test-case> + <test-case FilePath="column" check-warnings="true"> + <compilation-unit name="filter/boolean"> + <output-dir compare="Text">filter/boolean</output-dir> + <expected-warn>ASX0051: Incomparable input types: array and boolean (in line 27, at column 8)</expected-warn> + </compilation-unit> + </test-case> <test-case FilePath="column"> <compilation-unit name="filter/not-in_every"> <output-dir compare="Text">filter/not-in_every</output-dir> diff --git a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/accessor/ConstantColumnRangeFilterValueAccessorFactory.java b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/accessor/ConstantColumnRangeFilterValueAccessorFactory.java index 4d2c198..f493c94 100644 --- a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/accessor/ConstantColumnRangeFilterValueAccessorFactory.java +++ b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/filter/range/accessor/ConstantColumnRangeFilterValueAccessorFactory.java @@ -18,9 +18,12 @@ */ package org.apache.asterix.column.filter.range.accessor; +import java.util.Set; + import org.apache.asterix.column.filter.FilterAccessorProvider; import org.apache.asterix.column.filter.range.IColumnRangeFilterValueAccessor; import org.apache.asterix.column.filter.range.IColumnRangeFilterValueAccessorFactory; +import org.apache.asterix.om.base.ABoolean; import org.apache.asterix.om.base.ADouble; import org.apache.asterix.om.base.AInt64; import org.apache.asterix.om.base.AString; @@ -30,21 +33,37 @@ public class ConstantColumnRangeFilterValueAccessorFactory implements IColumnRangeFilterValueAccessorFactory { private static final long serialVersionUID = -4835407779342615453L; + public static final Set<ATypeTag> SUPPORTED_CONSTANT_TYPES; private final long normalizedValue; private final ATypeTag typeTag; private final String stringValue; + static { + SUPPORTED_CONSTANT_TYPES = Set.of(ATypeTag.BOOLEAN, ATypeTag.BIGINT, ATypeTag.DOUBLE, ATypeTag.STRING); + } + private ConstantColumnRangeFilterValueAccessorFactory(String stringValue, long normalizedValue, ATypeTag typeTag) { this.stringValue = stringValue; this.normalizedValue = normalizedValue; this.typeTag = typeTag; } + /** + * Create a constant accessor + * + * @param value constant value + * @return constant accessor factory if supported, null otherwise + */ public static ConstantColumnRangeFilterValueAccessorFactory createFactory(IAObject value) { String stringValue; long normalizedValue; ATypeTag typeTag = value.getType().getTypeTag(); switch (typeTag) { + case BOOLEAN: + boolean booleanVal = ((ABoolean) value).getBoolean(); + stringValue = Boolean.toString(booleanVal); + normalizedValue = booleanVal ? 1 : 0; + break; case BIGINT: long longVal = ((AInt64) value).getLongValue(); stringValue = Long.toString(longVal); diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/PushdownUtil.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/PushdownUtil.java index 90bd3aa..7daef5c 100644 --- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/PushdownUtil.java +++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/PushdownUtil.java @@ -92,6 +92,11 @@ return BuiltinFunctions.OR.equals(fid); } + public static boolean isNot(ILogicalExpression expression) { + FunctionIdentifier fid = getFunctionIdentifier(expression); + return BuiltinFunctions.NOT.equals(fid); + } + public static AOrderedList getArrayConstantFromScanCollection(ILogicalExpression expression) { FunctionIdentifier fid = getFunctionIdentifier(expression); if (!BuiltinFunctions.SCAN_COLLECTION.equals(fid)) { @@ -192,6 +197,7 @@ Set<FunctionIdentifier> pushableFunctions = new HashSet<>(COMPARE_FUNCTIONS); pushableFunctions.add(AlgebricksBuiltinFunctions.AND); pushableFunctions.add(AlgebricksBuiltinFunctions.OR); + pushableFunctions.add(AlgebricksBuiltinFunctions.NOT); return pushableFunctions; } } diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/filter/ColumnRangeFilterBuilder.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/filter/ColumnRangeFilterBuilder.java index f83b484..894394e 100644 --- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/filter/ColumnRangeFilterBuilder.java +++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/filter/ColumnRangeFilterBuilder.java @@ -20,6 +20,8 @@ import static org.apache.asterix.metadata.utils.PushdownUtil.isCompare; import static org.apache.asterix.metadata.utils.PushdownUtil.isConstant; +import static org.apache.asterix.metadata.utils.PushdownUtil.isFilterPath; +import static org.apache.asterix.metadata.utils.PushdownUtil.isNot; import static org.apache.hyracks.algebricks.core.algebra.functions.AlgebricksBuiltinFunctions.ComparisonKind; import java.util.List; @@ -36,6 +38,7 @@ import org.apache.asterix.column.filter.range.compartor.LTColumnFilterEvaluatorFactory; import org.apache.asterix.column.filter.range.evaluator.ANDColumnFilterEvaluatorFactory; import org.apache.asterix.column.filter.range.evaluator.ORColumnFilterEvaluatorFactory; +import org.apache.asterix.om.base.ABoolean; import org.apache.asterix.om.base.IAObject; import org.apache.asterix.om.constants.AsterixConstantValue; import org.apache.asterix.om.functions.BuiltinFunctions; @@ -71,26 +74,40 @@ ILogicalExpression filterExpression) { AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) filterExpression; - if (isCompare(funcExpr)) { + if (isFilterPath(funcExpr) || isNot(funcExpr)) { + return createBooleanEvaluator(funcExpr, filterPaths); + } else if (isCompare(funcExpr)) { return createComparator(funcExpr.getFunctionIdentifier(), funcExpr.getArguments(), filterPaths); } return createEvaluatorsForArgs(funcExpr, filterPaths); } + private IColumnRangeFilterEvaluatorFactory createBooleanEvaluator(AbstractFunctionCallExpression funcExpr, + Map<ILogicalExpression, ARecordType> filterPaths) { + boolean not = isNot(funcExpr); + IAObject constVal = not ? ABoolean.FALSE : ABoolean.TRUE; + ILogicalExpression pathExpr = not ? funcExpr.getArguments().get(0).getValue() : funcExpr; + ARecordType path = filterPaths.get(pathExpr); + + return createComparator(BuiltinFunctions.EQ, path, constVal, true); + } + private IColumnRangeFilterEvaluatorFactory createComparator(FunctionIdentifier fid, List<Mutable<ILogicalExpression>> arguments, Map<ILogicalExpression, ARecordType> filterPaths) { ILogicalExpression left = arguments.get(0).getValue(); ILogicalExpression right = arguments.get(1).getValue(); - - if (isConstant(right)) { - ARecordType path = filterPaths.get(left); - IAObject constant = getConstant(right); - return createComparator(fid, path, constant, true); + boolean rightConstant = isConstant(right); + ARecordType path; + IAObject constant; + if (rightConstant) { + path = filterPaths.get(left); + constant = getConstant(right); } else { - ARecordType path = filterPaths.get(right); - IAObject constant = getConstant(left); - return createComparator(fid, path, constant, false); + path = filterPaths.get(right); + constant = getConstant(left); } + + return createComparator(fid, path, constant, rightConstant); } private IColumnRangeFilterEvaluatorFactory createEvaluatorsForArgs(AbstractFunctionCallExpression funcExpr, @@ -112,8 +129,10 @@ private IColumnRangeFilterEvaluatorFactory createComparator(FunctionIdentifier fid, ARecordType path, IAObject constant, boolean rightConstant) { - if (path == null) { - // skipped path + IColumnRangeFilterValueAccessorFactory constValue = + ConstantColumnRangeFilterValueAccessorFactory.createFactory(constant); + if (path == null || constValue == null) { + // Skipped paths or unsupported constants. return NoOpColumnFilterEvaluatorFactory.INSTANCE; } @@ -123,8 +142,6 @@ return NoOpColumnFilterEvaluatorFactory.INSTANCE; } - IColumnRangeFilterValueAccessorFactory constValue = - ConstantColumnRangeFilterValueAccessorFactory.createFactory(constant); IColumnRangeFilterValueAccessorFactory min = new ColumnRangeFilterValueAccessorFactory(path, true); IColumnRangeFilterValueAccessorFactory max = new ColumnRangeFilterValueAccessorFactory(path, false); -- To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17924 To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Change-Id: Ib9e68cc2ec2d868c85192c9dc0ed3d6799c54343 Gerrit-Change-Number: 17924 Gerrit-PatchSet: 2 Gerrit-Owner: Wail Alkowaileet <[email protected]> Gerrit-Reviewer: Ali Alsuliman <[email protected]> Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Wail Alkowaileet <[email protected]> Gerrit-MessageType: merged
