Esempio n. 1
0
  private void convertFunction(ExprFunction1 expr) {
    logger.debug("convertFunction " + expr.toString());

    if (expr instanceof E_Str) {
      convertStr((E_Str) expr);
    } else if (expr instanceof E_IsIRI) {
      convertIsIRI((E_IsIRI) expr);
    } else if (expr instanceof E_IsBlank) {
      convertIsBlank((E_IsBlank) expr);
    } else if (expr instanceof E_IsLiteral) {
      convertIsLiteral((E_IsLiteral) expr);
    } else if (expr instanceof E_Datatype) {
      convertDataType((E_Datatype) expr);
    } else if (expr instanceof E_Lang) {
      convertLang((E_Lang) expr);
    } else if (expr instanceof E_LogicalNot) {
      convertLogicalNot((E_LogicalNot) expr);
    } else if (expr instanceof E_UnaryPlus) {
      convert((E_UnaryPlus) expr);
    } else if (expr instanceof E_UnaryMinus) {
      convert((E_UnaryMinus) expr);
    } else if (extensionSupports(expr)) {
      expr.getArg(1).visit(this);
      Expression e1 = expression.pop();
      List<Expression> args = Collections.singletonList(e1);
      extensionConvert(expr, args);
    } else {
      conversionFailed(expr);
    }
  }
    @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());
      }
    }