Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform fixes over the MongoDB Timestamp and other custom funtions #2880

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@
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.ValueExpressions.VarDecimalExpression;
import org.apache.drill.common.expression.visitors.AbstractExprVisitor;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.apache.drill.shaded.guava.com.google.common.collect.ImmutableMap;
import org.apache.drill.shaded.guava.com.google.common.collect.ImmutableSet;

Expand Down Expand Up @@ -179,6 +184,37 @@ public Boolean visitConvertExpression(ConvertExpression e,
@Override
public Boolean visitUnknown(LogicalExpression e, LogicalExpression valueArg)
throws RuntimeException {
if (e instanceof FunctionCall){

String name = ((FunctionCall) e).getName();
//handle Drill STRPOS function
if (name.equals("strpos")){
LogicalExpression arg_0 = ((FunctionCall) e).arg(0);
LogicalExpression arg_1 = ((FunctionCall) e).arg(1);
QuotedString arg_1qs = (QuotedString) arg_1;

this.functionName = name;
this.path = (SchemaPath) arg_0;
this.value = arg_1qs.getString();
return true;
}
//handle Drill POSITION function
if (name.equals("position")){

LogicalExpression arg_0 = ((FunctionCall) e).arg(0);
LogicalExpression arg_1 = ((FunctionCall) e).arg(1);
QuotedString arg_0qs = (QuotedString) arg_0;
String arg0_unsplit = arg_0qs.getString();
List<String> arg0_splitted = Arrays.asList(arg0_unsplit.split(","));

this.functionName = name;
this.path = (SchemaPath) arg_1;
this.value = arg0_splitted;
return true;
}

}

return false;
}

Expand Down Expand Up @@ -221,6 +257,14 @@ public Boolean visitSchemaPath(SchemaPath path, LogicalExpression valueArg)
return true;
}

//To support Drill Timestamp converter
if (valueArg instanceof TimeStampExpression) {
Long unixseconds = ((TimeStampExpression) valueArg).getTimeStamp();
this.value = new Date(unixseconds);
this.path = path;
return true;
}

// Mongo does not support decimals, therefore double value is used.
// See list of supported types in BsonValueCodecProvider.
if (valueArg instanceof VarDecimalExpression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ private MongoScanSpec createMongoScanSpec(String functionName,
case "is not null":
compareOp = MongoCompareOp.IFNOTNULL;
break;
case "strpos":
compareOp = MongoCompareOp.REGEX;
break;
case "position":
compareOp = MongoCompareOp.IN;
break;

}

if (compareOp != null) {
Expand Down