[
https://issues.apache.org/jira/browse/BEAM-8993?focusedWorklogId=367845&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-367845
]
ASF GitHub Bot logged work on BEAM-8993:
----------------------------------------
Author: ASF GitHub Bot
Created on: 07/Jan/20 22:54
Start Date: 07/Jan/20 22:54
Worklog Time Spent: 10m
Work Description: TheNeuralBit commented on pull request #10417:
[BEAM-8993] [SQL] MongoDB predicate push down.
URL: https://github.com/apache/beam/pull/10417#discussion_r363951251
##########
File path:
sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/meta/provider/mongodb/MongoDbFilterTest.java
##########
@@ -0,0 +1,127 @@
+/*
+ * 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.beam.sdk.extensions.sql.meta.provider.mongodb;
+
+import static
org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider.PUSH_DOWN_OPTION;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+
+import com.alibaba.fastjson.JSON;
+import org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair;
+import org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv;
+import org.apache.beam.sdk.extensions.sql.impl.rel.BeamCalcRel;
+import org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode;
+import org.apache.beam.sdk.extensions.sql.meta.Table;
+import org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider;
+import
org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider.PushDownOptions;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.values.Row;
+import
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class MongoDbFilterTest {
+ private static final Schema BASIC_SCHEMA =
+ Schema.builder()
+ .addInt32Field("unused1")
+ .addInt32Field("id")
+ .addStringField("name")
+ .addInt16Field("unused2")
+ .addBooleanField("b")
+ .build();
+
+ private BeamSqlEnv sqlEnv;
+
+ @Rule public TestPipeline pipeline = TestPipeline.create();
+
+ @Before
+ public void buildUp() {
+ TestTableProvider tableProvider = new TestTableProvider();
+ Table table = getTable("TEST", PushDownOptions.NONE);
+ tableProvider.createTable(table);
+ tableProvider.addRows(
+ table.getName(),
+ row(BASIC_SCHEMA, 100, 1, "one", (short) 100, true),
+ row(BASIC_SCHEMA, 200, 2, "two", (short) 200, false));
+
+ sqlEnv =
+ BeamSqlEnv.builder(tableProvider)
+ .setPipelineOptions(PipelineOptionsFactory.create())
+ .build();
+ }
+
+ @Test
+ public void testIsSupported() {
+ ImmutableList<Pair<String, Boolean>> sqlQueries =
+ ImmutableList.of(
+ Pair.of("select * from TEST where unused1=100", true),
+ Pair.of("select * from TEST where unused1 in (100, 200)", true),
+ Pair.of("select * from TEST where b", true),
+ Pair.of("select * from TEST where not b", true),
+ // Nested conjunction and disjunction is supported as long as
child operations are
+ // supported.
+ Pair.of(
+ "select * from TEST where unused1>100 and unused1<=200 and
id<>1 and (name='two' or id=2)",
+ true),
+ // RegEx matching push-down is not implemented at the moment.
+ Pair.of("select * from TEST where name like 'o%e'", false),
+ // Complex operations, which modify a field before a comparison
are not supported.
+ Pair.of("select * from TEST where unused1+10=110", false),
+ // Since unused2 is of type `short`, it will be cast to int32,
making this a complex
+ // operation.
+ Pair.of("select * from TEST where unused2=200", false),
+ // Operations involving more than one column are not supported yet.
+ Pair.of("select * from TEST where unused1=unused2 and id=2",
false),
+ Pair.of("select * from TEST where unused1+unused2=10", false));
Review comment:
You might consider making this a parameterized test instead, up to you
though.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 367845)
Time Spent: 0.5h (was: 20m)
> [SQL] MongoDb should use predicate push-down
> --------------------------------------------
>
> Key: BEAM-8993
> URL: https://issues.apache.org/jira/browse/BEAM-8993
> Project: Beam
> Issue Type: Improvement
> Components: dsl-sql
> Reporter: Kirill Kozlov
> Assignee: Kirill Kozlov
> Priority: Major
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> * Add a MongoDbFilter class, implementing BeamSqlTableFilter.
> ** Support simple comparison operations.
> ** Support boolean field.
> ** Support nested conjunction/disjunction.
> * Update MongoDbTable#buildIOReader
> ** Construct a push-down filter from RexNodes.
> ** Set filter to FindQuery.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)