As for the code-generation, you might like to leverage the implementation in
Optiq:
/** SQL {@code LIKE} function. */
public static boolean like(String s, String pattern) {
final String regex = Like.sqlToRegexLike(pattern, null);
return Pattern.matches(regex, s);
}
/** SQL {@code LIKE} function with escape. */
public static boolean like(String s, String pattern, String escape) {
final String regex = Like.sqlToRegexLike(pattern, escape);
return Pattern.matches(regex, s);
}
/** SQL {@code SIMILAR} function. */
public static boolean similar(String s, String pattern) {
final String regex = Like.sqlToRegexSimilar(pattern, null);
return Pattern.matches(regex, s);
}
/** SQL {@code SIMILAR} function with escape. */
public static boolean similar(String s, String pattern, String escape) {
final String regex = Like.sqlToRegexSimilar(pattern, escape);
return Pattern.matches(regex, s);
}
and see
https://github.com/julianhyde/optiq/blob/master/core/src/main/java/net/hydromatic/optiq/runtime/Like.java.
This can be packaged up as a DrillFunc.
However, fixing DrillOptiq$RexToDrill.visitCall is more challenging.
Julian
On Dec 6, 2013, at 1:50 PM, Jinfeng Ni <[email protected]> wrote:
> I believe we do not have support for like predicate. You may try some
> simple comparison predicate, eg. =, >, etc.
>
>
> On Fri, Dec 6, 2013 at 1:22 PM, Norris Lee <[email protected]> wrote:
>
>> Hello,
>>
>> I took a stab at trying to implement the "like" function by adding to
>> org/apache/drill/common/expression/fn/BooleanFunctions.java and
>> org/apache/drill/exec/expr/fn/impl/ComparisonFunctionsNullable.java (Are
>> these the right files to add it to?). However, I hit an error with
>> DrillOptiq. The error I got was:
>>
>> 0: jdbc:drill:schema=parquet-local> select * from
>> "sample-data/region.parquet" where 'test' like 'test';
>> java.lang.AssertionError: todo: implement syntax Special(LIKE('test',
>> 'test'))
>> at
>> org.apache.drill.optiq.DrillOptiq$RexToDrill.visitCall(DrillOptiq.java:129)
>> at
>> org.apache.drill.optiq.DrillOptiq$RexToDrill.visitCall(DrillOptiq.java:75)
>> at org.eigenbase.rex.RexCall.accept(RexCall.java:220)
>> at org.apache.drill.optiq.DrillOptiq.toDrill(DrillOptiq.java:71)
>> at
>> org.apache.drill.optiq.DrillFilterRel.implement(DrillFilterRel.java:57)
>> at
>> org.apache.drill.optiq.DrillImplementor.go(DrillImplementor.java:99)
>> at
>> org.apache.drill.optiq.EnumerableDrillRel.implement(EnumerableDrillRel.java:108)
>> at
>> net.hydromatic.optiq.rules.java.EnumerableRelImplementor.implementRoot(EnumerableRelImplementor.java:69)
>> at
>> net.hydromatic.optiq.prepare.OptiqPrepareImpl$OptiqPreparingStmt.implement(OptiqPrepareImpl.java:541)
>> at
>> net.hydromatic.optiq.prepare.Prepare.prepareSql(Prepare.java:227)
>> at
>> net.hydromatic.optiq.prepare.Prepare.prepareSql(Prepare.java:131)
>> at
>> net.hydromatic.optiq.prepare.OptiqPrepareImpl.prepare2_(OptiqPrepareImpl.java:256)
>> at
>> net.hydromatic.optiq.prepare.OptiqPrepareImpl.prepare_(OptiqPrepareImpl.java:196)
>> at
>> net.hydromatic.optiq.prepare.OptiqPrepareImpl.prepareSql(OptiqPrepareImpl.java:169)
>> at
>> net.hydromatic.optiq.jdbc.OptiqStatement.parseQuery(OptiqStatement.java:402)
>> at
>> net.hydromatic.optiq.jdbc.OptiqStatement.execute(OptiqStatement.java:192)
>> at sqlline.SqlLine$Commands.execute(SqlLine.java:3825)
>> at sqlline.SqlLine$Commands.sql(SqlLine.java:3738)
>> at sqlline.SqlLine.dispatch(SqlLine.java:882)
>> at sqlline.SqlLine.begin(SqlLine.java:717)
>> at sqlline.SqlLine.mainWithInputRedirection(SqlLine.java:460)
>> at sqlline.SqlLine.main(SqlLine.java:443)
>>
>> How would I go on from there? Any help/suggestions would be appreciated.
>> (I will create a JIRA for this soon).
>>
>> Thanks,
>> Norris
>>
>> -----Original Message-----
>> From: Yash Sharma [mailto:[email protected]]
>> Sent: November-26-13 2:37 AM
>> To: [email protected]
>> Subject: RE: How to contribute ?
>>
>> Hi Rohit,
>> Welcome to the Crew.
>> Apart from looking into JIRA's, I would also suggest you to debug the
>> existing test classes . This will show you the flow of a drill plan in
>> execution.
>> Eg:
>> https://github.com/apache/incubator-drill/blob/master/exec/ref/src/test/java/org/apache/drill/exec/ref/RunSimplePlan.java
>>
>> Here is a cool post by Tim on the lifetime of Drill Query which will be
>> helpful while debugging the flow:
>> Read:
>> http://tnachen.wordpress.com/2013/11/05/lifetime-of-a-query-in-drill-alpha-release/
>>
>> Also you can have a look into how Drill Functions work and you can add in
>> some new Drill Functions. Drill Functions are pretty simple to understand
>> and there are lot of examples implemented.
>> This is how a sample Drill Func. looks like:
>>
>> https://github.com/apache/incubator-drill/blob/103072a619741d5e228fdb181501ec2f82e111a3/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparisonFunctions.java
>>
>> I had a small post on contributing to MathFunctions which might be helpful:
>>
>> http://www.confusedcoders.com/bigdata/apache-drill/how-to-contribute-to-apache-drill-implementing-drill-math-functions
>>
>> Good luck Drilling.
>> - Yash
>>
>>
>>
>> -----Original Message-----
>> From: Rohit [mailto:[email protected]]
>> Sent: Tuesday, November 26, 2013 2:50 PM
>> To: [email protected]
>> Subject: How to contribute ?
>>
>> Hey Guys,
>>
>> I've configured Drill for Dev on my machine. However, I'm still not clear
>> how should i start contributing to it.
>>
>> I've gone through Jira issues. Being a newbie to this project i think it
>> would be best to start over with fixing test cases or add new test cases or
>> trivial bugs. This will help me in acquainting with Drill code. However, I
>> couldn't find any issues like this. (Jira issues - test.)
>>
>> Please let me know how should i start.
>>
>> Thanks,
>> RS.
>>
>> ________________________________
>>
>>
>>
>>
>>
>>
>> NOTE: This message may contain information that is confidential,
>> proprietary, privileged or otherwise protected by law. The message is
>> intended solely for the named addressee. If received in error, please
>> destroy and notify the sender. Any use of this email is prohibited when
>> received in error. Impetus does not represent, warrant and/or guarantee,
>> that the integrity of this communication has been maintained nor that the
>> communication is free of errors, virus, interception or interference.
>>