Skip to content

Commit 9c86114

Browse files
authored
feat: Add support for defining and using specific columns for metadata filtering. (#19)
1 parent 8ea32d6 commit 9c86114

20 files changed

+1122
-163
lines changed

presto-clp/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@
6565
<scope>provided</scope>
6666
</dependency>
6767

68+
<dependency>
69+
<groupId>com.fasterxml.jackson.core</groupId>
70+
<artifactId>jackson-core</artifactId>
71+
</dependency>
72+
73+
<dependency>
74+
<groupId>com.fasterxml.jackson.core</groupId>
75+
<artifactId>jackson-databind</artifactId>
76+
</dependency>
77+
6878
<dependency>
6979
<groupId>com.facebook.presto</groupId>
7080
<artifactId>presto-spi</artifactId>

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class ClpConfig
2929
private String metadataDbName;
3030
private String metadataDbUser;
3131
private String metadataDbPassword;
32+
private String metadataFilterConfig;
3233
private String metadataTablePrefix;
3334
private long metadataRefreshInterval = 60;
3435
private long metadataExpireInterval = 600;
@@ -107,6 +108,18 @@ public ClpConfig setMetadataDbPassword(String metadataDbPassword)
107108
return this;
108109
}
109110

111+
public String getMetadataFilterConfig()
112+
{
113+
return metadataFilterConfig;
114+
}
115+
116+
@Config("clp.metadata-filter-config")
117+
public ClpConfig setMetadataFilterConfig(String metadataFilterConfig)
118+
{
119+
this.metadataFilterConfig = metadataFilterConfig;
120+
return this;
121+
}
122+
110123
public String getMetadataTablePrefix()
111124
{
112125
return metadataTablePrefix;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333
public class ClpConnectorFactory
3434
implements ConnectorFactory
3535
{
36+
public static final String CONNECTOR_NAME = "clp";
37+
3638
@Override
3739
public String getName()
3840
{
39-
return "clp";
41+
return CONNECTOR_NAME;
4042
}
4143

4244
@Override

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.facebook.presto.spi.ErrorCodeSupplier;
1919

2020
import static com.facebook.presto.common.ErrorType.EXTERNAL;
21+
import static com.facebook.presto.common.ErrorType.USER_ERROR;
2122

2223
public enum ClpErrorCode
2324
implements ErrorCodeSupplier
@@ -26,7 +27,10 @@ public enum ClpErrorCode
2627
CLP_UNSUPPORTED_METADATA_SOURCE(1, EXTERNAL),
2728
CLP_UNSUPPORTED_SPLIT_SOURCE(2, EXTERNAL),
2829
CLP_UNSUPPORTED_TYPE(3, EXTERNAL),
29-
CLP_UNSUPPORTED_CONFIG_OPTION(4, EXTERNAL);
30+
CLP_UNSUPPORTED_CONFIG_OPTION(4, EXTERNAL),
31+
32+
CLP_METADATA_FILTER_CONFIG_NOT_FOUND(10, USER_ERROR),
33+
CLP_MANDATORY_METADATA_FILTER_NOT_VALID(11, USER_ERROR);
3034

3135
private final ErrorCode errorCode;
3236

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

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,30 @@
1818
import java.util.Optional;
1919

2020
/**
21-
* Represents the result of converting a Presto RowExpression into a CLP-compatible KQL query. In
22-
* every case, `pushDownExpression` represents the part of the RowExpression that could be
23-
* converted to a KQL expression, and `remainingExpression` represents the part that could not be
24-
* 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

34+
// Optional SQL string extracted from the query plan, which is only made of up of columns in
35+
// CLP's metadata database.
36+
private final Optional<String> metadataSqlQuery;
37+
3138
// The remaining (non-translatable) portion of the RowExpression, if any.
3239
private final Optional<RowExpression> remainingExpression;
3340

34-
public ClpExpression(String pushDownExpression, RowExpression remainingExpression)
41+
public ClpExpression(String pushDownExpression, String metadataSqlQuery, RowExpression remainingExpression)
3542
{
3643
this.pushDownExpression = Optional.ofNullable(pushDownExpression);
44+
this.metadataSqlQuery = Optional.ofNullable(metadataSqlQuery);
3745
this.remainingExpression = Optional.ofNullable(remainingExpression);
3846
}
3947

@@ -42,7 +50,7 @@ public ClpExpression(String pushDownExpression, RowExpression remainingExpressio
4250
*/
4351
public ClpExpression()
4452
{
45-
this(null, null);
53+
this(null, null, null);
4654
}
4755

4856
/**
@@ -52,7 +60,19 @@ public ClpExpression()
5260
*/
5361
public ClpExpression(String pushDownExpression)
5462
{
55-
this(pushDownExpression, null);
63+
this(pushDownExpression, null, null);
64+
}
65+
66+
/**
67+
* Creates a ClpExpression from a fully translatable KQL string or column name, as well as a
68+
* metadata SQL string.
69+
*
70+
* @param pushDownExpression
71+
* @param metadataSqlQuery
72+
*/
73+
public ClpExpression(String pushDownExpression, String metadataSqlQuery)
74+
{
75+
this(pushDownExpression, metadataSqlQuery, null);
5676
}
5777

5878
/**
@@ -62,14 +82,19 @@ public ClpExpression(String pushDownExpression)
6282
*/
6383
public ClpExpression(RowExpression remainingExpression)
6484
{
65-
this(null, remainingExpression);
85+
this(null, null, remainingExpression);
6686
}
6787

6888
public Optional<String> getPushDownExpression()
6989
{
7090
return pushDownExpression;
7191
}
7292

93+
public Optional<String> getMetadataSqlQuery()
94+
{
95+
return metadataSqlQuery;
96+
}
97+
7398
public Optional<RowExpression> getRemainingExpression()
7499
{
75100
return remainingExpression;

0 commit comments

Comments
 (0)