use of org.apache.jackrabbit.oak.query.ast.LiteralImpl in project jackrabbit-oak by apache.
the class SimpleExcerptProvider method extractFulltext.
private static Set<String> extractFulltext(ConstraintImpl c) {
Set<String> tokens = new HashSet<String>();
// as it will break without us noticing if we extend the AST
if (c instanceof FullTextSearchImpl) {
FullTextSearchImpl f = (FullTextSearchImpl) c;
if (f.getFullTextSearchExpression() instanceof LiteralImpl) {
LiteralImpl l = (LiteralImpl) f.getFullTextSearchExpression();
tokens.add(l.getLiteralValue().getValue(Type.STRING));
}
}
if (c instanceof AndImpl) {
for (ConstraintImpl constraint : ((AndImpl) c).getConstraints()) {
tokens.addAll(extractFulltext(constraint));
}
}
if (c instanceof OrImpl) {
for (ConstraintImpl constraint : ((OrImpl) c).getConstraints()) {
tokens.addAll(extractFulltext(constraint));
}
}
return tokens;
}
use of org.apache.jackrabbit.oak.query.ast.LiteralImpl in project jackrabbit-oak by apache.
the class SimpleExcerptProvider method extractFulltext.
private static Set<String> extractFulltext(ConstraintImpl c) {
Set<String> tokens = new HashSet<String>();
// as it will break without us noticing if we extend the AST
if (c instanceof FullTextSearchImpl) {
FullTextSearchImpl f = (FullTextSearchImpl) c;
if (f.getFullTextSearchExpression() instanceof LiteralImpl) {
LiteralImpl l = (LiteralImpl) f.getFullTextSearchExpression();
tokens.add(l.getLiteralValue().getValue(Type.STRING));
}
}
if (c instanceof AndImpl) {
for (ConstraintImpl constraint : ((AndImpl) c).getConstraints()) {
tokens.addAll(extractFulltext(constraint));
}
}
if (c instanceof OrImpl) {
for (ConstraintImpl constraint : ((OrImpl) c).getConstraints()) {
tokens.addAll(extractFulltext(constraint));
}
}
return tokens;
}
use of org.apache.jackrabbit.oak.query.ast.LiteralImpl in project jackrabbit-oak by apache.
the class SQL2Parser method parseStaticOperand.
private StaticOperandImpl parseStaticOperand() throws ParseException {
if (currentTokenType == PLUS) {
read();
if (currentTokenType != VALUE) {
throw getSyntaxError("number");
}
int valueType = currentValue.getType().tag();
switch(valueType) {
case PropertyType.LONG:
currentValue = PropertyValues.newLong(currentValue.getValue(Type.LONG));
break;
case PropertyType.DOUBLE:
currentValue = PropertyValues.newDouble(currentValue.getValue(Type.DOUBLE));
break;
case PropertyType.DECIMAL:
currentValue = PropertyValues.newDecimal(currentValue.getValue(Type.DECIMAL).negate());
break;
default:
throw getSyntaxError("Illegal operation: + " + currentValue);
}
} else if (currentTokenType == MINUS) {
read();
if (currentTokenType != VALUE) {
throw getSyntaxError("number");
}
int valueType = currentValue.getType().tag();
switch(valueType) {
case PropertyType.LONG:
currentValue = PropertyValues.newLong(-currentValue.getValue(Type.LONG));
break;
case PropertyType.DOUBLE:
currentValue = PropertyValues.newDouble(-currentValue.getValue(Type.DOUBLE));
break;
case PropertyType.BOOLEAN:
currentValue = PropertyValues.newBoolean(!currentValue.getValue(Type.BOOLEAN));
break;
case PropertyType.DECIMAL:
currentValue = PropertyValues.newDecimal(currentValue.getValue(Type.DECIMAL).negate());
break;
default:
throw getSyntaxError("Illegal operation: -" + currentValue);
}
}
if (currentTokenType == VALUE) {
LiteralImpl literal = getUncastLiteral(currentValue);
read();
return literal;
} else if (currentTokenType == PARAMETER) {
read();
String name = readName();
if (readIf(":")) {
name = name + ':' + readName();
}
BindVariableValueImpl var = bindVariables.get(name);
if (var == null) {
var = factory.bindVariable(name);
bindVariables.put(name, var);
}
return var;
} else if (readIf("TRUE")) {
LiteralImpl literal = getUncastLiteral(PropertyValues.newBoolean(true));
return literal;
} else if (readIf("FALSE")) {
LiteralImpl literal = getUncastLiteral(PropertyValues.newBoolean(false));
return literal;
} else if (readIf("CAST")) {
read("(");
StaticOperandImpl op = parseStaticOperand();
if (!(op instanceof LiteralImpl)) {
throw getSyntaxError("literal");
}
LiteralImpl literal = (LiteralImpl) op;
PropertyValue value = literal.getLiteralValue();
read("AS");
value = parseCastAs(value);
read(")");
// CastLiteral
literal = factory.literal(value);
return literal;
} else {
if (supportSQL1) {
if (readIf("TIMESTAMP")) {
StaticOperandImpl op = parseStaticOperand();
if (!(op instanceof LiteralImpl)) {
throw getSyntaxError("literal");
}
LiteralImpl literal = (LiteralImpl) op;
PropertyValue value = literal.getLiteralValue();
value = PropertyValues.newDate(value.getValue(Type.DATE));
literal = factory.literal(value);
return literal;
}
}
throw getSyntaxError("static operand");
}
}
use of org.apache.jackrabbit.oak.query.ast.LiteralImpl in project jackrabbit-oak by apache.
the class SQL2Parser method parseCondition.
private ConstraintImpl parseCondition(DynamicOperandImpl left) throws ParseException {
ConstraintImpl c;
if (readIf("=")) {
c = factory.comparison(left, Operator.EQUAL, parseStaticOperand());
} else if (readIf("<>")) {
c = factory.comparison(left, Operator.NOT_EQUAL, parseStaticOperand());
} else if (readIf("<")) {
c = factory.comparison(left, Operator.LESS_THAN, parseStaticOperand());
} else if (readIf(">")) {
c = factory.comparison(left, Operator.GREATER_THAN, parseStaticOperand());
} else if (readIf("<=")) {
c = factory.comparison(left, Operator.LESS_OR_EQUAL, parseStaticOperand());
} else if (readIf(">=")) {
c = factory.comparison(left, Operator.GREATER_OR_EQUAL, parseStaticOperand());
} else if (readIf("LIKE")) {
c = factory.comparison(left, Operator.LIKE, parseStaticOperand());
if (supportSQL1) {
if (readIf("ESCAPE")) {
StaticOperandImpl esc = parseStaticOperand();
if (!(esc instanceof LiteralImpl)) {
throw getSyntaxError("only ESCAPE '\' is supported");
}
PropertyValue v = ((LiteralImpl) esc).getLiteralValue();
if (!v.getValue(Type.STRING).equals("\\")) {
throw getSyntaxError("only ESCAPE '\' is supported");
}
}
}
} else if (readIf("IN")) {
read("(");
ArrayList<StaticOperandImpl> list = new ArrayList<StaticOperandImpl>();
do {
StaticOperandImpl x = parseStaticOperand();
list.add(x);
} while (readIf(","));
read(")");
c = factory.in(left, list);
} else if (readIf("IS")) {
boolean not = readIf("NOT");
read("NULL");
if (!(left instanceof PropertyValueImpl)) {
throw getSyntaxError("propertyName (NOT NULL is only supported for properties)");
}
PropertyValueImpl p = (PropertyValueImpl) left;
if (not) {
c = getPropertyExistence(p);
} else {
c = getPropertyInexistence(p);
}
} else if (readIf("NOT")) {
if (readIf("IS")) {
read("NULL");
if (!(left instanceof PropertyValueImpl)) {
throw new ParseException("Only property values can be tested for NOT IS NULL; got: " + left.getClass().getName(), parseIndex);
}
PropertyValueImpl pv = (PropertyValueImpl) left;
c = getPropertyExistence(pv);
} else {
read("LIKE");
c = factory.comparison(left, Operator.LIKE, parseStaticOperand());
c = factory.not(c);
}
} else {
throw getSyntaxError();
}
return c;
}
use of org.apache.jackrabbit.oak.query.ast.LiteralImpl 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(CoalesceImpl node) {
node.setQuery(query);
return super.visit(node);
}
@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 (QueryConstants.JCR_SCORE.equals(c.getPropertyName())) {
distinct = false;
}
distinctColumns[i] = distinct;
}
init = true;
}
Aggregations