Skip to content

Commit e94e218

Browse files
committed
add plan optimizer for clp connector
1 parent 2f33875 commit e94e218

File tree

6 files changed

+1275
-0
lines changed

6 files changed

+1275
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.facebook.presto.plugin.clp;
15+
16+
import com.facebook.presto.spi.relation.RowExpression;
17+
18+
import java.util.Optional;
19+
20+
/**
21+
* Represents the result of converting a Presto RowExpression into a CLP-compatible KQL query.
22+
* There are three possible cases:
23+
* 1. The entire RowExpression is convertible to KQL: `definition` is set, `remainingExpression` is empty.
24+
* 2. Part of the RowExpression is convertible: the KQL part is stored in `definition`,
25+
* and the remaining untranslatable part is stored in `remainingExpression`.
26+
* 3. None of the expression is convertible: the full RowExpression is stored in `remainingExpression`,
27+
* and `definition` is empty.
28+
*/
29+
public class ClpExpression
30+
{
31+
// Optional KQL query string representing the fully or partially translatable part of the expression.
32+
private final Optional<String> definition;
33+
34+
// The remaining (non-translatable) portion of the RowExpression, if any.
35+
private final Optional<RowExpression> remainingExpression;
36+
37+
public ClpExpression(String definition, RowExpression remainingExpression)
38+
{
39+
this.definition = Optional.ofNullable(definition);
40+
this.remainingExpression = Optional.ofNullable(remainingExpression);
41+
}
42+
43+
// Creates an empty ClpExpression (no KQL definition, no remaining expression).
44+
public ClpExpression()
45+
{
46+
this (null, null);
47+
}
48+
49+
// Creates a ClpExpression from a fully translatable KQL string.
50+
public ClpExpression(String definition)
51+
{
52+
this(definition, null);
53+
}
54+
55+
// Creates a ClpExpression from a non-translatable RowExpression.
56+
public ClpExpression(RowExpression remainingExpression)
57+
{
58+
this(null, remainingExpression);
59+
}
60+
61+
public Optional<String> getDefinition()
62+
{
63+
return definition;
64+
}
65+
66+
public Optional<RowExpression> getRemainingExpression()
67+
{
68+
return remainingExpression;
69+
}
70+
}

0 commit comments

Comments
 (0)