Skip to content

Commit c302fbe

Browse files
committed
Rename and address comments
1 parent d1f34bf commit c302fbe

File tree

6 files changed

+51
-49
lines changed

6 files changed

+51
-49
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public PlanNode optimize(PlanNode maxSubplan, ConnectorSession session, Variable
6363
Rewriter rewriter = new Rewriter(idAllocator);
6464
PlanNode optimizedPlanNode = rewriteWith(rewriter, maxSubplan);
6565

66-
// Throw exception if there are any required metadata filters
66+
// Throw exception if any required metadata filters are missing
6767
if (!rewriter.tableScopeSet.isEmpty() && !rewriter.hasVisitedFilter) {
6868
metadataFilterProvider.checkContainsRequiredFilters(rewriter.tableScopeSet, "");
6969
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@
2929
* filter is missing or cannot be pushed down, the query will be rejected.</li>
3030
* </ul>
3131
*/
32-
public class ClpMetadataFilter
32+
public class ClpMetadataFilterConfig
3333
{
3434
@JsonProperty("columnName")
3535
public String columnName;
3636

3737
@JsonProperty("metadataProviderSpecific")
38-
public MetadataProviderSpecific metadataProviderSpecific;
38+
public MetadataProviderSpecificOptions metadataProviderSpecific;
3939

4040
@JsonProperty("required")
4141
public boolean required;
4242

43-
public interface MetadataProviderSpecific
43+
public interface MetadataProviderSpecificOptions
4444
{}
4545
}

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
import static com.facebook.presto.plugin.clp.ClpErrorCode.CLP_MANDATORY_METADATA_FILTER_NOT_VALID;
3333
import static com.facebook.presto.plugin.clp.ClpErrorCode.CLP_METADATA_FILTER_CONFIG_NOT_FOUND;
34-
import static com.facebook.presto.plugin.clp.metadata.filter.ClpMetadataFilter.MetadataProviderSpecific;
34+
import static com.facebook.presto.plugin.clp.metadata.filter.ClpMetadataFilterConfig.MetadataProviderSpecificOptions;
3535
import static com.google.common.collect.ImmutableSet.toImmutableSet;
3636
import static java.util.Objects.requireNonNull;
3737

@@ -46,11 +46,11 @@
4646
* to all tables within that schema).
4747
* <p></p>
4848
* Different metadata providers can customize filter configurations through the
49-
* {@code metadataProviderSpecific} field within each {@link ClpMetadataFilter}.
49+
* {@code metadataProviderSpecific} field within each {@link ClpMetadataFilterConfig}.
5050
*/
5151
public abstract class ClpMetadataFilterProvider
5252
{
53-
protected final Map<String, List<ClpMetadataFilter>> filterMap;
53+
protected final Map<String, List<ClpMetadataFilterConfig>> filterMap;
5454

5555
public ClpMetadataFilterProvider(ClpConfig config)
5656
{
@@ -63,22 +63,22 @@ public ClpMetadataFilterProvider(ClpConfig config)
6363
ObjectMapper mapper = new ObjectMapper();
6464
SimpleModule module = new SimpleModule();
6565
module.addDeserializer(
66-
MetadataProviderSpecific.class,
67-
new ClpMetadataProviderSpecificDeserializer(getMetadataProviderSpecificClass()));
66+
MetadataProviderSpecificOptions.class,
67+
new ClpMetadataProviderSpecificOptionsDeserializer(getMetadataProviderSpecificOptionsClass()));
6868
mapper.registerModule(module);
6969
try {
7070
filterMap = mapper.readValue(
7171
new File(config.getMetadataFilterConfig()),
72-
new TypeReference<Map<String, List<ClpMetadataFilter>>>() {});
72+
new TypeReference<Map<String, List<ClpMetadataFilterConfig>>>() {});
7373
}
7474
catch (IOException e) {
7575
throw new PrestoException(CLP_METADATA_FILTER_CONFIG_NOT_FOUND, "Failed to open metadata filter config file", e);
7676
}
7777
}
7878

