-
Notifications
You must be signed in to change notification settings - Fork 95
feat(isthmus)!: inject ConverterProvider into the SQL statement parsers #1035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7927291
c07d8ca
88b012c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package io.substrait.isthmus.sql; | ||
|
|
||
| import io.substrait.isthmus.ConverterProvider; | ||
| import io.substrait.isthmus.SqlConverterBase; | ||
| import io.substrait.isthmus.SubstraitTypeSystem; | ||
| import io.substrait.isthmus.Utils; | ||
|
|
@@ -50,9 +51,29 @@ public class SubstraitCreateStatementParser { | |
| */ | ||
| public static List<SubstraitTable> processCreateStatements(@NonNull final String createStatements) | ||
| throws SqlParseException { | ||
| return processCreateStatements(ConverterProvider.DEFAULT, createStatements); | ||
| } | ||
|
|
||
| /** | ||
| * Parses a SQL string containing only CREATE statements into a list of {@link SubstraitTable}s, | ||
| * using the parser settings from the given {@link ConverterProvider}. | ||
| * | ||
| * <p>This method only supports simple table names without any additional qualifiers. Only used | ||
| * with {@link io.substrait.isthmus.SqlExpressionToSubstrait}. | ||
| * | ||
| * @param converterProvider the converter provider whose parser config controls identifier casing | ||
| * and other parser settings | ||
| * @param createStatements a SQL string containing only CREATE statements; must not be null | ||
| * @return list of {@link SubstraitTable}s generated from the CREATE statements | ||
| * @throws SqlParseException if parsing fails or statements are invalid | ||
| */ | ||
| public static List<SubstraitTable> processCreateStatements( | ||
| @NonNull final ConverterProvider converterProvider, @NonNull final String createStatements) | ||
| throws SqlParseException { | ||
| final List<SubstraitTable> tableList = new ArrayList<>(); | ||
|
|
||
| final List<SqlNode> sqlNode = SubstraitSqlStatementParser.parseStatements(createStatements); | ||
| final List<SqlNode> sqlNode = | ||
| SubstraitSqlStatementParser.parseStatements(createStatements, converterProvider); | ||
| for (final SqlNode parsed : sqlNode) { | ||
| if (!(parsed instanceof SqlCreateTable)) { | ||
| throw fail("Not a valid CREATE TABLE statement."); | ||
|
|
@@ -89,6 +110,26 @@ public static CalciteCatalogReader processCreateStatementsToCatalog( | |
| return processCreateStatementsToCatalog(createStatements.toArray(new String[0])); | ||
| } | ||
|
|
||
| /** | ||
| * Parses one or more SQL strings containing only CREATE statements into a {@link | ||
| * CalciteCatalogReader}, using the parser settings from the given {@link ConverterProvider}. | ||
| * | ||
| * <p>This method expects the use of fully qualified table names in the CREATE statements. | ||
| * | ||
| * @param converterProvider the converter provider whose parser config controls identifier casing | ||
| * and other parser settings | ||
| * @param createStatements List of SQL strings containing only CREATE statements, must not be null | ||
| * @return a {@link CalciteCatalogReader} generated from the CREATE statements | ||
| * @throws SqlParseException if there is an error parsing the SQL statements | ||
| */ | ||
| public static CalciteCatalogReader processCreateStatementsToCatalog( | ||
| @NonNull final ConverterProvider converterProvider, | ||
| @NonNull final List<String> createStatements) | ||
| throws SqlParseException { | ||
| return processCreateStatementsToCatalog( | ||
| converterProvider, createStatements.toArray(new String[0])); | ||
| } | ||
|
|
||
| /** | ||
| * Parses one or more SQL strings containing only CREATE statements into a {@link | ||
| * CalciteCatalogReader} | ||
|
|
@@ -101,7 +142,33 @@ public static CalciteCatalogReader processCreateStatementsToCatalog( | |
| */ | ||
| public static CalciteCatalogReader processCreateStatementsToCatalog( | ||
| @NonNull final String... createStatements) throws SqlParseException { | ||
| final CalciteSchema rootSchema = processCreateStatementsToSchema(createStatements); | ||
| final CalciteSchema rootSchema = | ||
| processCreateStatementsToSchema(ConverterProvider.DEFAULT, createStatements); | ||
| final List<String> defaultSchema = Collections.emptyList(); | ||
| return new CalciteCatalogReader( | ||
| rootSchema, | ||
| defaultSchema, | ||
| SubstraitTypeSystem.TYPE_FACTORY, | ||
| SqlConverterBase.CONNECTION_CONFIG); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (not for this PR) I wonder if it would make sense to get the RelTypeFactory and SqlConverterBase from the ConverterProvider as well. The former is already configured in the ConverterProvider.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can probably include that in the builder PR |
||
| } | ||
|
|
||
| /** | ||
| * Parses one or more SQL strings containing only CREATE statements into a {@link | ||
| * CalciteCatalogReader}, using the parser settings from the given {@link ConverterProvider}. | ||
| * | ||
| * <p>This method expects the use of fully qualified table names in the CREATE statements. | ||
| * | ||
| * @param converterProvider the converter provider whose parser config controls identifier casing | ||
| * and other parser settings | ||
| * @param createStatements a SQL string containing only CREATE statements, must not be null | ||
| * @return a {@link CalciteCatalogReader} generated from the CREATE statements | ||
| * @throws SqlParseException if parsing fails or statements are invalid | ||
| */ | ||
| public static CalciteCatalogReader processCreateStatementsToCatalog( | ||
| @NonNull final ConverterProvider converterProvider, @NonNull final String... createStatements) | ||
| throws SqlParseException { | ||
| final CalciteSchema rootSchema = | ||
| processCreateStatementsToSchema(converterProvider, createStatements); | ||
| final List<String> defaultSchema = Collections.emptyList(); | ||
| return new CalciteCatalogReader( | ||
| rootSchema, | ||
|
|
@@ -133,19 +200,17 @@ private static SqlParseException fail(@Nullable final String message) { | |
| } | ||
|
|
||
| /** | ||
| * Parses one or more SQL strings containing only CREATE statements into a {@link CalciteSchema}. | ||
| * | ||
| * @param createStatements one or more SQL strings containing only CREATE statements; must not be | ||
| * null | ||
| * @return a {@link CalciteSchema} generated from the CREATE statements | ||
| * @throws SqlParseException if parsing fails or statements are invalid | ||
| * Parses one or more SQL strings containing only CREATE statements into a {@link CalciteSchema} | ||
| * using the given provider's parser config. | ||
| */ | ||
| private static CalciteSchema processCreateStatementsToSchema( | ||
| @NonNull final String... createStatements) throws SqlParseException { | ||
| @NonNull final ConverterProvider converterProvider, @NonNull final String... createStatements) | ||
| throws SqlParseException { | ||
| final CalciteSchema rootSchema = CalciteSchema.createRootSchema(false); | ||
|
|
||
| for (final String statement : createStatements) { | ||
| final List<SqlNode> sqlNode = SubstraitSqlStatementParser.parseStatements(statement); | ||
| final List<SqlNode> sqlNode = | ||
| SubstraitSqlStatementParser.parseStatements(statement, converterProvider); | ||
| for (final SqlNode parsed : sqlNode) { | ||
| if (!(parsed instanceof SqlCreateTable)) { | ||
| throw fail("Not a valid CREATE TABLE statement."); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.