Пример #1
0
  /**
   * Methods to create a {@link Function} starting from a {@link IsNullExpression}
   *
   * @param pred IsNullExpression
   * @param lookupTable
   * @return a function from the OBDADataFactory
   */
  private Function getFunction(IsNullExpression pred, LookupTable lookupTable) {

    Expression column = pred.getLeftExpression();
    String columnName = column.toString();
    String variableName = lookupTable.lookup(columnName);
    if (variableName == null) {
      throw new RuntimeException("Unable to find column name for variable: " + columnName);
    }
    Term var = dfac.getVariable(variableName);

    if (!pred.isNot()) {
      return dfac.getFunctionIsNull(var);
    } else {
      return dfac.getFunctionIsNotNull(var);
    }
  }
 private Expression isExpressionBound(Expression expr) {
   expr = DataTypeHelper.uncast(expr);
   // date col check
   if (optConf.shortcutFilters && expr instanceof NullValue) {
     // do nothing
     return new StringExpression("false");
   }
   if (optConf.shortcutFilters
       && (DataTypeHelper.constantValueExpressions.contains(expr.getClass()))) {
     // constant value detected is therefore bound
     return new StringExpression("true");
   } else {
     IsNullExpression isNullExpr = new IsNullExpression();
     isNullExpr.setLeftExpression(expr);
     isNullExpr.setNot(true);
     return isNullExpr;
   }
 }
Пример #3
0
 public void visit(IsNullExpression isNullExpression) throws Exception {
   isNullExpression.getLeftExpression().accept(this);
 }
    @Override
    public void visit(ExprFunction1 func) {
      if (func instanceof E_Bound) {
        TermMap boundCheck = tms.pop();
        tms.push(translateIsBound(boundCheck));

      } else if (func instanceof E_LogicalNot) {
        TermMap notCheck = tms.pop();
        Expression bool = DataTypeHelper.uncast(notCheck.getLiteralValBool());
        if (bool instanceof IsNullExpression) {
          ((IsNullExpression) bool).setNot(!((IsNullExpression) bool).isNot());

        } else {
          Parenthesis parenthesis = new Parenthesis(bool);
          parenthesis.setNot();

          notCheck = tmf.createBoolTermMap(parenthesis);
        }

        tms.push(notCheck);

      } else if (func instanceof E_Lang) {
        TermMap langFunc = tms.pop();
        Expression lang = DataTypeHelper.uncast(langFunc.getLiteralLang());
        TermMap langTermMap = tmf.createStringTermMap(lang);
        tms.push(langTermMap);

      } else if (func instanceof E_Str) {
        TermMap strParam = tms.pop();

        // create the coalesce function here

        List<Expression> strExpressions = new ArrayList<Expression>();

        strExpressions.add(
            dth.cast(
                DataTypeHelper.uncast(strParam.getLiteralValBinary()), dth.getStringCastType()));
        strExpressions.add(
            dth.cast(DataTypeHelper.uncast(strParam.getLiteralValBool()), dth.getStringCastType()));
        strExpressions.add(
            dth.cast(DataTypeHelper.uncast(strParam.getLiteralValDate()), dth.getStringCastType()));
        strExpressions.add(
            dth.cast(
                DataTypeHelper.uncast(strParam.getLiteralValNumeric()), dth.getStringCastType()));
        strExpressions.add(
            dth.cast(
                DataTypeHelper.uncast(strParam.getLiteralValString()), dth.getStringCastType()));

        strExpressions.add(FilterUtil.concat(strParam.getExpressions().toArray(new Expression[0])));

        Expression toString = FilterUtil.coalesce(strExpressions.toArray(new Expression[0]));

        tms.push(tmf.createStringTermMap(toString));
      } else if (func instanceof E_IsBlank) {
        TermMap isBlank = tms.pop();
        EqualsTo eq = new EqualsTo();
        eq.setLeftExpression(isBlank.getTermType());
        eq.setRightExpression(new StringValue("'" + ColumnHelper.COL_VAL_TYPE_BLANK + "'"));
        tms.push(tmf.createBoolTermMap(eq));
      } else if (func instanceof E_IsIRI) {
        TermMap isIri = tms.pop();
        EqualsTo eq = new EqualsTo();
        eq.setLeftExpression(isIri.getTermType());
        eq.setRightExpression(new StringValue("'" + ColumnHelper.COL_VAL_TYPE_RESOURCE + "'"));
        tms.push(tmf.createBoolTermMap(eq));
      } else if (func instanceof E_IsLiteral) {
        TermMap isLiteral = tms.pop();
        EqualsTo eq = new EqualsTo();
        eq.setLeftExpression(isLiteral.getTermType());
        eq.setRightExpression(new StringValue("'" + ColumnHelper.COL_VAL_TYPE_LITERAL + "'"));
        tms.push(tmf.createBoolTermMap(eq));
      } else {
        throw new ImplementationException("Implement Conversion for " + func.toString());
      }
    }