7979
/**
80-
* Rewrites the given pushed-down expression for metadata filtering to remap filter conditions
81-
* based on the configured range mappings for the given scope.
80+
* Rewrites the given {@code pushDownExpression} for metadata filtering to remap filter
81+
* conditions based on the configured range mappings for the given scope.
8282
* <p></p>
8383
* The {@code scope} follows the format {@code catalog[.schema][.table]}, and determines
8484
* which filter mappings to apply, since mappings from more specific scopes (e.g., table-level)
@@ -87,19 +87,19 @@ public ClpMetadataFilterProvider(ClpConfig config)
8787
* filter configuration.
8888
*
8989
* @param scope the scope of the filter
90-
* @param pushDownExpression the pushed-down expression for metadata filtering that needs to
91-
* be rewritten
92-
* @return the rewritten pushed-down expression for metadata filtering
90+
* @param pushDownExpression the {@code pushDownExpression} for metadata filtering that needs
91+
* to be rewritten
92+
* @return the rewritten {@code pushDownExpression} for metadata filtering
9393
*/
9494
public abstract String remapMetadataFilterPushDown(String scope, String pushDownExpression);
9595

9696
/**
97-
* Checks for the given table, if the given pushed-down expression for metadata filtering
97+
* Checks for the given table, if the given {@code pushDownExpression} for metadata filtering
9898
* contains all required fields.
9999
*
100100
* @param tableScopeSet the set of scopes of the tables that are being queried
101-
* @param metadataFilterPushDownExpression the pushed-down expression for metadata filtering
102-
* to be checked
101+
* @param metadataFilterPushDownExpression the {@code pushDownExpression} for metadata
102+
* filtering to be checked
103103
*/
104104
public void checkContainsRequiredFilters(Set<String> tableScopeSet, String metadataFilterPushDownExpression)
105105
{
@@ -126,20 +126,20 @@ public Set<String> getColumnNames(String scope)
126126
}
127127

128128
/**
129-
* Returns the {@link MetadataProviderSpecific} class implemented by the user. To respect our
129+
* Returns the {@link MetadataProviderSpecificOptions} class implemented by the user. To respect our
130130
* code style, we recommend implementing a {@code protected static class} as an inner class
131131
* in the user-implemented {@link ClpMetadataFilterProvider} class.
132132
*
133-
* @return the user-implemented {@link MetadataProviderSpecific} class.
133+
* @return the user-implemented {@link MetadataProviderSpecificOptions} class.
134134
*/
135-
protected abstract Class<? extends MetadataProviderSpecific> getMetadataProviderSpecificClass();
135+
protected abstract Class<? extends MetadataProviderSpecificOptions> getMetadataProviderSpecificOptionsClass();
136136

137137
private Set<String> getRequiredColumnNames(String scope)
138138
{
139139
return collectColumnNamesFromScopes(scope, this::getRequiredColumnNamesFromFilters);
140140
}
141141

