-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Add CLP_GET_* UDFs with rewrites for schemaless querying.
#42
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
Changes from 1 commit
d840972
a6f7870
a1f37c1
06eb758
f5556a8
2bd80ff
52de22c
445dee2
206b809
eae59b7
ecdaa3f
db8aab4
8598686
ba2262f
8e864bf
a6ea16e
7e10ca9
1175af3
644f77b
c88f1ff
080ab18
13bf115
d501fb5
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 | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,68 @@ | ||||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||||
| * Licensed 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 com.facebook.presto.plugin.clp; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import com.facebook.presto.common.block.Block; | ||||||||||||||||||||||||||||||
| import com.facebook.presto.common.type.StandardTypes; | ||||||||||||||||||||||||||||||
| import com.facebook.presto.spi.function.Description; | ||||||||||||||||||||||||||||||
| import com.facebook.presto.spi.function.ScalarFunction; | ||||||||||||||||||||||||||||||
| import com.facebook.presto.spi.function.SqlType; | ||||||||||||||||||||||||||||||
| import io.airlift.slice.Slice; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
Comment on lines
+16
to
+22
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. 🛠️ Refactor suggestion Use PrestoException with NOT_SUPPORTED for clearer user-facing errors Throwing UnsupportedOperationException surfaces as an internal error to users. Prefer a PrestoException with NOT_SUPPORTED and a clear action message. import com.facebook.presto.common.block.Block;
import com.facebook.presto.common.type.StandardTypes;
import com.facebook.presto.spi.function.Description;
import com.facebook.presto.spi.function.ScalarFunction;
import com.facebook.presto.spi.function.SqlType;
import io.airlift.slice.Slice;
+import com.facebook.presto.spi.PrestoException;
+import static com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| public final class ClpFunctions | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| private ClpFunctions() | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
Comment on lines
+23
to
+28
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. 🛠️ Refactor suggestion Centralise placeholder throwing and improve messages Consolidate the placeholder exception and use consistent, actionable messages so accidental execution fails clearly. public final class ClpFunctions
{
private ClpFunctions()
{
}
+ private static RuntimeException placeholderInvocation(String name)
+ {
+ return new PrestoException(
+ NOT_SUPPORTED,
+ name + " must be rewritten by the CLP query rewriter and should not be executed at runtime.");
+ }
+
@ScalarFunction(value = "CLP_GET_BIGINT", deterministic = false)
@Description("Retrieves an integer value corresponding to the given JSON path.")
@SqlType(StandardTypes.BIGINT)
public static long clpGetBigint(@SqlType(StandardTypes.VARCHAR) Slice jsonPath)
{
- throw new UnsupportedOperationException("CLP_GET_BIGINT is a placeholder function without implementation.");
+ throw placeholderInvocation("CLP_GET_BIGINT");
}
@ScalarFunction(value = "CLP_GET_DOUBLE", deterministic = false)
- @Description("Retrieves a floating point value corresponding to the given JSON path.")
+ @Description("Retrieves a double value corresponding to the given JSON path.")
@SqlType(StandardTypes.DOUBLE)
public static double clpGetDouble(@SqlType(StandardTypes.VARCHAR) Slice jsonPath)
{
- throw new UnsupportedOperationException("CLP_GET_DOUBLE is a placeholder function without implementation.");
+ throw placeholderInvocation("CLP_GET_DOUBLE");
}
@ScalarFunction(value = "CLP_GET_BOOL", deterministic = false)
@Description("Retrieves a boolean value corresponding to the given JSON path.")
@SqlType(StandardTypes.BOOLEAN)
public static boolean clpGetBool(@SqlType(StandardTypes.VARCHAR) Slice jsonPath)
{
- throw new UnsupportedOperationException("CLP_GET_BOOL is a placeholder function without implementation.");
+ throw placeholderInvocation("CLP_GET_BOOL");
}
@ScalarFunction(value = "CLP_GET_STRING", deterministic = false)
@Description("Retrieves a string value corresponding to the given JSON path.")
@SqlType(StandardTypes.VARCHAR)
public static Slice clpGetString(@SqlType(StandardTypes.VARCHAR) Slice jsonPath)
{
- throw new UnsupportedOperationException("CLP_GET_STRING is a placeholder function without implementation.");
+ throw placeholderInvocation("CLP_GET_STRING");
}
@ScalarFunction(value = "CLP_GET_STRING_ARRAY", deterministic = false)
@Description("Retrieves an array value corresponding to the given JSON path and converts each element into a string.")
- @SqlType("ARRAY(VARCHAR)")
+ @SqlType("array(varchar)")
public static Block clpGetStringArray(@SqlType(StandardTypes.VARCHAR) Slice jsonPath)
{
- throw new UnsupportedOperationException("CLP_GET_STRING_ARRAY is a placeholder function without implementation.");
+ throw placeholderInvocation("CLP_GET_STRING_ARRAY");
}
}Also applies to: 29-36, 37-44, 45-52, 53-60, 61-67 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| @ScalarFunction(value = "CLP_GET_INT", deterministic = false) | ||||||||||||||||||||||||||||||
anlowee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||
| @Description("Retrieves an integer value corresponding to the given JSON path.") | ||||||||||||||||||||||||||||||
| @SqlType(StandardTypes.BIGINT) | ||||||||||||||||||||||||||||||
| public static long clpGetInt(@SqlType(StandardTypes.VARCHAR) Slice jsonPath) | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| throw new UnsupportedOperationException("CLP_GET_INT is a placeholder function without implementation."); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @ScalarFunction(value = "CLP_GET_FLOAT", deterministic = false) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| @Description("Retrieves a floating point value corresponding to the given JSON path.") | ||||||||||||||||||||||||||||||
anlowee marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||
| @SqlType(StandardTypes.DOUBLE) | ||||||||||||||||||||||||||||||
| public static double clpGetFloat(@SqlType(StandardTypes.VARCHAR) Slice jsonPath) | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| throw new UnsupportedOperationException("CLP_GET_FLOAT is a placeholder function without implementation."); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @ScalarFunction(value = "CLP_GET_BOOL", deterministic = false) | ||||||||||||||||||||||||||||||
| @Description("Retrieves a boolean value corresponding to the given JSON path.") | ||||||||||||||||||||||||||||||
| @SqlType(StandardTypes.BOOLEAN) | ||||||||||||||||||||||||||||||
| public static boolean clpGetBool(@SqlType(StandardTypes.VARCHAR) Slice jsonPath) | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| throw new UnsupportedOperationException("CLP_GET_BOOL is a placeholder function without implementation."); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @ScalarFunction(value = "CLP_GET_STRING", deterministic = false) | ||||||||||||||||||||||||||||||
| @Description("Retrieves a string value corresponding to the given JSON path.") | ||||||||||||||||||||||||||||||
| @SqlType(StandardTypes.VARCHAR) | ||||||||||||||||||||||||||||||
| public static Slice clpGetString(@SqlType(StandardTypes.VARCHAR) Slice jsonPath) | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| throw new UnsupportedOperationException("CLP_GET_STRING is a placeholder function without implementation."); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @ScalarFunction(value = "CLP_GET_STRING_ARRAY", deterministic = false) | ||||||||||||||||||||||||||||||
| @Description("Retrieves an array value corresponding to the given JSON path and converts each element into a string.") | ||||||||||||||||||||||||||||||
anlowee marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||
| @SqlType("ARRAY(VARCHAR)") | ||||||||||||||||||||||||||||||
| public static Block clpGetStringArray(@SqlType(StandardTypes.VARCHAR) Slice jsonPath) | ||||||||||||||||||||||||||||||
|
Comment on lines
+61
to
+64
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. 🧹 Nitpick (assertive) Normalise type literal casing in @SqlType Presto annotations typically use lower-case type literals (array(varchar)). The parser is case-insensitive, but lower-case improves consistency. 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| throw new UnsupportedOperationException("CLP_GET_STRING_ARRAY is a placeholder function without implementation."); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.