// If our parent has a VIEW statement, combine it with this one
if (parentToBe.getViewStatement() != null) {
SelectStatement select = new SQLParser(parentToBe.getViewStatement()).parseQuery().combine(whereNode);
whereNode = select.getWhere();
}
Expression where = whereNode.accept(expressionCompiler);
if (where != null && !LiteralExpression.isTrue(where)) {
TableName baseTableName = create.getBaseTableName();
String schemaName = baseTableName.getSchemaName();
// Only form we currently support for VIEWs: SELECT * FROM t WHERE ...
viewStatementToBe = SELECT + " " + WildcardParseNode.NAME + " " + FROM + " " +
(schemaName == null ? "" : "\"" + schemaName + "\".") +
("\"" + baseTableName.getTableName() + "\" ") +
(WHERE + " " + where.toString());
}
if (viewTypeToBe != ViewType.MAPPED) {
Long scn = connection.getSCN();
connectionToBe = scn != null ? connection :
// If we haved no SCN on our connection, freeze the SCN at when
// the base table was resolved to prevent any race condition on
// the error checking we do for the base table. The only potential
// issue is if the base table lives on a different region server
// than the new table will, then we're relying here on the system
// clocks being in sync.
new PhoenixConnection(
// When the new table is created, we still want to cache it
// on our connection.
new DelegateConnectionQueryServices(connection.getQueryServices()) {
@Override
public PMetaData addTable(PTable table) throws SQLException {
return connection.addTable(table);
}
},
connection, tableRef.getTimeStamp());
viewColumnConstantsToBe = new byte[nColumns][];
ViewWhereExpressionVisitor visitor = new ViewWhereExpressionVisitor(parentToBe, viewColumnConstantsToBe);
where.accept(visitor);
// If view is not updatable, viewColumnConstants should be empty. We will still
// inherit our parent viewConstants, but we have no additional ones.
viewTypeToBe = visitor.isUpdatable() ? ViewType.UPDATABLE : ViewType.READ_ONLY;
if (viewTypeToBe != ViewType.UPDATABLE) {
viewColumnConstantsToBe = null;
}
}
}
}
final ViewType viewType = viewTypeToBe;
final String viewStatement = viewStatementToBe;
final byte[][] viewColumnConstants = viewColumnConstantsToBe;
final BitSet isViewColumnReferenced = isViewColumnReferencedToBe;
List<ParseNode> splitNodes = create.getSplitNodes();
final byte[][] splits = new byte[splitNodes.size()][];
ImmutableBytesWritable ptr = context.getTempPtr();
ExpressionCompiler expressionCompiler = new ExpressionCompiler(context);
for (int i = 0; i < splits.length; i++) {
ParseNode node = splitNodes.get(i);
if (node.isStateless()) {
Expression expression = node.accept(expressionCompiler);
if (expression.evaluate(null, ptr)) {;
splits[i] = ByteUtil.copyKeyBytesIfNecessary(ptr);
continue;
}
}
throw new SQLExceptionInfo.Builder(SQLExceptionCode.SPLIT_POINT_NOT_CONSTANT)