-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a QueryPreparer interface, all analyzers should implement this interface to support query prepare functionality.
- Loading branch information
1 parent
bc873b8
commit e97afc8
Showing
24 changed files
with
374 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
presto-analyzer/src/main/java/com/facebook/presto/sql/analyzer/AnalyzerModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.sql.analyzer; | ||
|
||
import com.google.inject.Binder; | ||
import com.google.inject.Module; | ||
import com.google.inject.multibindings.MapBinder; | ||
|
||
import static com.facebook.presto.sql.analyzer.AnalyzerType.BUILTIN; | ||
import static com.facebook.presto.sql.analyzer.AnalyzerType.NATIVE; | ||
import static com.google.inject.Scopes.SINGLETON; | ||
|
||
public class AnalyzerModule | ||
implements Module | ||
{ | ||
@Override | ||
public void configure(Binder binder) | ||
{ | ||
MapBinder<AnalyzerType, QueryPreparer> queryPreparersByType = MapBinder.newMapBinder(binder, AnalyzerType.class, QueryPreparer.class); | ||
queryPreparersByType.addBinding(BUILTIN).to(BuiltInQueryPreparer.class).in(SINGLETON); | ||
queryPreparersByType.addBinding(NATIVE).to(NativeQueryPreparer.class).in(SINGLETON); | ||
|
||
binder.bind(AnalyzerProvider.class).in(SINGLETON); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
presto-analyzer/src/main/java/com/facebook/presto/sql/analyzer/AnalyzerProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.facebook.presto.sql.analyzer; | ||
|
||
import com.facebook.presto.spi.PrestoException; | ||
|
||
import javax.inject.Inject; | ||
|
||
import java.util.Map; | ||
|
||
import static com.facebook.presto.spi.StandardErrorCode.UNSUPPORTED_ANALYZER_TYPE; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* This class provides various interfaces for various functionalities in the analyzer. | ||
* This class can be used to get a specific analyzer implementation for a given analyzer type. | ||
*/ | ||
public class AnalyzerProvider | ||
{ | ||
private final Map<AnalyzerType, QueryPreparer> queryPreparersByType; | ||
|
||
@Inject | ||
public AnalyzerProvider(Map<AnalyzerType, QueryPreparer> queryPreparersByType) | ||
{ | ||
this.queryPreparersByType = requireNonNull(queryPreparersByType, "queryPreparersByType is null"); | ||
} | ||
|
||
public QueryPreparer getQueryPreparer(AnalyzerType analyzerType) | ||
{ | ||
requireNonNull(analyzerType, "AnalyzerType is null"); | ||
if (queryPreparersByType.containsKey(analyzerType)) { | ||
return queryPreparersByType.get(analyzerType); | ||
} | ||
|
||
throw new PrestoException(UNSUPPORTED_ANALYZER_TYPE, "Unsupported analyzer type: " + analyzerType); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
presto-analyzer/src/main/java/com/facebook/presto/sql/analyzer/AnalyzerType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.sql.analyzer; | ||
|
||
/** | ||
* Presto supports various analyzers to support various analyzer functionality. | ||
*/ | ||
public enum AnalyzerType | ||
{ | ||
/** | ||
* This is for builtin analyzer. This provides default antlr based parser and inbuilt analyzer to produce Analysis object. | ||
*/ | ||
BUILTIN, | ||
/** | ||
* This is for C++ based parser and analyzer. This analyzer is currently under development. | ||
* Please avoid using it, as it may corrupt the session. | ||
*/ | ||
NATIVE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
presto-analyzer/src/main/java/com/facebook/presto/sql/analyzer/NativePreparedQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.sql.analyzer; | ||
|
||
import java.util.Optional; | ||
|
||
public class NativePreparedQuery | ||
extends PreparedQuery | ||
{ | ||
// TODO: Dummy implementation. This should be replaced with native implementation. | ||
public NativePreparedQuery(Optional<String> formattedQuery, Optional<String> prepareSql) | ||
{ | ||
super(formattedQuery, prepareSql); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
presto-analyzer/src/main/java/com/facebook/presto/sql/analyzer/NativeQueryPreparer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.sql.analyzer; | ||
|
||
import com.facebook.presto.spi.PrestoException; | ||
import com.facebook.presto.spi.WarningCollector; | ||
import com.facebook.presto.sql.parser.ParsingException; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public class NativeQueryPreparer | ||
implements QueryPreparer | ||
{ | ||
@Override | ||
public PreparedQuery prepareQuery(AnalyzerOptions analyzerOptions, String query, Map<String, String> preparedStatements, WarningCollector warningCollector) | ||
throws ParsingException, PrestoException, SemanticException | ||
{ | ||
return new NativePreparedQuery(Optional.of(query), Optional.of(query)); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
presto-analyzer/src/main/java/com/facebook/presto/sql/analyzer/PreparedQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.sql.analyzer; | ||
|
||
import com.facebook.presto.common.resourceGroups.QueryType; | ||
|
||
import java.util.Optional; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public abstract class PreparedQuery | ||
{ | ||
private final Optional<String> formattedQuery; | ||
private final Optional<String> prepareSql; | ||
|
||
public PreparedQuery(Optional<String> formattedQuery, Optional<String> prepareSql) | ||
{ | ||
this.formattedQuery = requireNonNull(formattedQuery, "formattedQuery is null"); | ||
this.prepareSql = requireNonNull(prepareSql, "prepareSql is null"); | ||
} | ||
|
||
public Optional<String> getFormattedQuery() | ||
{ | ||
return formattedQuery; | ||
} | ||
|
||
public Optional<String> getPrepareSql() | ||
{ | ||
return prepareSql; | ||
} | ||
|
||
public Optional<QueryType> getQueryType() | ||
{ | ||
throw new UnsupportedOperationException("getQueryType method is not supported!"); | ||
} | ||
|
||
public boolean isTransactionControlStatement() | ||
{ | ||
throw new UnsupportedOperationException("isTransactionControlStatement method is not supported!"); | ||
} | ||
|
||
public Class<?> getStatementClass() | ||
{ | ||
throw new UnsupportedOperationException("getStatementClass method is not supported!"); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
presto-analyzer/src/main/java/com/facebook/presto/sql/analyzer/QueryPreparer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.sql.analyzer; | ||
|
||
import com.facebook.presto.spi.PrestoException; | ||
import com.facebook.presto.spi.WarningCollector; | ||
import com.facebook.presto.sql.parser.ParsingException; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* QueryPreparer interface should be implemented by the analyzer to provide prepare query related functionality. | ||
*/ | ||
public interface QueryPreparer | ||
{ | ||
/** | ||
* This method should do the necessary work required to prepare the query and return the preparedQuery object. | ||
* @param analyzerOptions various analyzer options required to parse and analyze the query | ||
* @param query query string which needs to be prepared | ||
* @param preparedStatements existing prepared query statements | ||
* @param warningCollector Warning collector to collect various warnings | ||
* @return preared query object | ||
* @throws ParsingException | ||
* @throws PrestoException | ||
* @throws SemanticException | ||
*/ | ||
PreparedQuery prepareQuery(AnalyzerOptions analyzerOptions, String query, Map<String, String> preparedStatements, WarningCollector warningCollector) | ||
throws ParsingException, PrestoException, SemanticException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.