[
https://issues.apache.org/jira/browse/DRILL-5977?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16518657#comment-16518657
]
ASF GitHub Bot commented on DRILL-5977:
---------------------------------------
aravi5 commented on a change in pull request #1272: DRILL-5977: Filter Pushdown
in Drill-Kafka plugin
URL: https://github.com/apache/drill/pull/1272#discussion_r196958291
##########
File path:
contrib/storage-kafka/src/main/java/org/apache/drill/exec/store/kafka/KafkaNodeProcessor.java
##########
@@ -0,0 +1,186 @@
+/*
+ * 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.drill.exec.store.kafka;
+
+import org.apache.drill.common.expression.FunctionCall;
+import org.apache.drill.common.expression.LogicalExpression;
+import org.apache.drill.common.expression.SchemaPath;
+import org.apache.drill.common.expression.ValueExpressions.BooleanExpression;
+import org.apache.drill.common.expression.ValueExpressions.DateExpression;
+import org.apache.drill.common.expression.ValueExpressions.DoubleExpression;
+import org.apache.drill.common.expression.ValueExpressions.FloatExpression;
+import org.apache.drill.common.expression.ValueExpressions.IntExpression;
+import org.apache.drill.common.expression.ValueExpressions.LongExpression;
+import org.apache.drill.common.expression.ValueExpressions.QuotedString;
+import org.apache.drill.common.expression.ValueExpressions.TimeExpression;
+import org.apache.drill.common.expression.ValueExpressions.TimeStampExpression;
+import org.apache.drill.common.expression.visitors.AbstractExprVisitor;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+
+class KafkaNodeProcessor extends AbstractExprVisitor<Boolean,
LogicalExpression, RuntimeException> {
+
+ private String functionName;
+ private Boolean success;
+ private Long value;
+ private String path;
+
+ public KafkaNodeProcessor(String functionName) {
+ this.functionName = functionName;
+ this.success = false;
+ }
+
+ public static boolean isPushdownFunction(String functionName) {
+ return COMPARE_FUNCTIONS_TRANSPOSE_MAP.keySet().contains(functionName);
+ }
+
+ @Override
+ public Boolean visitUnknown(LogicalExpression e, LogicalExpression valueArg)
throws RuntimeException {
+ return false;
+ }
+
+ public static KafkaNodeProcessor process(FunctionCall call) {
+ String functionName = call.getName();
+ LogicalExpression nameArg = call.args.get(0);
+ LogicalExpression valueArg = call.args.size() >= 2? call.args.get(1) :
null;
+ KafkaNodeProcessor evaluator = new KafkaNodeProcessor(functionName);
+
+ if (VALUE_EXPRESSION_CLASSES.contains(nameArg.getClass())) {
+ LogicalExpression swapArg = valueArg;
+ valueArg = nameArg;
+ nameArg = swapArg;
+ evaluator.functionName =
COMPARE_FUNCTIONS_TRANSPOSE_MAP.get(functionName);
+ }
+ evaluator.success = nameArg.accept(evaluator, valueArg);
+ return evaluator;
+ }
+
+ public boolean isSuccess() {
+ // TODO Auto-generated method stub
+ return success;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public Long getValue() {
+ return value;
+ }
+
+ public String getFunctionName() {
+ return functionName;
+ }
+
+ @Override
+ public Boolean visitSchemaPath(SchemaPath path, LogicalExpression valueArg)
throws RuntimeException {
+ this.path = path.getRootSegmentPath();
+
+ if(valueArg == null) {
+ return false;
+ }
+
+ switch (this.path) {
+ case "kafkaMsgOffset":
+ /*
+ * Do not pushdown "not_equal" on kafkaMsgOffset.
+ */
+ if(functionName.equals("not_equal")) {
+ return false;
+ }
+ case "kafkaPartitionId":
+ if(valueArg instanceof IntExpression) {
+ value = (long) ((IntExpression) valueArg).getInt();
+ return true;
+ }
+
+ if(valueArg instanceof LongExpression) {
+ value = ((LongExpression) valueArg).getLong();
+ return true;
+ }
+ break;
+ case "kafkaMsgTimestamp":
+ /*
+ Only pushdown "equal", "greater_than", "greater_than_or_equal" on
kafkaMsgTimestamp
+ */
+ if(!functionName.equals("equal") &&
!functionName.equals("greater_than")
+ && !functionName.equals("greater_than_or_equal_to")) {
+ return false;
+ }
+
+ if(valueArg instanceof IntExpression) {
+ value = (long) ((IntExpression) valueArg).getInt();
+ return true;
+ }
Review comment:
This was mostly added for unit tests. It is possible (although unlikely) for
Kafka topic be configured for `CreateTime` and one can specify timestamp as Int.
I have, however, moved the check for `IntExpression` to the end since it is
least probable.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> predicate pushdown support kafkaMsgOffset
> -----------------------------------------
>
> Key: DRILL-5977
> URL: https://issues.apache.org/jira/browse/DRILL-5977
> Project: Apache Drill
> Issue Type: Improvement
> Reporter: B Anil Kumar
> Assignee: Abhishek Ravi
> Priority: Major
> Fix For: 1.14.0
>
>
> As part of Kafka storage plugin review, below is the suggestion from Paul.
> {noformat}
> Does it make sense to provide a way to select a range of messages: a starting
> point or a count? Perhaps I want to run my query every five minutes, scanning
> only those messages since the previous scan. Or, I want to limit my take to,
> say, the next 1000 messages. Could we use a pseudo-column such as
> "kafkaMsgOffset" for that purpose? Maybe
> SELECT * FROM <some topic> WHERE kafkaMsgOffset > 12345
> {noformat}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)