Skip to content

Commit a75d694

Browse files
Apply suggestions from code review
Co-authored-by: kirkrodrigues <[email protected]>
1 parent 7b7811b commit a75d694

File tree

4 files changed

+42
-40
lines changed

4 files changed

+42
-40
lines changed

presto-clp/src/main/java/com/facebook/presto/plugin/clp/ClpExpression.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,21 @@
1818
import java.util.Optional;
1919

2020
/**
21-
* Represents the result of converting a Presto RowExpression into a CLP-compatible KQL query and
22-
* a SQL query for filtering splits using a metadata database. In every case, `pushDownExpression`
23-
* represents the part of the RowExpression that could be converted to a KQL expression, and
24-
* `remainingExpression` represents the part that could not be converted.
21+
* Represents the result of:
22+
* <ul>
23+
* <li>splitting a {@link RowExpression} into an expression that can be pushed down to CLP
24+
* (`pushDownExpression`) and any remaining expression that cannot be
25+
* (`remainingExpression`).</li>
26+
* <li>a SQL query for filtering splits using CLP's metadata database.</li>
27+
* </ul>
2528
*/
2629
public class ClpExpression
2730
{
2831
// Optional KQL query or column name representing the fully or partially translatable part of the expression.
2932
private final Optional<String> pushDownExpression;
3033

31-
// Optional SQL string extracted from the query plan, which is only made of given metadata columns.
34+
// Optional SQL string extracted from the query plan, which is only made of up of columns in
35+
// CLP's metadata database.
3236
private final Optional<String> metadataSqlQuery;
3337

3438
// The remaining (non-translatable) portion of the RowExpression, if any.

presto-clp/src/main/java/com/facebook/presto/plugin/clp/ClpFilterToKqlConverter.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@
8484
* <li>Dereferencing fields from row-typed variables.</li>
8585
* <li>Logical operators AND, OR, and NOT.</li>
8686
* </ul>
87-
*
88-
* Supported translations for Metadata SQL include:
87+
* <p></p>
88+
* Supported translations for SQL include:
8989
* <ul>
9090
* <li>Comparisons between variables and constants (e.g., =, !=, <, >, <=, >=).</li>
9191
* <li>Dereferencing fields from row-typed variables.</li>
@@ -209,7 +209,7 @@ private String getVariableName(VariableReferenceExpression variable)
209209
* Handles the <code>BETWEEN</code> expression.
210210
* <p></p>
211211
* The translation is only performed if:
212-
* <ul>All arguments must have numeric types.</ul>
212+
* <ul>All arguments have numeric types.</ul>
213213
* <ul>The first argument is a variable reference expression.</ul>
214214
* <ul>The second and third arguments are constant expressions.</ul>
215215
* <p></p>
@@ -866,12 +866,12 @@ private ClpExpression handleDereference(RowExpression expression)
866866
}
867867

868868
/**
869-
* Refer to
869+
* See
870870
* <a href="https://docs.yscope.com/clp/main/user-guide/reference-json-search-syntax">here
871871
* </a> for all special chars in the string value that need to be escaped.
872872
*
873-
* @param literalString the target string to escape special chars '\', '"', '?' and '*'
874-
* @return the escaped string
873+
* @param literalString
874+
* @return the string with special characters escaped
875875
*/
876876
public static String escapeKqlSpecialCharsForStringValue(String literalString)
877877
{
@@ -884,11 +884,11 @@ public static String escapeKqlSpecialCharsForStringValue(String literalString)
884884
}
885885

