Package de.fuberlin.wiwiss.d2rq.algebra

Examples of de.fuberlin.wiwiss.d2rq.algebra.Join


    this.out.println("\t.");
  }

  private void writeLinkTable(RelationName linkTableName) {
    List<Join> keys = schema.foreignKeys(linkTableName, DatabaseSchemaInspector.KEYS_IMPORTED);
    Join join1 = keys.get(0);
    Join join2 = keys.get(1);
    if (!filter.matches(join1.table1()) || !filter.matches(join1.table2()) ||
        !filter.matchesAll(join1.attributes1()) || !filter.matchesAll(join1.attributes2()) ||
        !filter.matches(join2.table1()) || !filter.matches(join2.table2()) ||
        !filter.matchesAll(join2.attributes1()) || !filter.matchesAll(join2.attributes2())) {
      log.info("Skipping link table " + linkTableName);
      return;
    }
    log.info("Generating d2rq:PropertyBridge instance for table " + linkTableName.qualifiedName());
    RelationName table1 = this.schema.getCorrectCapitalization(join1.table2());
    RelationName table2 = this.schema.getCorrectCapitalization(join2.table2());
    boolean isSelfJoin = table1.equals(table2);
    this.out.println("# Table " + linkTableName + (isSelfJoin ? " (n:m self-join)" : " (n:m)"));
    this.out.println(propertyBridgeIRITurtle(linkTableName, "link") + " a d2rq:PropertyBridge;");
    this.out.println("\td2rq:belongsToClassMap " + classMapIRITurtle(table1) + ";");
    this.out.println("\td2rq:property " + vocabularyIRITurtle(linkTableName) + ";");
    this.out.println("\td2rq:refersToClassMap " + classMapIRITurtle(table2) + ";");
    for (Attribute column: join1.attributes1()) {
      Attribute otherColumn = join1.equalAttribute(column);
      this.out.println("\td2rq:join \"" + column.qualifiedName() + " " + Join.joinOperators[join1.joinDirection()] + " " + otherColumn.qualifiedName() + "\";");
    }
    AliasMap alias = AliasMap.NO_ALIASES;
    if (isSelfJoin) {
      RelationName aliasName = new RelationName(
          null, table2.tableName() + "_" + linkTableName.tableName() + "__alias");
      alias = AliasMap.create1(table2, aliasName);
      this.out.println("\td2rq:alias \"" + table2.qualifiedName() +
          " AS " + aliasName.qualifiedName() + "\";");
    }
    for (Attribute column: join2.attributes1()) {
      Attribute otherColumn = join2.equalAttribute(column);
      this.out.println("\td2rq:join \"" + column.qualifiedName() + " " + Join.joinOperators[join2.joinDirection()] + " " + alias.applyTo(otherColumn).qualifiedName() + "\";");
    }
    this.out.println("\t.");
    this.out.println();
    createLinkProperty(linkTableName, table1, table2);
    this.out.flush();
View Full Code Here


    if (!exportedKeys.isEmpty()) return false;
   
    List<Attribute> columns = schema.listColumns(tableName);
    Iterator<Join> it = foreignKeys.iterator();
    while (it.hasNext()) {
      Join fk = it.next();
      if (fk.isSameTable()) return false;
      columns.removeAll(fk.attributes1());
    }
    return columns.isEmpty();
  }
View Full Code Here

    int joinOperator = Join.DIRECTION_UNDIRECTED;
    AttributeEqualityCondition previousCondition = null;
    for (AttributeEqualityCondition condition: parsedConditions) {
      if (previousCondition == null || !condition.sameRelations(previousCondition)) {
        if (previousCondition != null) {
          results.add(new Join(attributes1, attributes2, joinOperator));
        }
        attributes1 = new ArrayList<Attribute>();
        attributes2 = new ArrayList<Attribute>();
        joinOperator = condition.joinOperator();
      }
      attributes1.add(condition.firstAttribute());
      attributes2.add(condition.secondAttribute());
      previousCondition = condition;
    }
    if (previousCondition != null) {
      results.add(new Join(attributes1, attributes2, joinOperator));
    }
    return results;
  }
View Full Code Here

  public void testParseJoinTwoConditionsOnDifferentTables() {
    Set<Join> joins = SQL.parseJoins(Arrays.asList(new String[]{
        "foo.col1 <= bar.col1", "foo.col2 => baz.col1", "foo.col2 = bar.col1"}));
    assertEquals(3, joins.size());
    assertEquals(new HashSet<Join>(Arrays.asList(new Join[]{
        new Join(bar_col1, foo_col1, Join.DIRECTION_LEFT),
        new Join(baz_col1, foo_col2, Join.DIRECTION_RIGHT),
        new Join(foo_col2, bar_col1, Join.DIRECTION_UNDIRECTED)})),
        joins);
  }
View Full Code Here

    private void addColumns(int keySequence, Attribute foreign, Attribute primary) {
      primaryColumns.put(new Integer(keySequence), primary);
      foreignColumns.put(new Integer(keySequence), foreign);
    }
    private Join toJoin() {
      return new Join(
          new ArrayList<Attribute>(foreignColumns.values()),
          new ArrayList<Attribute>(primaryColumns.values()),
          Join.DIRECTION_RIGHT);
    }
View Full Code Here

  }
 
  public void testParseJoinOneCondition() {
    Set<Join> joins = SQL.parseJoins(Collections.singleton("foo.col1 = bar.col2"));
    assertEquals(1, joins.size());
    Join join = (Join) joins.iterator().next();
    assertEquals(Collections.singletonList(bar_col2), join.attributes1());
    assertEquals(Collections.singletonList(foo_col1), join.attributes2());
  }
View Full Code Here

 
  public void testParseJoinTwoConditionsOnSameTables() {
    Set<Join> joins = SQL.parseJoins(Arrays.asList(new String[]{
        "foo.col1 = bar.col1", "foo.col2 = bar.col2"}));
    assertEquals(1, joins.size());
    Join join = (Join) joins.iterator().next();
    assertEquals(Arrays.asList(new Attribute[]{bar_col1, bar_col2}),
        join.attributes1());
    assertEquals(Arrays.asList(new Attribute[]{foo_col1, foo_col2}),
        join.attributes2());
    assertEquals(foo_col1, join.equalAttribute(bar_col1));
  }
View Full Code Here

TOP

Related Classes of de.fuberlin.wiwiss.d2rq.algebra.Join

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.