15
15
import org .apache .calcite .rel .rules .CoreRules ;
16
16
import org .apache .calcite .rex .RexBuilder ;
17
17
import org .apache .calcite .sql .SqlNode ;
18
+ import org .apache .calcite .sql .SqlOperatorTable ;
18
19
import org .apache .calcite .sql .parser .SqlParseException ;
19
20
import org .apache .calcite .sql .validate .SqlValidator ;
20
21
import org .apache .calcite .sql2rel .SqlToRelConverter ;
@@ -41,6 +42,23 @@ public static RelRoot convertQuery(String sqlStatement, Prepare.CatalogReader ca
41
42
return convertQuery (sqlStatement , catalogReader , validator , createDefaultRelOptCluster ());
42
43
}
43
44
45
+ /**
46
+ * Converts a SQL statement to a Calcite {@link RelRoot}.
47
+ *
48
+ * @param sqlStatement a SQL statement string
49
+ * @param catalogReader the {@link Prepare.CatalogReader} for finding tables/views referenced in
50
+ * the SQL statement
51
+ * @param operatorTable the {@link SqlOperatorTable} for dynamic operators
52
+ * @return a {@link RelRoot} corresponding to the given SQL statement
53
+ * @throws SqlParseException if there is an error while parsing the SQL statement
54
+ */
55
+ public static RelRoot convertQuery (
56
+ String sqlStatement , Prepare .CatalogReader catalogReader , SqlOperatorTable operatorTable )
57
+ throws SqlParseException {
58
+ SqlValidator validator = new SubstraitSqlValidator (catalogReader , operatorTable );
59
+ return convertQuery (sqlStatement , catalogReader , validator , createDefaultRelOptCluster ());
60
+ }
61
+
44
62
/**
45
63
* Converts a SQL statement to a Calcite {@link RelRoot}.
46
64
*
@@ -72,6 +90,24 @@ public static RelRoot convertQuery(
72
90
return relRoots .get (0 );
73
91
}
74
92
93
+ /**
94
+ * Converts one or more SQL statements to a List of {@link RelRoot}, with one {@link RelRoot} per
95
+ * statement.
96
+ *
97
+ * @param sqlStatements a string containing one or more SQL statements
98
+ * @param catalogReader the {@link Prepare.CatalogReader} for finding tables/views referenced in
99
+ * the SQL statements
100
+ * @param operatorTable the {@link SqlOperatorTable} for dynamic operators
101
+ * @return a list of {@link RelRoot}s corresponding to the given SQL statements
102
+ * @throws SqlParseException if there is an error while parsing the SQL statements
103
+ */
104
+ public static List <RelRoot > convertQueries (
105
+ String sqlStatements , Prepare .CatalogReader catalogReader , SqlOperatorTable operatorTable )
106
+ throws SqlParseException {
107
+ SqlValidator validator = new SubstraitSqlValidator (catalogReader , operatorTable );
108
+ return convertQueries (sqlStatements , catalogReader , validator , createDefaultRelOptCluster ());
109
+ }
110
+
75
111
/**
76
112
* Converts one or more SQL statements to a List of {@link RelRoot}, with one {@link RelRoot} per
77
113
* statement.
0 commit comments