use of org.h2.table.TableFilter in project ignite by apache.
the class GridH2CollocationModel method childFilters.
/**
* @param childFilters New child filters.
* @return {@code true} If child filters were updated.
*/
private boolean childFilters(TableFilter[] childFilters) {
assert childFilters != null;
assert view;
Select select = childFilters[0].getSelect();
assert this.select == null || this.select == select;
if (this.select == null) {
this.select = select;
assert this.childFilters == null;
} else if (Arrays.equals(this.childFilters, childFilters))
return false;
if (this.childFilters == null) {
// We have to clone because H2 reuses array and reorders elements.
this.childFilters = childFilters.clone();
children = new GridH2CollocationModel[childFilters.length];
} else {
assert this.childFilters.length == childFilters.length;
// We have to copy because H2 reuses array and reorders elements.
System.arraycopy(childFilters, 0, this.childFilters, 0, childFilters.length);
Arrays.fill(children, null);
}
// Reset results.
type = null;
multiplier = 0;
return true;
}
use of org.h2.table.TableFilter in project ignite by apache.
the class GridH2CollocationModel method buildCollocationModel.
/**
* @param qctx Query context.
* @param info Sub-query info.
* @param filters Filters.
* @param filter Filter.
* @param validate Query validation flag.
* @return Collocation.
*/
public static GridH2CollocationModel buildCollocationModel(GridH2QueryContext qctx, SubQueryInfo info, TableFilter[] filters, int filter, boolean validate) {
GridH2CollocationModel cm;
if (info != null) {
// Go up until we reach the root query.
cm = buildCollocationModel(qctx, info.getUpper(), info.getFilters(), info.getFilter(), validate);
} else {
// We are at the root query.
cm = qctx.queryCollocationModel();
if (cm == null) {
cm = createChildModel(null, -1, null, true, validate);
qctx.queryCollocationModel(cm);
}
}
assert cm.view;
Select select = filters[0].getSelect();
// For sub-queries we will drop collocation models, so that they will be recalculated anyways.
if (cm.select != null && cm.select != select) {
List<GridH2CollocationModel> unions = cm.getOrCreateUnions();
// Start with 1 because at 0 it always will be c.
for (int i = 1; i < unions.size(); i++) {
GridH2CollocationModel u = unions.get(i);
if (u.select == select) {
cm = u;
break;
}
}
// Nothing was found, need to create new child in union.
if (cm.select != select)
cm = createChildModel(cm.upper, cm.filter, unions, true, validate);
}
cm.childFilters(filters);
return cm.child(filter, true);
}
use of org.h2.table.TableFilter in project h2database by h2database.
the class Parser method parseMerge.
private Prepared parseMerge() {
Merge command = new Merge(session);
currentPrepared = command;
int start = lastParseIndex;
read("INTO");
List<String> excludeIdentifiers = Arrays.asList("USING", "KEY", "VALUES");
TableFilter targetTableFilter = readSimpleTableFilter(0, excludeIdentifiers);
command.setTargetTableFilter(targetTableFilter);
Table table = command.getTargetTable();
if (readIf("USING")) {
return parseMergeUsing(command, start);
}
if (readIf("(")) {
if (isSelect()) {
command.setQuery(parseSelect());
read(")");
return command;
}
Column[] columns = parseColumnList(table);
command.setColumns(columns);
}
if (readIf("KEY")) {
read("(");
Column[] keys = parseColumnList(table);
command.setKeys(keys);
}
if (readIf("VALUES")) {
do {
ArrayList<Expression> values = New.arrayList();
read("(");
if (!readIf(")")) {
do {
if (readIf("DEFAULT")) {
values.add(null);
} else {
values.add(readExpression());
}
} while (readIfMore(false));
}
command.addRow(values.toArray(new Expression[0]));
} while (readIf(","));
} else {
command.setQuery(parseSelect());
}
return command;
}
use of org.h2.table.TableFilter in project h2database by h2database.
the class Parser method parseSelectSimpleFromPart.
private void parseSelectSimpleFromPart(Select command) {
do {
TableFilter filter = readTableFilter();
parseJoinTableFilter(filter, command);
} while (readIf(","));
// to get the order as it was in the original query.
if (session.isForceJoinOrder()) {
sortTableFilters(command.getTopFilters());
}
}
use of org.h2.table.TableFilter in project h2database by h2database.
the class Parser method parseMergeUsing.
private MergeUsing parseMergeUsing(Merge oldCommand, int start) {
MergeUsing command = new MergeUsing(oldCommand);
currentPrepared = command;
if (readIf("(")) {
/* a select query is supplied */
if (isSelect()) {
command.setQuery(parseSelect());
read(")");
}
command.setQueryAlias(readFromAlias(null, Collections.singletonList("ON")));
String[] querySQLOutput = { null };
List<Column> columnTemplateList = TableView.createQueryColumnTemplateList(null, command.getQuery(), querySQLOutput);
TableView temporarySourceTableView = createCTEView(command.getQueryAlias(), querySQLOutput[0], columnTemplateList, false, /* no recursion */
false, /* do not add to session */
false, /* isPersistent */
session);
TableFilter sourceTableFilter = new TableFilter(session, temporarySourceTableView, command.getQueryAlias(), rightsChecked, (Select) command.getQuery(), 0, null);
command.setSourceTableFilter(sourceTableFilter);
} else {
/* Its a table name, simulate a query by building a select query for the table */
List<String> excludeIdentifiers = Collections.singletonList("ON");
TableFilter sourceTableFilter = readSimpleTableFilter(0, excludeIdentifiers);
command.setSourceTableFilter(sourceTableFilter);
StringBuilder buff = new StringBuilder("SELECT * FROM ");
appendTableWithSchemaAndAlias(buff, sourceTableFilter.getTable(), sourceTableFilter.getTableAlias());
Prepared preparedQuery = prepare(session, buff.toString(), null);
command.setQuery((Select) preparedQuery);
}
read("ON");
read("(");
Expression condition = readExpression();
command.setOnCondition(condition);
read(")");
if (readIfAll("WHEN", "MATCHED", "THEN")) {
int startMatched = lastParseIndex;
if (readIf("UPDATE")) {
Update updateCommand = new Update(session);
// currentPrepared = updateCommand;
TableFilter filter = command.getTargetTableFilter();
updateCommand.setTableFilter(filter);
parseUpdateSetClause(updateCommand, filter, startMatched);
command.setUpdateCommand(updateCommand);
}
startMatched = lastParseIndex;
if (readIf("DELETE")) {
Delete deleteCommand = new Delete(session);
TableFilter filter = command.getTargetTableFilter();
deleteCommand.setTableFilter(filter);
parseDeleteGivenTable(deleteCommand, null, startMatched);
command.setDeleteCommand(deleteCommand);
}
}
if (readIfAll("WHEN", "NOT", "MATCHED", "THEN")) {
if (readIf("INSERT")) {
Insert insertCommand = new Insert(session);
insertCommand.setTable(command.getTargetTable());
parseInsertGivenTable(insertCommand, command.getTargetTable());
command.setInsertCommand(insertCommand);
}
}
setSQL(command, "MERGE", start);
// build and prepare the targetMatchQuery ready to test each rows
// existence in the target table (using source row to match)
StringBuilder targetMatchQuerySQL = new StringBuilder("SELECT _ROWID_ FROM ");
appendTableWithSchemaAndAlias(targetMatchQuerySQL, command.getTargetTable(), command.getTargetTableFilter().getTableAlias());
targetMatchQuerySQL.append(" WHERE ").append(command.getOnCondition().getSQL());
command.setTargetMatchQuery((Select) parse(targetMatchQuerySQL.toString()));
return command;
}
Aggregations