886886
/**
887-
* Check if the type is one of the numeric types that CLP will handle. Refer to
888-
* {@link ClpSchemaTree} for all types that CLP will handle.
887+
* Checks if the type is one of the numeric types that can be pushed down to CLP. Refer to
888+
* {@link ClpSchemaTree} for all types that can be pushed down.
889889
*
890890
* @param type the type to check
891-
* @return is the type numeric or not
891+
* @return whether the type can be pushed down.
892892
*/
893893
public static boolean isNumericType(Type type)
894894
{

presto-clp/src/main/java/com/facebook/presto/plugin/clp/ClpMetadataFilterProvider.java

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,18 @@
4242

4343
/**
4444
* Loads and manages metadata filter configurations for the CLP connector.
45-
* <p>
45+
* <p></p>
4646
* The configuration file is specified by the {@code clp.metadata-filter-config} property
4747
* and defines metadata filters used to optimize query execution through split pruning.
48-
* Filters can be declared at different scopes:
48+
* <p></p>
49+
* Filter configs can be declared at either a catalog, schema, or table scope. Filter configs under
50+
* a particular scope will apply to all child scopes (e.g., schema-level filter configs will apply
51+
* to all tables within that schema).
52+
* <p></p>
53+
* Each filter config includes the following fields:
4954
* <ul>
50-
* <li><b>Catalog-level</b>: applies to all schemas and tables within a catalog.</li>
51-
* <li><b>Schema-level</b>: applies to all tables within a specific catalog and schema.</li>
52-
* <li><b>Table-level</b>: applies to a fully qualified table {@code catalog.schema.table}.</li>
53-
* </ul>
54-
*
55-
* <p>Each scope maps to a list of filter definitions. Each filter includes the following fields:
56-
* <ul>
57-
* <li><b>{@code columnName}</b> (required): the name of a column in the table's logical schema.
58-
* Only columns of numeric type are currently supported as metadata filters.</li>
55+
* <li><b>{@code columnName}</b>: the name of a column in the table's logical schema. Currently,
56+
* only numeric-type columns can be used as metadata filters.</li>
5957
*
6058
* <li><b>{@code rangeMapping}</b> (optional): remaps a logical filter to physical metadata-only columns.
6159
* This field is valid only for numeric-type columns.
@@ -69,9 +67,9 @@
6967
* }</pre>
7068
* This ensures the filter applies to a superset of the actual result set, enabling safe pruning.</li>
7169
*
72-
* <li><b>{@code required}</b> (optional, default: {@code false}): indicates whether the filter must be present
73-
* in the extracted metadata filter SQL query. If a required filter is missing or cannot be pushed down,
74-
* the query will be rejected.</li>
70+
* <li><b>{@code required}</b> (optional, defaults to {@code false}): indicates whether the filter
71+
* must be present in the translated metadata filter SQL query. If a required filter is missing or
72+
* cannot be pushed down, the query will be rejected.</li>
7573
* </ul>
7674
*/
7775
public class ClpMetadataFilterProvider
@@ -112,29 +110,27 @@ public void checkContainsRequiredFilters(SchemaTableName schemaTableName, String
112110
}
113111

114112
/**
115-
* Rewrites the input SQL string by remapping filter conditions based on the configured
116-
* metadata filter range mappings for the given scope.
113+
* Rewrites the given SQL string to remap filter conditions based on the configured range
114+
* mappings for the given scope.
117115
*
118116
* <p>The {@code scope} follows the format {@code catalog[.schema][.table]}, and determines
119-
* which filter mappings to apply. For each level of scope (catalog, schema, table), this
120-
* method collects all range mappings defined in the metadata filter configuration. Mappings
121-
* from more specific scopes (e.g., table-level) override or supplement those from broader
122-
* scopes (e.g., catalog-level).
117+
* which filter mappings to apply, since mappings from more specific scopes (e.g., table-level)
118+
* override or supplement those from broader scopes (e.g., catalog-level). For each scope
119+
* (catalog, schema, table), this method collects all range mappings defined in the metadata
120+
* filter configuration.
123121
*
124122
* <p>This method performs regex-based replacements to convert numeric filter expressions such
125123
* as:
126-
*
127124
* <ul>
128125
* <li>{@code "msg.timestamp" >= 1234} → {@code end_timestamp >= 1234}</li>
129126
* <li>{@code "msg.timestamp" <= 5678} → {@code begin_timestamp <= 5678}</li>
130127
* <li>{@code "msg.timestamp" = 4567} →
131128
* {@code (begin_timestamp <= 4567 AND end_timestamp >= 4567)}</li>
132129
* </ul>
133130
*
134-
* @param scope the catalog.schema.table scope used to resolve applicable filter mappings
135-
* @param sql the original SQL expression to be remapped
136-
* @return the rewritten SQL string with metadata filter expressions remapped according to the
137-
* configured range mappings
131+
* @param scope
132+
* @param sql
133+
* @return the rewritten SQL string
138134
*/
139135
public String remapFilterSql(String scope, String sql)
140136
{

presto-clp/src/test/java/com/facebook/presto/plugin/clp/TestClpFilterToKql.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ public void testBetweenPushDown()
105105
"fare BETWEEN (city.Region.Id - 5) AND (city.Region.Id + 5)",
106106
null,
107107
"fare BETWEEN (city.Region.Id - 5) AND (city.Region.Id + 5)");
108-
// If the last two arguments of BETWEEN are not numeric constants, then CLP connector won't do push down
108+
109+
// If the last two arguments of BETWEEN are not numeric constants, then the CLP connector
110+
// won't push them down.
109111
testPushDown(sessionHolder, "city.Name BETWEEN 'a' AND 'b'", null, "city.Name BETWEEN 'a' AND 'b'");
110112
}
111113

0 commit comments

Comments
 (0)