[
https://issues.apache.org/jira/browse/BEAM-8993?focusedWorklogId=370043&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-370043
]
ASF GitHub Bot logged work on BEAM-8993:
----------------------------------------
Author: ASF GitHub Bot
Created on: 10/Jan/20 20:10
Start Date: 10/Jan/20 20:10
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_r365410980
##########
File path:
sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/meta/provider/mongodb/MongoDbFilterTest.java
##########
@@ -0,0 +1,126 @@
+/*
+ * 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 java.util.Arrays;
+import java.util.Collection;
+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.mongodb.MongoDbTable.MongoDbFilter;
+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.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.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;
+
+ @Parameters
+ public static Collection<Object[]> data() {
+ return Arrays.asList(
+ new Object[][] {
+ {"select * from TEST where unused1=100", true},
+ {"select * from TEST where unused1 in (100, 200)", true},
+ {"select * from TEST where b", true},
+ {"select * from TEST where not b", true},
+ {
+ "select * from TEST where unused1>100 and unused1<=200 and id<>1
and (name='two' or id=2)",
+ true
+ },
+ {"select * from TEST where name like 'o%e'", false},
+ {"select * from TEST where unused1+10=110", false},
+ {"select * from TEST where unused1=unused2 and id=2", false},
+ {"select * from TEST where unused1+unused2=10", false}
+ });
+ }
+
+ @Parameter public String query;
+
+ @Parameter(1)
+ public boolean isSupported;
+
+ @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() {
+ BeamRelNode beamRelNode = sqlEnv.parseQuery(query);
+ assertThat(beamRelNode, instanceOf(BeamCalcRel.class));
+ MongoDbFilter filter =
+ MongoDbFilter.create(((BeamCalcRel)
beamRelNode).getProgram().split().right);
Review comment:
Doesn't necessarily need to be changed now, but I was envisioning that this
would be tested through the public API, `MongoDbTable#createFilter`, and that
MongoDbFilter could be private.
----------------------------------------------------------------
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: 370043)
Time Spent: 3h 50m (was: 3h 40m)
> [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: 3h 50m
> 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)