-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Add CLP UDFs with query rewriting support #31
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
base: release-0.293-clp-connector
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| /* | ||
| * 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.block.BlockBuilder; | ||
| 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 io.airlift.slice.Slices; | ||
|
|
||
| import static com.facebook.presto.common.type.VarcharType.VARCHAR; | ||
|
|
||
| public final class ClpFunctions | ||
| { | ||
| private ClpFunctions() | ||
| { | ||
| } | ||
|
|
||
| @ScalarFunction(value = "CLP_GET_INT", deterministic = false) | ||
| @Description("Retrieves an integer value corresponding to the given JSON path.") | ||
| @SqlType(StandardTypes.BIGINT) | ||
| public static long clpGetInt(@SqlType(StandardTypes.VARCHAR) Slice jsonPath) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| @ScalarFunction(value = "CLP_GET_FLOAT", deterministic = false) | ||
| @Description("Retrieves a floating point value corresponding to the given JSON path.") | ||
| @SqlType(StandardTypes.DOUBLE) | ||
| public static double clpGetFloat(@SqlType(StandardTypes.VARCHAR) Slice jsonPath) | ||
| { | ||
| return 0.0; | ||
| } | ||
|
|
||
| @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) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| @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) | ||
| { | ||
| return Slices.EMPTY_SLICE; | ||
| } | ||
|
|
||
| @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)") | ||
| public static Block clpGetStringArray(@SqlType(StandardTypes.VARCHAR) Slice jsonPath) | ||
| { | ||
| BlockBuilder blockBuilder = VARCHAR.createBlockBuilder(null, 0); | ||
| return blockBuilder.build(); | ||
| } | ||
|
|
||
| @ScalarFunction(value = "CLP_WILDCARD_STRING_COLUMN", deterministic = false) | ||
| @Description("Used in filter expressions to allow comparisons with any string column in the log record.") | ||
| @SqlType(StandardTypes.VARCHAR) | ||
| public static Slice clpWildcardStringColumn() | ||
| { | ||
| return Slices.EMPTY_SLICE; | ||
| } | ||
|
|
||
| @ScalarFunction(value = "CLP_WILDCARD_INT_COLUMN", deterministic = false) | ||
| @Description("Used in filter expressions to allow comparisons with any integer column in the log record.") | ||
| @SqlType(StandardTypes.BIGINT) | ||
| public static long clpWildcardIntColumn() | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| @ScalarFunction(value = "CLP_WILDCARD_FLOAT_COLUMN", deterministic = false) | ||
| @Description("Used in filter expressions to allow comparisons with any floating point column in the log record.") | ||
| @SqlType(StandardTypes.DOUBLE) | ||
| public static double clpWildcardFloatColumn() | ||
| { | ||
| return 0.0; | ||
| } | ||
|
|
||
| @ScalarFunction(value = "CLP_WILDCARD_BOOL_COLUMN", deterministic = false) | ||
| @Description("Used in filter expressions to allow comparisons with any boolean column in the log record.") | ||
| @SqlType(StandardTypes.BOOLEAN) | ||
| public static boolean clpWildcardBoolColumn() | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| @ScalarFunction(value = "CLP_GET_JSON_STRING", deterministic = false) | ||
| @Description("Converts an entire log record into a JSON string.") | ||
| @SqlType(StandardTypes.VARCHAR) | ||
| public static Slice clpGetJSONString() | ||
| { | ||
| return Slices.EMPTY_SLICE; | ||
| } | ||
|
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. 💡 Verification agent 🧩 Analysis chainConsider adding a parameter to CLP_GET_JSON_STRING Unlike other CLP_GET functions, this one takes no parameters. Should it accept a JSON path parameter for consistency, or is it intended to return the entire record? 🌐 Web query: 💡 Result: The intended behavior of the CLP_GET_JSON_STRING function in the Presto CLP connector is not documented in detail within the provided search results. However, based on best practices for similar JSON extraction functions in SQL engines and the available context around JSON path extraction and CLP encoding, the following evidence-supported conclusions can be drawn:
Given these conventions, the intended behavior of a function named CLP_GET_JSON_STRING in Presto’s CLP connector is most likely to accept a JSON path parameter and extract (or return) the value at that path from the log record—not just return the entire JSON log record. Requiring a path parameter also aligns with SQL and analytic platform norms for working with nested or semi-structured data. If CLP_GET_JSON_STRING were designed to return the whole log record, there would be little benefit in calling it specifically, as fetching the entire record typically does not require a specialized function or parameterization. In summary: Citations:
Add a JSON path parameter to Based on common SQL connector patterns and Presto’s own JSON extraction functions, Please update accordingly: • File: • Change the signature from: public static Slice clpGetJSONString()to: public static Slice clpGetJSONString(
@SqlType(StandardTypes.VARCHAR) Slice jsonPath)• Adjust the annotations: @ScalarFunction(value = "CLP_GET_JSON_STRING", deterministic = false)
@Description("Extracts the JSON string at the given path from a log record.")
@SqlType(StandardTypes.VARCHAR)• Implement lookup of the specified path inside the record (or throw a clear error if the path is invalid). This aligns with Presto’s Kafka connector ( 🤖 Prompt for AI Agents |
||
| } | ||
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.
🧹 Nitpick (assertive)
Document that these are placeholder implementations
All functions return hardcoded default values. While this is intentional since they're rewritten during query optimization, it would be helpful to add a class-level comment explaining this design choice.
🤖 Prompt for AI Agents