Skip to content

Commit 6925011

Browse files
committed
Add a new config option clp.metadata-filter-provider-type
1 parent c302fbe commit 6925011

File tree

8 files changed

+120
-92
lines changed

8 files changed

+120
-92
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class ClpConfig
2424

2525
private boolean polymorphicTypeEnabled = true;
2626

27+
private MetadataFilterProviderType metadataFilterProviderType = MetadataFilterProviderType.MYSQL;
2728
private MetadataProviderType metadataProviderType = MetadataProviderType.MYSQL;
2829
private String metadataDbUrl;
2930
private String metadataDbName;
@@ -48,6 +49,18 @@ public ClpConfig setPolymorphicTypeEnabled(boolean polymorphicTypeEnabled)
4849
return this;
4950
}
5051

52+
public MetadataFilterProviderType getMetadataFilterProviderType()
53+
{
54+
return metadataFilterProviderType;
55+
}
56+
57+
@Config("clp.metadata-filter-provider-type")
58+
public ClpConfig setMetadataFilterProviderType(MetadataFilterProviderType metadataFilterProviderType)
59+
{
60+
this.metadataFilterProviderType = metadataFilterProviderType;
61+
return this;
62+
}
63+
5164
public MetadataProviderType getMetadataProviderType()
5265
{
5366
return metadataProviderType;
@@ -174,6 +187,11 @@ public ClpConfig setSplitProviderType(SplitProviderType splitProviderType)
174187
return this;
175188
}
176189

190+
public enum MetadataFilterProviderType
191+
{
192+
MYSQL
193+
}
194+
177195
public enum MetadataProviderType
178196
{
179197
MYSQL

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.google.inject.Scopes;
2626

2727
import static com.facebook.airlift.configuration.ConfigBinder.configBinder;
28+
import static com.facebook.presto.plugin.clp.ClpConfig.MetadataFilterProviderType;
2829
import static com.facebook.presto.plugin.clp.ClpConfig.MetadataProviderType;
2930
import static com.facebook.presto.plugin.clp.ClpConfig.SplitProviderType;
3031
import static com.facebook.presto.plugin.clp.ClpErrorCode.CLP_UNSUPPORTED_METADATA_SOURCE;
@@ -43,9 +44,13 @@ protected void setup(Binder binder)
4344
configBinder(binder).bindConfig(ClpConfig.class);
4445

4546
ClpConfig config = buildConfigObject(ClpConfig.class);
47+
48+
if (MetadataFilterProviderType.MYSQL == config.getMetadataFilterProviderType()) {
49+
binder.bind(ClpMetadataFilterProvider.class).to(ClpMySqlMetadataFilterProvider.class).in(Scopes.SINGLETON);
50+
}
51+
4652
if (config.getMetadataProviderType() == MetadataProviderType.MYSQL) {
4753
binder.bind(ClpMetadataProvider.class).to(ClpMySqlMetadataProvider.class).in(Scopes.SINGLETON);
48-
binder.bind(ClpMetadataFilterProvider.class).to(ClpMySqlMetadataFilterProvider.class).in(Scopes.SINGLETON);
4954
}
5055
else {
5156
throw new PrestoException(CLP_UNSUPPORTED_METADATA_SOURCE, "Unsupported metadata provider type: " + config.getMetadataProviderType());
Lines changed: 10 additions & 10 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.ClpMetadataFilterConfig.MetadataProviderSpecificOptions;
24+
import static com.facebook.presto.plugin.clp.metadata.filter.ClpMetadataFilterConfig.CustomMetadataFilterOptions;
2525

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

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

4141
@Override
42-
public MetadataProviderSpecificOptions deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
42+
public CustomMetadataFilterOptions 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, actualMetadataProviderSpecificOptionsClass);
47+
return mapper.treeToValue(node, actualCustomMetadataFilterOptionsClass);
4848
}
4949
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* <ul>
2323
* <li><b>{@code columnName}</b>: the data column's name.</li>
2424
*
25-
* <li><b>{@code metadataProviderSpecific}</b>: the metadata provider specific sub-object.</li>
25+
* <li><b>{@code customOptions}</b>: the metadata provider specific sub-object.</li>
2626
*
2727
* <li><b>{@code required}</b> (optional, defaults to {@code false}): indicates whether the
2828
* filter must be present in the pushed-down expression for metadata filtering. If a required
@@ -34,12 +34,12 @@ public class ClpMetadataFilterConfig
3434
@JsonProperty("columnName")
3535
public String columnName;
3636