142-
private Set<String> collectColumnNamesFromScopes(String scope, Function<List<ClpMetadataFilter>, Set<String>> extractor)
142+
private Set<String> collectColumnNamesFromScopes(String scope, Function<List<ClpMetadataFilterConfig>, Set<String>> extractor)
143143
{
144144
String[] splitScope = scope.split("\\.");
145145
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
@@ -157,14 +157,14 @@ private Set<String> collectColumnNamesFromScopes(String scope, Function<List<Clp
157157
return builder.build();
158158
}
159159

160-
private Set<String> getAllColumnNamesFromFilters(List<ClpMetadataFilter> filters)
160+
private Set<String> getAllColumnNamesFromFilters(List<ClpMetadataFilterConfig> filters)
161161
{
162162
return null != filters ? filters.stream()
163163
.map(filter -> filter.columnName)
164164
.collect(toImmutableSet()) : ImmutableSet.of();
165165
}
166166

167-
private Set<String> getRequiredColumnNamesFromFilters(List<ClpMetadataFilter> filters)
167+
private Set<String> getRequiredColumnNamesFromFilters(List<ClpMetadataFilterConfig> filters)
168168
{
169169
return null != filters ? filters.stream()
170170
.filter(filter -> filter.required)
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,29 @@
2121

2222
import java.io.IOException;
2323

24-
import static com.facebook.presto.plugin.clp.metadata.filter.ClpMetadataFilter.MetadataProviderSpecific;
24+
import static com.facebook.presto.plugin.clp.metadata.filter.ClpMetadataFilterConfig.MetadataProviderSpecificOptions;
2525

2626
/**
27-
* Uses the given implementation of {@link MetadataProviderSpecific} to deserialize the
27+
* Uses the given implementation of {@link MetadataProviderSpecificOptions} to deserialize the
2828
* {@code "metadataProviderSpecific"} field in the filter. The implementation is originally chosen
2929
* by the {@code clp.metadata-provider-type} config option.
3030
*/
31-
public class ClpMetadataProviderSpecificDeserializer
32-
extends JsonDeserializer<MetadataProviderSpecific>
31+
public class ClpMetadataProviderSpecificOptionsDeserializer
32+
extends JsonDeserializer<MetadataProviderSpecificOptions>
3333
{
34-
private final Class<? extends MetadataProviderSpecific> actualMetadataProviderSpecificClass;
34+
private final Class<? extends MetadataProviderSpecificOptions> actualMetadataProviderSpecificOptionsClass;
3535

36-
public ClpMetadataProviderSpecificDeserializer(Class<? extends MetadataProviderSpecific> actualMetadataProviderSpecificClass)
36+
public ClpMetadataProviderSpecificOptionsDeserializer(Class<? extends MetadataProviderSpecificOptions> actualMetadataProviderSpecificOptionsClass)
3737
{
38-
this.actualMetadataProviderSpecificClass = actualMetadataProviderSpecificClass;
38+
this.actualMetadataProviderSpecificOptionsClass = actualMetadataProviderSpecificOptionsClass;
3939
}
4040

4141
@Override
42-
public MetadataProviderSpecific deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
42+
public MetadataProviderSpecificOptions deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
4343
{
4444
ObjectNode node = p.getCodec().readTree(p);
4545
ObjectMapper mapper = (ObjectMapper) p.getCodec();
4646

47-
return mapper.treeToValue(node, actualMetadataProviderSpecificClass);
47+
return mapper.treeToValue(node, actualMetadataProviderSpecificOptionsClass);
4848
}
4949
}

presto-clp/src/main/java/com/facebook/presto/plugin/clp/metadata/filter/ClpMySqlMetadataFilterProvider.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.util.Map;
2424
import java.util.Objects;
2525

26-
import static com.facebook.presto.plugin.clp.metadata.filter.ClpMetadataFilter.MetadataProviderSpecific;
26+
import static com.facebook.presto.plugin.clp.metadata.filter.ClpMetadataFilterConfig.MetadataProviderSpecificOptions;
2727
import static com.google.common.collect.ImmutableMap.toImmutableMap;
2828
import static java.lang.String.format;
2929

@@ -42,7 +42,7 @@ public ClpMySqlMetadataFilterProvider(ClpConfig config)
4242

4343
/**
4444
* This method performs regex-based replacements according to the {@code "rangeMapping"} field
45-
* in {@link ClpMySqlMetadataProviderSpecific} to convert numeric filter expressions. For
45+
* in {@link ClpMySqlMetadataProviderSpecificOptions} to convert numeric filter expressions. For
4646
* example:
4747
* <ul>
4848
* <li>{@code "msg.timestamp" >= 1234} → {@code end_timestamp >= 1234}</li>
@@ -60,7 +60,7 @@ public String remapMetadataFilterPushDown(String scope, String pushDownExpressio
6060
{
6161
String[] splitScope = scope.split("\\.");
6262

63-
Map<String, ClpMySqlMetadataProviderSpecific.RangeMapping> mappings = new HashMap<>(getAllMappingsFromFilters(filterMap.get(splitScope[0])));
63+
Map<String, ClpMySqlMetadataProviderSpecificOptions.RangeMapping> mappings = new HashMap<>(getAllMappingsFromFilters(filterMap.get(splitScope[0])));
6464

6565
if (1 < splitScope.length) {
6666
mappings.putAll(getAllMappingsFromFilters(filterMap.get(splitScope[0] + "." + splitScope[1])));
@@ -71,9 +71,9 @@ public String remapMetadataFilterPushDown(String scope, String pushDownExpressio
7171
}
7272

7373
String remappedSql = pushDownExpression;
74-
for (Map.Entry<String, ClpMySqlMetadataProviderSpecific.RangeMapping> entry : mappings.entrySet()) {
74+
for (Map.Entry<String, ClpMySqlMetadataProviderSpecificOptions.RangeMapping> entry : mappings.entrySet()) {
7575
String key = entry.getKey();
76-
ClpMySqlMetadataProviderSpecific.RangeMapping value = entry.getValue();
76+
ClpMySqlMetadataProviderSpecificOptions.RangeMapping value = entry.getValue();
7777
remappedSql = remappedSql.replaceAll(
7878
format("\"(%s)\"\\s(>=?)\\s(-?[0-9]+(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?)", key),
7979
format("%s $2 $3", value.upperBound));
@@ -88,21 +88,21 @@ public String remapMetadataFilterPushDown(String scope, String pushDownExpressio
8888
}
8989

9090
@Override
91-
protected Class<? extends MetadataProviderSpecific> getMetadataProviderSpecificClass()
91+
protected Class<? extends MetadataProviderSpecificOptions> getMetadataProviderSpecificOptionsClass()
9292
{
93-
return ClpMySqlMetadataProviderSpecific.class;
93+
return ClpMySqlMetadataProviderSpecificOptions.class;
9494
}
9595

96-
private Map<String, ClpMySqlMetadataProviderSpecific.RangeMapping> getAllMappingsFromFilters(List<ClpMetadataFilter> filters)
96+
private Map<String, ClpMySqlMetadataProviderSpecificOptions.RangeMapping> getAllMappingsFromFilters(List<ClpMetadataFilterConfig> filters)
9797
{
9898
return null != filters
9999
? filters.stream()
100100
.filter(filter ->
101-
filter.metadataProviderSpecific instanceof ClpMySqlMetadataProviderSpecific &&
102-
((ClpMySqlMetadataProviderSpecific) filter.metadataProviderSpecific).rangeMapping != null)
101+
filter.metadataProviderSpecific instanceof ClpMySqlMetadataProviderSpecificOptions &&
102+
((ClpMySqlMetadataProviderSpecificOptions) filter.metadataProviderSpecific).rangeMapping != null)
103103
.collect(toImmutableMap(
104104
filter -> filter.columnName,
105-
filter -> ((ClpMySqlMetadataProviderSpecific) filter.metadataProviderSpecific).rangeMapping))
105+
filter -> ((ClpMySqlMetadataProviderSpecificOptions) filter.metadataProviderSpecific).rangeMapping))
106106
: ImmutableMap.of();
107107
}
108108

@@ -120,8 +120,8 @@ private Map<String, ClpMySqlMetadataProviderSpecific.RangeMapping> getAllMapping
120120
* </li>
121121
* </ul>
122122
*/
123-
protected static class ClpMySqlMetadataProviderSpecific
124-
implements MetadataProviderSpecific
123+
protected static class ClpMySqlMetadataProviderSpecificOptions
124+
implements MetadataProviderSpecificOptions
125125
{
126126
@JsonProperty("rangeMapping")
127127
public RangeMapping rangeMapping;

presto-docs/src/main/sphinx/connector/clp.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ Property Name Description
5858
``clp.metadata-provider-type`` Specifies the metadata provider type. Currently, the only supported ``mysql``
5959
type is a MySQL database, which is also used by the CLP package to store
6060
metadata. Additional providers can be supported by implementing the
61-
``ClpMetadataProvider`` interface.
61+
``ClpMetadataProvider`` interface. You may also need to implement the
62+
``ClpMetadataFilterProvider`` interface.
6263
``clp.metadata-db-url`` The JDBC URL used to connect to the metadata database. This property is
6364
required if ``clp.metadata-provider-type`` is set to ``mysql``.
6465
``clp.metadata-db-name`` The name of the metadata database. This option is required if
@@ -95,8 +96,8 @@ uses a MySQL database for both metadata and split storage. We recommend using th
9596
automatically populates the database with the required information.
9697

9798
If you prefer to use a different source--or the same source with a custom implementation--you can provide your own
98-
implementations of the ``ClpMetadataProvider`` and ``ClpSplitProvider`` interfaces, and configure the connector
99-
accordingly.
99+
implementations of the ``ClpMetadataFilterProvider``, ``ClpMetadataProvider`` and ``ClpSplitProvider`` interfaces, and
100+
configure the connector accordingly.
100101

101102
.. _metadata-filter-config-file:
102103

@@ -143,6 +144,7 @@ Each filter config has the following options:
143144

144145
- ``metadataProviderSpecific`` *(optional)*: Configs specific to the current metadata provider. Options for the default
145146
metadata provider (``ClpMySqlMetadataProvider``) are :ref:`below<clp-mysql-metadata-provider-specific-filter-config>`.
147+
Customized
146148

147149
- ``required`` *(optional, defaults to false)*: Whether the filter **must** be present in the generated metadata query.
148150
If a required filter is missing or cannot be added to the metadata query, the original query will be rejected.

0 commit comments

Comments
 (0)