Package org.apache.calcite.tools
Class Hoist
java.lang.Object
org.apache.calcite.tools.Hoist
Utility that extracts constants from a SQL query.
Simple use:
final String sql =
"select 'x' from emp where deptno < 10";
final Hoist.Hoisted hoisted =
Hoist.create(Hoist.config()).hoist();
print(hoisted); // "select ?0 from emp where deptno < ?1"
Calling Hoist.Hoisted.toString()
generates a string that is similar to
SQL where a user has manually converted all constants to bind variables, and
which could then be executed using PreparedStatement.execute()
.
That is not a goal of this utility, but see
[CALCITE-963]
Hoist literals.
For more advanced formatting, use Hoist.Hoisted.substitute(Function)
.
Adjust Hoist.Config
to use a different parser or parsing options.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Configuration.static class
Result of hoisting.static class
Variable. -
Method Summary
Modifier and TypeMethodDescriptionstatic Hoist.Config
config()
Creates a Config.static Hoist
create
(Hoist.Config config) Creates a Hoist.Hoists literals in a given SQL string, returning aHoist.Hoisted
.static String
Converts aHoist.Variable
to a string "?N", where N is theHoist.Variable.ordinal
.static String
Converts aHoist.Variable
to a string "?N", where N is theHoist.Variable.ordinal
, if the fragment is a character literal.
-
Method Details
-
config
Creates a Config. -
create
Creates a Hoist. -
ordinalString
Converts aHoist.Variable
to a string "?N", where N is theHoist.Variable.ordinal
. -
ordinalStringIfChar
Converts aHoist.Variable
to a string "?N", where N is theHoist.Variable.ordinal
, if the fragment is a character literal. Other fragments are unchanged. -
hoist
Hoists literals in a given SQL string, returning aHoist.Hoisted
.
-