-
Notifications
You must be signed in to change notification settings - Fork 59
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
initial implementation of startsWith #78
base: master
Are you sure you want to change the base?
Changes from 3 commits
11becd6
06a3b41
072faaa
9b5ae77
b5230ca
a43a715
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,10 @@ public static <T> UnboundPredicate<T> notEqual(String name, T value) { | |
return new UnboundPredicate<>(Expression.Operation.NOT_EQ, ref(name), value); | ||
} | ||
|
||
public static <T> UnboundPredicate<T> startWith(String name, T value) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this accept There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, is it a typo that this is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I leave this as String it won't compile, I wanted to have it throw There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the compile error? I'm surprised it won't compile if you remove the type variable and use String. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had a test checking that if I try to run startWith on anything other then string it will throw There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can always use the |
||
return new UnboundPredicate<>(Operation.STARTS_WITH, ref(name), value); | ||
} | ||
|
||
public static <T> UnboundPredicate<T> predicate(Operation op, String name, T value) { | ||
Preconditions.checkArgument(op != Operation.IS_NULL && op != Operation.NOT_NULL, | ||
"Cannot create %s predicate inclusive a value", op); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
package com.netflix.iceberg.expressions; | ||
|
||
import com.netflix.iceberg.TestHelpers; | ||
import com.netflix.iceberg.exceptions.ValidationException; | ||
import com.netflix.iceberg.types.Types; | ||
import com.netflix.iceberg.types.Types.StructType; | ||
import org.apache.avro.util.Utf8; | ||
|
@@ -26,6 +27,7 @@ | |
import static com.netflix.iceberg.expressions.Expressions.alwaysFalse; | ||
import static com.netflix.iceberg.expressions.Expressions.alwaysTrue; | ||
import static com.netflix.iceberg.expressions.Expressions.and; | ||
import static com.netflix.iceberg.expressions.Expressions.startWith; | ||
import static com.netflix.iceberg.expressions.Expressions.equal; | ||
import static com.netflix.iceberg.expressions.Expressions.greaterThan; | ||
import static com.netflix.iceberg.expressions.Expressions.greaterThanOrEqual; | ||
|
@@ -151,4 +153,24 @@ public void testCharSeqValue() { | |
Assert.assertFalse("string(abc) == utf8(abcd) => false", | ||
evaluator.eval(TestHelpers.Row.of(new Utf8("abcd")))); | ||
} | ||
|
||
@Test | ||
public void testStartWith() { | ||
StructType struct = StructType.of(required(3, "s", Types.StringType.get())); | ||
Evaluator evaluator = new Evaluator(struct, startWith("s", "abc")); | ||
Assert.assertTrue("startWith(abcdddd, abc) => true", | ||
evaluator.eval(TestHelpers.Row.of(("abcdddd")))); | ||
|
||
Assert.assertFalse("startWith(xyzffff, abc) => false", | ||
evaluator.eval(TestHelpers.Row.of(("xyzffff")))); | ||
|
||
Liorba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Test(expected = ValidationException.class) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is more of a binding test, which should go in |
||
public void testStartsWithThrowsOnNotString() { | ||
StructType struct = StructType.of(required(3, "s", Types.IntegerType.get())); | ||
Evaluator evaluator = new Evaluator(struct, startWith("s", 112)); | ||
evaluator.eval(TestHelpers.Row.of(("xyzffff"))); | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this calling
to
? ABoundReference
guarantees that the type of its literal is correct and has already been coerced during the binding process.