use of org.apache.jackrabbit.oak.query.ast.ColumnImpl in project jackrabbit-oak by apache.
the class QueryImpl method copyOf.
@Override
public Query copyOf() {
if (isInit()) {
throw new IllegalStateException("QueryImpl cannot be cloned once initialised.");
}
List<ColumnImpl> cols = newArrayList();
for (ColumnImpl c : columns) {
cols.add((ColumnImpl) copyElementAndCheckReference(c));
}
QueryImpl copy = new QueryImpl(this.statement, (SourceImpl) copyElementAndCheckReference(this.source), this.constraint, cols.toArray(new ColumnImpl[0]), this.namePathMapper, this.settings);
copy.explain = this.explain;
copy.distinct = this.distinct;
return copy;
}
use of org.apache.jackrabbit.oak.query.ast.ColumnImpl in project jackrabbit-oak by apache.
the class QueryImpl method init.
@Override
public void init() {
final QueryImpl query = this;
if (constraint != null) {
// need to do this *before* the visitation below, as the
// simplify() method does not always keep the query reference
// passed in setQuery(). TODO: avoid that mutability concern
constraint = constraint.simplify();
}
new AstVisitorBase() {
@Override
public boolean visit(BindVariableValueImpl node) {
node.setQuery(query);
bindVariableMap.put(node.getBindVariableName(), null);
return true;
}
@Override
public boolean visit(ChildNodeImpl node) {
node.setQuery(query);
node.bindSelector(source);
return true;
}
@Override
public boolean visit(ChildNodeJoinConditionImpl node) {
node.setQuery(query);
node.bindSelector(source);
return true;
}
@Override
public boolean visit(ColumnImpl node) {
node.setQuery(query);
return true;
}
@Override
public boolean visit(DescendantNodeImpl node) {
node.setQuery(query);
node.bindSelector(source);
return true;
}
@Override
public boolean visit(DescendantNodeJoinConditionImpl node) {
node.setQuery(query);
node.bindSelector(source);
return true;
}
@Override
public boolean visit(EquiJoinConditionImpl node) {
node.setQuery(query);
node.bindSelector(source);
return true;
}
@Override
public boolean visit(FullTextSearchImpl node) {
node.setQuery(query);
node.bindSelector(source);
return super.visit(node);
}
@Override
public boolean visit(NativeFunctionImpl node) {
node.setQuery(query);
node.bindSelector(source);
return super.visit(node);
}
@Override
public boolean visit(SimilarImpl node) {
node.setQuery(query);
node.bindSelector(source);
return super.visit(node);
}
@Override
public boolean visit(SpellcheckImpl node) {
node.setQuery(query);
node.bindSelector(source);
return super.visit(node);
}
@Override
public boolean visit(SuggestImpl node) {
node.setQuery(query);
node.bindSelector(source);
return super.visit(node);
}
@Override
public boolean visit(FullTextSearchScoreImpl node) {
node.setQuery(query);
node.bindSelector(source);
return true;
}
@Override
public boolean visit(LiteralImpl node) {
node.setQuery(query);
return true;
}
@Override
public boolean visit(NodeLocalNameImpl node) {
node.setQuery(query);
node.bindSelector(source);
return true;
}
@Override
public boolean visit(NodeNameImpl node) {
node.setQuery(query);
node.bindSelector(source);
return true;
}
@Override
public boolean visit(PropertyExistenceImpl node) {
node.setQuery(query);
node.bindSelector(source);
return true;
}
@Override
public boolean visit(PropertyInexistenceImpl node) {
node.setQuery(query);
node.bindSelector(source);
return true;
}
@Override
public boolean visit(PropertyValueImpl node) {
node.setQuery(query);
node.bindSelector(source);
return true;
}
@Override
public boolean visit(SameNodeImpl node) {
node.setQuery(query);
node.bindSelector(source);
return true;
}
@Override
public boolean visit(SameNodeJoinConditionImpl node) {
node.setQuery(query);
node.bindSelector(source);
return true;
}
@Override
public boolean visit(SelectorImpl node) {
String name = node.getSelectorName();
if (selectorIndexes.put(name, selectors.size()) != null) {
throw new IllegalArgumentException("Two selectors with the same name: " + name);
}
selectors.add(node);
node.setQuery(query);
return true;
}
@Override
public boolean visit(LengthImpl node) {
node.setQuery(query);
return super.visit(node);
}
@Override
public boolean visit(UpperCaseImpl node) {
node.setQuery(query);
return super.visit(node);
}
@Override
public boolean visit(LowerCaseImpl node) {
node.setQuery(query);
return super.visit(node);
}
@Override
public boolean visit(ComparisonImpl node) {
node.setQuery(query);
return super.visit(node);
}
@Override
public boolean visit(InImpl node) {
node.setQuery(query);
return super.visit(node);
}
@Override
public boolean visit(AndImpl node) {
node.setQuery(query);
return super.visit(node);
}
@Override
public boolean visit(OrImpl node) {
node.setQuery(query);
return super.visit(node);
}
@Override
public boolean visit(NotImpl node) {
node.setQuery(query);
return super.visit(node);
}
}.visit(this);
source.setQueryConstraint(constraint);
for (ColumnImpl column : columns) {
column.bindSelector(source);
}
distinctColumns = new boolean[columns.length];
for (int i = 0; i < columns.length; i++) {
ColumnImpl c = columns[i];
boolean distinct = true;
if (JCR_SCORE.equals(c.getPropertyName())) {
distinct = false;
}
distinctColumns[i] = distinct;
}
init = true;
}
use of org.apache.jackrabbit.oak.query.ast.ColumnImpl in project jackrabbit-oak by apache.
the class UnionQueryImpl method getRows.
@Override
public Iterator<ResultRowImpl> getRows() {
prepare();
if (explain) {
String plan = getPlan();
columns = new ColumnImpl[] { new ColumnImpl("explain", "plan", "plan") };
ResultRowImpl r = new ResultRowImpl(this, Tree.EMPTY_ARRAY, new PropertyValue[] { PropertyValues.newString(plan) }, null, null);
return Arrays.asList(r).iterator();
}
if (LOG.isDebugEnabled()) {
if (isInternal) {
LOG.trace("query union plan {}", getPlan());
} else {
LOG.debug("query union plan {}", getPlan());
}
}
boolean distinct = !unionAll;
Comparator<ResultRowImpl> orderBy = ResultRowImpl.getComparator(orderings);
Iterator<ResultRowImpl> it;
final Iterator<ResultRowImpl> leftRows = left.getRows();
final Iterator<ResultRowImpl> rightRows = right.getRows();
Iterator<ResultRowImpl> leftIter = leftRows;
Iterator<ResultRowImpl> rightIter = rightRows;
// if measure retrieve the backing delegate iterator instead
if (measure) {
leftIter = ((MeasuringIterator) leftRows).getDelegate();
rightIter = ((MeasuringIterator) rightRows).getDelegate();
}
// Since sorted by index use a merge iterator
if (isSortedByIndex()) {
it = FilterIterators.newCombinedFilter(Iterators.mergeSorted(ImmutableList.of(leftIter, rightIter), orderBy), distinct, limit, offset, null, settings);
} else {
it = FilterIterators.newCombinedFilter(Iterators.concat(leftIter, rightIter), distinct, limit, offset, orderBy, settings);
}
if (measure) {
// return the measuring iterator for the union
it = new MeasuringIterator(this, it) {
MeasuringIterator left = (MeasuringIterator) leftRows;
MeasuringIterator right = (MeasuringIterator) rightRows;
@Override
protected void setColumns(ColumnImpl[] cols) {
columns = cols;
left.setColumns(cols);
right.setColumns(cols);
}
@Override
protected Map<String, Long> getSelectorScanCount() {
// Merge the 2 maps from the left and right queries to get the selector counts
Map<String, Long> leftSelectorScan = left.getSelectorScanCount();
Map<String, Long> rightSelectorScan = right.getSelectorScanCount();
Map<String, Long> unionScan = Maps.newHashMap(leftSelectorScan);
for (String key : rightSelectorScan.keySet()) {
if (unionScan.containsKey(key)) {
unionScan.put(key, rightSelectorScan.get(key) + unionScan.get(key));
} else {
unionScan.put(key, rightSelectorScan.get(key));
}
}
return unionScan;
}
@Override
protected long getReadCount() {
return left.getReadCount() + right.getReadCount();
}
};
}
return it;
}
use of org.apache.jackrabbit.oak.query.ast.ColumnImpl in project jackrabbit-oak by apache.
the class QueryImpl method getRows.
@Override
public Iterator<ResultRowImpl> getRows() {
prepare();
if (explain) {
String plan = getPlan();
if (measure) {
plan += " cost: { " + getIndexCostInfo() + " }";
}
columns = new ColumnImpl[] { new ColumnImpl("explain", "plan", "plan") };
ResultRowImpl r = new ResultRowImpl(this, Tree.EMPTY_ARRAY, new PropertyValue[] { PropertyValues.newString(plan) }, null, null);
return Arrays.asList(r).iterator();
}
if (LOG.isDebugEnabled()) {
logDebug("query execute " + statement);
logDebug("query plan " + getPlan());
}
final RowIterator rowIt = new RowIterator(context.getBaseState());
Comparator<ResultRowImpl> orderBy;
if (isSortedByIndex) {
orderBy = null;
} else {
orderBy = ResultRowImpl.getComparator(orderings);
}
Iterator<ResultRowImpl> it = FilterIterators.newCombinedFilter(rowIt, distinct, limit, offset, orderBy, settings);
if (orderBy != null) {
// this will force the rows to be read, so that the size is known
it.hasNext();
// we need the size, and there is no other way to get it right now
// but we also have to take limit and offset into account
long read = rowIt.getReadCount();
// we will ignore whatever is behind 'limit+offset'
read = Math.min(saturatedAdd(limit, offset), read);
// and we will skip 'offset' entries
read = Math.max(0, read - offset);
size = read;
}
if (measure) {
// return the measuring iterator delegating the readCounts to the rowIterator
it = new MeasuringIterator(this, it) {
@Override
protected void setColumns(ColumnImpl[] col) {
columns = col;
}
@Override
protected long getReadCount() {
return rowIt.getReadCount();
}
@Override
protected Map<String, Long> getSelectorScanCount() {
Map<String, Long> selectorReadCounts = Maps.newHashMap();
for (SelectorImpl selector : selectors) {
selectorReadCounts.put(selector.getSelectorName(), selector.getScanCount());
}
return selectorReadCounts;
}
};
}
return it;
}
use of org.apache.jackrabbit.oak.query.ast.ColumnImpl in project jackrabbit-oak by apache.
the class ResultImpl method getColumnSelectorNames.
@Override
public String[] getColumnSelectorNames() {
ArrayList<String> list = new ArrayList<String>();
for (ColumnImpl c : query.getColumns()) {
SelectorImpl selector = c.getSelector();
String name = selector == null ? null : selector.getSelectorName();
if (!list.contains(name)) {
list.add(name);
}
}
return list.toArray(new String[list.size()]);
}
Aggregations