ViewType viewTypeToBe = null;
Scan scan = new Scan();
final StatementContext context = new StatementContext(statement, resolver, statement.getParameters(), scan);
ExpressionCompiler expressionCompiler = new ExpressionCompiler(context);
ParseNode whereNode = create.getWhereClause();
Expression where = null;
if (type == PTableType.VIEW) {
TableRef tableRef = resolver.getTables().get(0);
parentToBe = tableRef.getTable();
viewTypeToBe = parentToBe.getViewType() == ViewType.MAPPED ? ViewType.MAPPED : ViewType.UPDATABLE;
if (whereNode != null) {
if (whereNode.isStateless()) {
throw new SQLExceptionInfo.Builder(SQLExceptionCode.VIEW_WHERE_IS_CONSTANT)
.build().buildException();
}
whereNode = StatementNormalizer.normalize(whereNode, resolver);
where = whereNode.accept(expressionCompiler);
if (expressionCompiler.isAggregate()) {
throw new SQLExceptionInfo.Builder(SQLExceptionCode.AGGREGATE_IN_WHERE).build().buildException();
}
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());
ViewWhereExpressionVisitor visitor = new ViewWhereExpressionVisitor();
where.accept(visitor);
viewTypeToBe = visitor.isUpdatable() ? ViewType.UPDATABLE : ViewType.READ_ONLY;
}
}
}
final Expression viewExpression = where;
final ViewType viewType = viewTypeToBe;
List<ParseNode> splitNodes = create.getSplitNodes();
final byte[][] splits = new byte[splitNodes.size()][];
ImmutableBytesWritable ptr = context.getTempPtr();
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)