@Override public boolean equals(Object obj) { if (!(obj instanceof ConstantExpression)) { return false; } else { return value.equals(((ConstantExpression) obj).getValue()); } }
@Override public Object getType(ILogicalExpression expr, IMetadataProvider<?, ?> metadataProvider, IVariableTypeEnvironment env) throws AlgebricksException { if (expr.getExpressionTag() == LogicalExpressionTag.CONSTANT) { ConstantExpression ce = (ConstantExpression) expr; IAlgebricksConstantValue acv = ce.getValue(); if (acv == ConstantExpression.TRUE.getValue() || acv == ConstantExpression.FALSE.getValue()) { return SequenceType.create(BuiltinTypeRegistry.XS_BOOLEAN, Quantifier.QUANT_ONE); } VXQueryConstantValue cv = (VXQueryConstantValue) acv; return cv.getType(); } return null; } });
private int readKeyInclusives(List<Mutable<ILogicalExpression>> funcArgs, int index) { lowKeyInclusive = ((ConstantExpression) funcArgs.get(index).getValue()).getValue().isTrue(); // Read the next function argument at index + 1. highKeyInclusive = ((ConstantExpression) funcArgs.get(index + 1).getValue()).getValue().isTrue(); // We have read two of the function arguments, so the next index is at index + 2. return index + 2; }
private void readIsEqCondition(List<Mutable<ILogicalExpression>> funcArgs, int index) { isEqCondition = ((ConstantExpression) funcArgs.get(index).getValue()).getValue().isTrue(); }
public static boolean isAlwaysTrueCond(ILogicalExpression cond) { if (cond.getExpressionTag() == LogicalExpressionTag.CONSTANT) { return ((ConstantExpression) cond).getValue().isTrue(); } return false; }
@Override public ILogicalExpression visitConstantExpression(ConstantExpression expr, Void arg) throws AlgebricksException { ConstantExpression exprCopy = new ConstantExpression(expr.getValue()); copySourceLocation(expr, exprCopy); return exprCopy; }
@Override public String visitConstantExpression(ConstantExpression expr, Integer indent) throws AlgebricksException { IAlgebricksConstantValue value = expr.getValue(); if (value instanceof VXQueryConstantValue) { VXQueryConstantValue vxqValue = (VXQueryConstantValue) value; tvp.set(vxqValue.getValue(), 0, vxqValue.getValue().length); serializer.printTaggedValuePointable(ps, tvp); try { return vxqValue.getType() + ": " + os.toString("UTF8"); } catch (UnsupportedEncodingException e) { // print stack trace and return the default e.printStackTrace(); } finally { ps.flush(); os.reset(); } } return value.toString(); }
private IScalarEvaluatorFactory createConstantEvaluatorFactory(ConstantExpression expr, JobGenContext context) throws AlgebricksException { MetadataProvider metadataProvider = (MetadataProvider) context.getMetadataProvider(); return metadataProvider.getDataFormat().getConstantEvalFactory(expr.getValue()); }
public static void getConstantAsPointable(ConstantExpression typeExpression, TaggedValuePointable tvp) { VXQueryConstantValue treatTypeConstant = (VXQueryConstantValue) typeExpression.getValue(); tvp.set(treatTypeConstant.getValue(), 0, treatTypeConstant.getValue().length); }
private boolean setFieldNameSet(ILogicalExpression expr, Set<String> fieldNameSet) { if (expr.getExpressionTag() == LogicalExpressionTag.CONSTANT) { AOrderedList orderedList = (AOrderedList) (((AsterixConstantValue) ((ConstantExpression) expr).getValue()).getObject()); for (int i = 0; i < orderedList.size(); i++) { AString as = (AString) orderedList.getItem(i); fieldNameSet.add(as.getStringValue()); } return true; // Success } return false; }
private List<String> getListFromExpression(String funcName, ILogicalExpression expression, SourceLocation sourceLoc) throws AlgebricksException { AbstractFunctionCallExpression funcExp = (AbstractFunctionCallExpression) expression; List<Mutable<ILogicalExpression>> args = funcExp.getArguments(); List<String> list = new ArrayList<>(); for (Mutable<ILogicalExpression> arg : args) { // At this point all elements has to be a constant // Input list has only one level of nesting (list of list or list of strings) ConstantExpression ce = (ConstantExpression) arg.getValue(); if (!(ce.getValue() instanceof AsterixConstantValue)) { throw new InvalidExpressionException(sourceLoc, funcName, 1, ce, LogicalExpressionTag.CONSTANT); } IAObject item = ((AsterixConstantValue) ce.getValue()).getObject(); ATypeTag type = item.getType().getTypeTag(); if (type == ATypeTag.STRING) { list.add(((AString) item).getStringValue()); } else { throw new UnsupportedTypeException(sourceLoc, funcName, type); } } return list; }
public static IAObject getConstantIaObject(ILogicalExpression expr, ATypeTag typeTag) { if (expr.getExpressionTag() != LogicalExpressionTag.CONSTANT) { return null; } final IAlgebricksConstantValue acv = ((ConstantExpression) expr).getValue(); if (!(acv instanceof AsterixConstantValue)) { return null; } final IAObject iaObject = ((AsterixConstantValue) acv).getObject(); if (typeTag != null) { return iaObject.getType().getTypeTag() == typeTag ? iaObject : null; } else { return iaObject; } }
@Override public void readFromFuncArgs(List<Mutable<ILogicalExpression>> funcArgs) { super.readFromFuncArgs(funcArgs); int index = super.getNumParams(); // Read search modifier type. int searchModifierOrdinal = AccessMethodUtils.getInt32Constant(funcArgs.get(index + SEARCH_MODIFIER_INDEX)); searchModifierType = SearchModifierType.values()[searchModifierOrdinal]; // Read similarity threshold. Concrete type depends on search modifier. similarityThreshold = ((ConstantExpression) funcArgs.get(index + SIM_THRESHOLD_INDEX).getValue()).getValue(); // Read type of search key. int typeTagOrdinal = AccessMethodUtils.getInt32Constant(funcArgs.get(index + SEARCH_KEY_TYPE_INDEX)); searchKeyType = ATypeTag.values()[typeTagOrdinal]; // Read full-text search information. isFullTextSearchQuery = AccessMethodUtils.getBooleanConstant(funcArgs.get(index + IS_FULLTEXT_SEARCH_INDEX)); // Read key var list. keyVarList = new ArrayList<>(); readVarList(funcArgs, index + KEY_VAR_INDEX, keyVarList); // TODO: We could possibly simplify things if we did read the non-key var list here. // We don't need to read the non-key var list. nonKeyVarList = null; }
protected String getString(List<Mutable<ILogicalExpression>> args, int i) throws AlgebricksException { ConstantExpression ce = (ConstantExpression) args.get(i).getValue(); IAlgebricksConstantValue acv = ce.getValue(); if (!(acv instanceof AsterixConstantValue)) { throw new AlgebricksException("Expected arg[" + i + "] to be of type String"); } AsterixConstantValue acv2 = (AsterixConstantValue) acv; if (acv2.getObject().getType().getTypeTag() != ATypeTag.STRING) { throw new AlgebricksException("Expected arg[" + i + "] to be of type String"); } return ((AString) acv2.getObject()).getStringValue(); }
private boolean isFullTextContainsFuncSelectOptimizable(Index index, IOptimizableFuncExpr optFuncExpr) { AsterixConstantValue strConstVal = (AsterixConstantValue) ((ConstantExpression) optFuncExpr.getConstantExpr(0)).getValue(); IAObject strObj = strConstVal.getObject(); ATypeTag typeTag = strObj.getType().getTypeTag(); return isFullTextContainsFuncCompatible(typeTag, index.getIndexType()); }
private IAType getTypeForConstant(ConstantExpression expr, IVariableTypeEnvironment env) { IAlgebricksConstantValue acv = expr.getValue(); if (acv.isFalse() || acv.isTrue()) { return BuiltinType.ABOOLEAN; } else if (acv.isMissing()) { return BuiltinType.AMISSING; } else if (acv.isNull()) { return BuiltinType.ANULL; } else { AsterixConstantValue value = (AsterixConstantValue) acv; return value.getObject().getType(); } }
protected SequenceType getSequenceType(final ConstantExpression cTypeEx) { final VXQueryConstantValue typeCodeVal = (VXQueryConstantValue) cTypeEx.getValue(); tvp.set(typeCodeVal.getValue(), 0, typeCodeVal.getValue().length); assert tvp.getTag() == ValueTag.XS_INT_TAG; tvp.getValue(ip); int typeCode = ip.getInteger(); SequenceType type = ctx.lookupSequenceType(typeCode); return type; }
@Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context, CompilerProperties compilerProps) throws AlgebricksException { AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expr; IAType t = (IAType) context.getType(fce.getArguments().get(0).getValue()); AOrderedList fieldPath = (AOrderedList) (((AsterixConstantValue) ((ConstantExpression) fce.getArguments().get(1).getValue()) .getValue()).getObject()); List<String> listFieldPath = new ArrayList<>(); for (int i = 0; i < fieldPath.size(); i++) { listFieldPath.add(((AString) fieldPath.getItem(i)).getStringValue()); } switch (t.getTypeTag()) { case OBJECT: { fd.setImmutableStates(t, listFieldPath); break; } case ANY: fd.setImmutableStates(RecordUtil.FULLY_OPEN_RECORD_TYPE, listFieldPath); break; default: { throw new NotImplementedException("field-access-nested for data of type " + t); } } } }
private boolean isContainsFuncSelectOptimizable(Index index, IOptimizableFuncExpr optFuncExpr) { AsterixConstantValue strConstVal = (AsterixConstantValue) ((ConstantExpression) optFuncExpr.getConstantExpr(0)).getValue(); IAObject strObj = strConstVal.getObject(); ATypeTag typeTag = strObj.getType().getTypeTag(); if (!isContainsFuncCompatible(typeTag, index.getIndexType())) { return false; } // Check that the constant search string has at least gramLength characters. if (strObj.getType().getTypeTag() == ATypeTag.STRING) { AString astr = (AString) strObj; if (astr.getStringValue().length() >= index.getGramLength()) { return true; } } return false; }
private Pair<ILogicalExpression, List<String>> getFieldExpression(AssignOperator access, ARecordType rt) { LinkedList<String> fieldPath = new LinkedList<>(); ILogicalExpression e0 = access.getExpressions().get(0).getValue(); while (AnalysisUtil.isAccessToFieldRecord(e0)) { ILogicalExpression e1 = ((AbstractFunctionCallExpression) e0).getArguments().get(1).getValue(); if (e1.getExpressionTag() != LogicalExpressionTag.CONSTANT) { return new Pair<>(null, null); } ConstantExpression ce = (ConstantExpression) e1; IAObject obj = ((AsterixConstantValue) ce.getValue()).getObject(); String fldName; if (obj.getType().getTypeTag() == ATypeTag.STRING) { fldName = ((AString) obj).getStringValue(); } else { int pos = ((AInt32) obj).getIntegerValue(); if (pos >= rt.getFieldNames().length) { return new Pair<>(null, null); } fldName = rt.getFieldNames()[pos]; } fieldPath.addFirst(fldName); e0 = ((AbstractFunctionCallExpression) e0).getArguments().get(0).getValue(); } return new Pair<>(e0, fieldPath); }