|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.sf.saffron.sql2rel.SqlToRelConverter
Converts a SQL parse tree (consisting of SqlNode
objects) into a relational algebra expression (consisting of
SaffronRel
objects).
This class accomplishes in one step what you could accomplish in two steps
using a SqlToOpenjavaConverter
followed by a
OJQueryExpander
.
Nested Class Summary | |
private class |
SqlToRelConverter.Blackboard
Workspace for translating an individual SELECT statement (or sub-SELECT). |
(package private) static class |
SqlToRelConverter.DeferredLookup
Contains the information necessary to repeat a call to Blackboard#lookup . |
(package private) class |
SqlToRelConverter.NullDefaultValueFactory
An implementation of DefaultValueFactory which always supplies NULL. |
static class |
SqlToRelConverter.SchemaCatalogReader
A SchemaCatalogReader looks up catalog information from a
saffron schema object . |
Field Summary | |
private static HashMap |
binaryMap
Maps an operator name to an operator . |
private VolcanoCluster |
cluster
|
private SaffronConnection |
connection
|
private DefaultValueFactory |
defaultValueFactory
|
private static HashMap |
functionMap
Maps a function name to an operator . |
(package private) ArrayList |
leaves
|
private HashMap |
mapScopeToRel
|
private static HashMap |
postfixMap
Maps an operator name to an operator . |
private static HashMap |
prefixMap
Maps an operator name to an operator . |
private boolean |
producingFlatReferences
|
private RexBuilder |
rexBuilder
|
private SaffronSchema |
schema
|
private SqlValidator |
validator
|
Constructor Summary | |
SqlToRelConverter(SqlValidator validator,
SaffronSchema schema,
Environment env,
SaffronConnection connection)
Creates a converter |
Method Summary | |
private static boolean |
contains(String[] names,
int length,
String s)
|
private SaffronRel |
convertDelete(SqlDelete call)
|
private SaffronRel |
convertExists(SqlToRelConverter.Blackboard bb,
SqlNode seek,
SqlNode condition,
RexLiteral extraExpr,
String extraName)
Converts a query into a join with an indicator variable. |
RexNode |
convertExpression(SqlToRelConverter.Blackboard bb,
SqlNode node)
Converts an expression from SqlNode to RexNode format. |
private RexNode[] |
convertExpressionList(SqlToRelConverter.Blackboard bb,
SqlNode[] nodes)
|
private void |
convertFrom(SqlToRelConverter.Blackboard bb,
SqlNode from)
Converts a FROM clause into a relational expression. |
private void |
convertGroup(SqlToRelConverter.Blackboard bb,
SqlNodeList groupList)
Converts a GROUP BY clause. |
private void |
convertHaving(SqlToRelConverter.Blackboard bb,
SqlNode having)
|
private RexNode |
convertIdentifier(SqlToRelConverter.Blackboard bb,
SqlIdentifier identifier)
Converts an identifier into an expression in a given scope. |
private SaffronRel |
convertInsert(SqlInsert call)
|
private RexNode |
convertJoinCondition(SqlToRelConverter.Blackboard bb,
SqlNode condition,
SqlJoinOperator.ConditionType conditionType,
SaffronRel leftRel,
SaffronRel rightRel)
|
private static int |
convertJoinType(SqlJoinOperator.JoinType joinType)
|
private RexLiteral |
convertLiteral(SqlLiteral literal)
|
private void |
convertOrder(SqlToRelConverter.Blackboard bb,
SqlNodeList orderList)
Converts an ORDER BY clause. |
SaffronRel |
convertQuery(SqlNode query)
Converts a query's parse tree into a relational expression. |
private SaffronRel |
convertQueryOrInList(SqlToRelConverter.Blackboard bb,
SqlNode seek)
|
private SaffronRel |
convertQueryRecursive(SqlNode query)
|
private SaffronRel |
convertRowConstructor(SqlToRelConverter.Blackboard bb,
SqlCall rowConstructor)
Converts a row constructor into a relational expression. |
SaffronRel |
convertSelect(SqlSelect query)
Converts a SELECT statement's parse tree into a relational expression. |
private void |
convertSelectList(SqlToRelConverter.Blackboard bb,
SqlNodeList selectList)
|
private void |
convertValues(SqlToRelConverter.Blackboard bb,
SqlCall values)
Converts a values clause (as in "INSERT INTO T(x,y) VALUES (1,2)") into a relational expression. |
private void |
convertWhere(SqlToRelConverter.Blackboard bb,
SqlNode where)
|
static HashMap |
createBinaryMap()
|
(package private) VolcanoCluster |
createCluster(Environment env)
|
static HashMap |
createFunctionMap()
|
private JoinRel |
createJoin(SqlToRelConverter.Blackboard bb,
SaffronRel leftRel,
SaffronRel rightRel,
SqlNode condition,
SqlJoinOperator.ConditionType conditionType,
int joinType)
|
static HashMap |
createPostfixMap()
|
static HashMap |
createPrefixMap()
|
private void |
findSubqueries(SqlToRelConverter.Blackboard bb,
SqlNode node)
Builds a list of all IN or EXISTS operators
inside SQL parse tree. |
RexBuilder |
getRexBuilder()
Returns the row-expression builder. |
static SaffronTable |
getSaffronTable(SqlValidator.Scope scope,
SaffronSchema schema)
Converts a scope into a SaffronTable . |
private boolean |
isRowConstructor(SqlNode node)
|
private static RexKind |
mapSqlFunToRex(SqlFunction op)
|
private void |
replaceSubqueries(SqlToRelConverter.Blackboard bb,
SqlNode expr)
|
void |
requestFlatReferences()
Request that references to join outputs be produced as "flat" FieldAccesses rather than preserving the structure of the join. |
void |
setDefaultValueFactory(DefaultValueFactory factory)
Set a new DefaultValueFactory. |
private void |
substituteSubqueries(SqlToRelConverter.Blackboard bb)
|
static Test |
suite()
Standard method recognised by JUnit. |
private static String |
uniqueFieldName(String[] names,
int length,
String s)
Generates a unique name |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final HashMap binaryMap
operator name
to an operator
.
For example, binaryMap.get("/") yields RexKind.Divide
.
private static final HashMap prefixMap
operator name
to an operator
.
For example, binaryMap.get("-") yields RexKind.MinusPrefix
.
private static final HashMap postfixMap
operator name
to an operator
.
private static final HashMap functionMap
function name
to an operator
.
private final SqlValidator validator
private RexBuilder rexBuilder
private SaffronConnection connection
private SaffronSchema schema
private VolcanoCluster cluster
private HashMap mapScopeToRel
private DefaultValueFactory defaultValueFactory
private boolean producingFlatReferences
final ArrayList leaves
Constructor Detail |
public SqlToRelConverter(SqlValidator validator, SaffronSchema schema, Environment env, SaffronConnection connection)
validator
- schema
- env
- connection
- Method Detail |
public RexBuilder getRexBuilder()
public void setDefaultValueFactory(DefaultValueFactory factory)
factory
- new DefaultValueFactorypublic void requestFlatReferences()
public SaffronRel convertQuery(SqlNode query)
public SaffronRel convertSelect(SqlSelect query)
private void convertHaving(SqlToRelConverter.Blackboard bb, SqlNode having)
private void convertWhere(SqlToRelConverter.Blackboard bb, SqlNode where)
private void replaceSubqueries(SqlToRelConverter.Blackboard bb, SqlNode expr)
private void substituteSubqueries(SqlToRelConverter.Blackboard bb)
private SaffronRel convertExists(SqlToRelConverter.Blackboard bb, SqlNode seek, SqlNode condition, RexLiteral extraExpr, String extraName)
bb
- seek
- A query, for example 'select * from emp' or 'values (1,2,3)'
or '('Foo', 34)'.condition
- May be null, or a node, or a node listextraExpr
- Column expression to add. "TRUE" for EXISTS and INextraName
- Name of expression to add.
private SaffronRel convertQueryOrInList(SqlToRelConverter.Blackboard bb, SqlNode seek)
private boolean isRowConstructor(SqlNode node)
private static String uniqueFieldName(String[] names, int length, String s)
names
- Array of existing nameslength
- Number of existing namess
- Suggested name
length
positions of the names
array.private static boolean contains(String[] names, int length, String s)
private void findSubqueries(SqlToRelConverter.Blackboard bb, SqlNode node)
IN
or EXISTS
operators
inside SQL parse tree. Does not traverse inside queries.
public static Test suite()
public RexNode convertExpression(SqlToRelConverter.Blackboard bb, SqlNode node)
SqlNode
to RexNode
format.
bb
- Workspacenode
- Expression to translate
private static RexKind mapSqlFunToRex(SqlFunction op)
private RexNode[] convertExpressionList(SqlToRelConverter.Blackboard bb, SqlNode[] nodes)
private void convertFrom(SqlToRelConverter.Blackboard bb, SqlNode from)
bb
- Scope within which to resolve identifiersfrom
- FROM clause of a query. Examples include:
a single table ("SALES.EMP"),
an aliased table ("EMP AS E"),
a list of tables ("EMP, DEPT"),
an ANSI Join expression ("EMP JOIN DEPT ON EMP.DEPTNO = DEPT.DEPTNO"),
a VALUES clause ("VALUES ('Fred', 20)"),
a query ("(SELECT * FROM EMP WHERE GENDER = 'F')"),
or any combination of the above.private JoinRel createJoin(SqlToRelConverter.Blackboard bb, SaffronRel leftRel, SaffronRel rightRel, SqlNode condition, SqlJoinOperator.ConditionType conditionType, int joinType)
private RexNode convertJoinCondition(SqlToRelConverter.Blackboard bb, SqlNode condition, SqlJoinOperator.ConditionType conditionType, SaffronRel leftRel, SaffronRel rightRel)
private static int convertJoinType(SqlJoinOperator.JoinType joinType)
private void convertGroup(SqlToRelConverter.Blackboard bb, SqlNodeList groupList)
bb
- Scope within which to resolve identifiersgroupList
- GROUP BY clause, or nullprivate RexLiteral convertLiteral(SqlLiteral literal)
private void convertOrder(SqlToRelConverter.Blackboard bb, SqlNodeList orderList)
bb
- Scope within which to resolve identifiersorderList
- Order by clause, or nullprivate SaffronRel convertQueryRecursive(SqlNode query)
private SaffronRel convertInsert(SqlInsert call)
private SaffronRel convertDelete(SqlDelete call)
private RexNode convertIdentifier(SqlToRelConverter.Blackboard bb, SqlIdentifier identifier)
private SaffronRel convertRowConstructor(SqlToRelConverter.Blackboard bb, SqlCall rowConstructor)
bb
- rowConstructor
-
private void convertSelectList(SqlToRelConverter.Blackboard bb, SqlNodeList selectList)
private void convertValues(SqlToRelConverter.Blackboard bb, SqlCall values)
VolcanoCluster createCluster(Environment env)
public static HashMap createBinaryMap()
public static HashMap createPrefixMap()
public static HashMap createPostfixMap()
public static HashMap createFunctionMap()
public static SaffronTable getSaffronTable(SqlValidator.Scope scope, SaffronSchema schema)
SaffronTable
. This is only possible if
the scope represents an identifier, such as "sales.emp". Otherwise,
returns null.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |