public static SqlOpQuery makeSelectOrTable(SqlOpQuery node) {
    String alias = aliasGenerator.next();

    SqlOpQuery result = new SqlOpQuery(node.getSchema(), node.getQueryString(), alias);

    return result;
  }
예제 #2
0
  /**
   * Builds up the one triple that states where the actual data for the target mapping comes from.
   * Such a source can be simply a database table or an SQL query.
   *
   * @param r2rml the target com.hp.hpl.jena.rdf.model.Model
   * @param relation the data source (table name or SQL query)
   * @return the whole Statement stating where the data comes from, e.g. '[] rr:tableName "EMP"'
   */
  private Statement buildLogicalTableTriple(Model r2rml, SqlOpBase relation) {
    // subject (a blank node [])
    Resource logicalTableSubject = ResourceFactory.createResource();
    // predicate (rr:tableName or rr:sqlQuery)
    Property logicalTablePredicate;
    // object (a Literal like "SELECT DEPTNO FROM DEPT WHERE DEPTNO > 23" or
    // simply a table name like "DEPTNO"
    Literal logicalTableObject;

    // it's a table
    if (relation instanceof SqlOpTable) {
      SqlOpTable tbl = (SqlOpTable) relation;
      logicalTablePredicate = ResourceFactory.createProperty(rrNamespace, "tableName");
      logicalTableObject = ResourceFactory.createPlainLiteral(tbl.getTableName());

      // it's a query
    } else if (relation instanceof SqlOpQuery) {
      SqlOpQuery query = (SqlOpQuery) relation;
      logicalTablePredicate = ResourceFactory.createProperty(rrNamespace, "sqlQuery");
      logicalTableObject = ResourceFactory.createPlainLiteral(query.getQueryString());

      // it's not possible
    } else {
      // should never be called since a relation can either be a table
      // or a query
      logicalTablePredicate = ResourceFactory.createProperty("");
      logicalTableObject = ResourceFactory.createPlainLiteral("");
    }

    Statement logicalTblStatement =
        r2rml.createStatement(logicalTableSubject, logicalTablePredicate, logicalTableObject);

    return logicalTblStatement;
  }
  public static SqlOpSelectBlock makeSelect(SqlOpQuery node) {

    SqlOpQuery opQuery = makeSelectOrTable(node);

    SqlOpSelectBlock result = SqlOpSelectBlock.create(opQuery);

    for (String columnName : opQuery.getSchema().getColumnNames()) {
      result
          .getProjection()
          .put(columnName, new ExprVar(opQuery.getAliasName() + "." + columnName));
    }

    return result;
  }