37-
@JsonProperty("metadataProviderSpecific")
38-
public MetadataProviderSpecificOptions metadataProviderSpecific;
37+
@JsonProperty("customOptions")
38+
public CustomMetadataFilterOptions customOptions;
3939

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

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

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

Lines changed: 7 additions & 7 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.ClpMetadataFilterConfig.MetadataProviderSpecificOptions;
34+
import static com.facebook.presto.plugin.clp.metadata.filter.ClpMetadataFilterConfig.CustomMetadataFilterOptions;
3535
import static com.google.common.collect.ImmutableSet.toImmutableSet;
3636
import static java.util.Objects.requireNonNull;
3737

@@ -46,7 +46,7 @@
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 ClpMetadataFilterConfig}.
49+
* {@code "customOptions"} field within each {@link ClpMetadataFilterConfig}.
5050
*/
5151
public abstract class ClpMetadataFilterProvider
5252
{
@@ -63,8 +63,8 @@ public ClpMetadataFilterProvider(ClpConfig config)
6363
ObjectMapper mapper = new ObjectMapper();
6464
SimpleModule module = new SimpleModule();
6565
module.addDeserializer(
66-
MetadataProviderSpecificOptions.class,
67-
new ClpMetadataProviderSpecificOptionsDeserializer(getMetadataProviderSpecificOptionsClass()));
66+
CustomMetadataFilterOptions.class,
67+
new ClpCustomMetadataFilterOptionsDeserializer(getMetadataProviderSpecificOptionsClass()));
6868
mapper.registerModule(module);
6969
try {
7070
filterMap = mapper.readValue(
@@ -126,13 +126,13 @@ public Set<String> getColumnNames(String scope)
126126
}
127127

128128
/**
129-
* Returns the {@link MetadataProviderSpecificOptions} class implemented by the user. To respect our
129+
* Returns the {@link CustomMetadataFilterOptions} 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 MetadataProviderSpecificOptions} class.
133+
* @return the user-implemented {@link CustomMetadataFilterOptions} class.
134134
*/
135-
protected abstract Class<? extends MetadataProviderSpecificOptions> getMetadataProviderSpecificOptionsClass();
135+
protected abstract Class<? extends CustomMetadataFilterOptions> getMetadataProviderSpecificOptionsClass();
136136

137137
private Set<String> getRequiredColumnNames(String scope)
138138
{

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.ClpMetadataFilterConfig.MetadataProviderSpecificOptions;
26+
import static com.facebook.presto.plugin.clp.metadata.filter.ClpMetadataFilterConfig.CustomMetadataFilterOptions;
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 ClpMySqlMetadataProviderSpecificOptions} to convert numeric filter expressions. For
45+
* in {@link ClpMySqlCustomMetadataFilterOptions} 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, ClpMySqlMetadataProviderSpecificOptions.RangeMapping> mappings = new HashMap<>(getAllMappingsFromFilters(filterMap.get(splitScope[0])));
63+
Map<String, ClpMySqlCustomMetadataFilterOptions.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, ClpMySqlMetadataProviderSpecificOptions.RangeMapping> entry : mappings.entrySet()) {
74+
for (Map.Entry<String, ClpMySqlCustomMetadataFilterOptions.RangeMapping> entry : mappings.entrySet()) {
7575
String key = entry.getKey();
76-
ClpMySqlMetadataProviderSpecificOptions.RangeMapping value = entry.getValue();
76+
ClpMySqlCustomMetadataFilterOptions.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 MetadataProviderSpecificOptions> getMetadataProviderSpecificOptionsClass()
91+
protected Class<? extends CustomMetadataFilterOptions> getMetadataProviderSpecificOptionsClass()
9292
{
93-
return ClpMySqlMetadataProviderSpecificOptions.class;
93+
return ClpMySqlCustomMetadataFilterOptions.class;
9494
}
9595

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

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

presto-clp/src/test/resources/test-mysql-metadata-filter.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"clp.default.table_1": [
1313
{
1414
"columnName": "msg.timestamp",
15-
"metadataProviderSpecific": {
15+
"customOptions": {
1616
"rangeMapping": {
1717
"lowerBound": "begin_timestamp",
1818
"upperBound": "end_timestamp"

0 commit comments

Comments
 (0)