Ejemplo n.º 1
0
  @Test
  public void testSelectFuncDependency() {
    QueryTree queryTree = new QueryTree();
    TableInfo tableInfo = new TableInfo();

    tableInfo.setName(TABLE_NAME);
    tableInfo.setColumns(columnSet);

    Set<TableInfo> tableInfoSet = new HashSet<TableInfo>();
    tableInfoSet.add(tableInfo);

    // Only equals condition will create functional dependency
    SelectCondition sc1 =
        new SelectCondition(TABLE_NAME, FOREIGN_KEY_COLUMN, FuncDependencies.EQUALS_OPERATION, "0");
    SelectCondition sc2 =
        new SelectCondition(TABLE_NAME, KEY1, FuncDependencies.EQUALS_OPERATION + "<", "0");
    queryTree.getSelectConditions().add(sc1);
    queryTree.getSelectConditions().add(sc2);

    FuncDependencies funcDep = new FuncDependencies(queryTree, tableInfoSet);

    Set<String> det = new HashSet<String>();
    Set<String> dep =
        new HashSet<String>(
            Arrays.asList(Utility.formatColumnName(TABLE_NAME, FOREIGN_KEY_COLUMN)));

    Set<FuncDep> expected = new HashSet<FuncDep>();
    expected.add(new FuncDep(det, dep));

    checkFunctionalDependencies(expected, funcDep.funcDeps);
  }
Ejemplo n.º 2
0
  @Test
  public void testJoinFuncDependency() {
    QueryTree queryTree = new QueryTree();
    TableInfo tableInfo = new TableInfo();

    tableInfo.setName(TABLE_NAME);
    tableInfo.setColumns(columnSet);

    Set<TableInfo> tableInfoSet = new HashSet<TableInfo>();
    tableInfoSet.add(tableInfo);

    JoinCondition jc1 =
        new JoinCondition(
            TABLE_NAME, FOREIGN_KEY_COLUMN, FOREIGN_TABLE_NAME, FOREIGN_TABLE_KEY_COLUMN);
    queryTree.getJoinConditions().add(jc1);

    FuncDependencies funcDep = new FuncDependencies(queryTree, tableInfoSet);

    Set<String> det =
        new HashSet<String>(
            Arrays.asList(Utility.formatColumnName(TABLE_NAME, FOREIGN_KEY_COLUMN)));
    Set<String> dep =
        new HashSet<String>(
            Arrays.asList(Utility.formatColumnName(FOREIGN_TABLE_NAME, FOREIGN_TABLE_KEY_COLUMN)));

    Set<FuncDep> expected = new HashSet<FuncDep>();
    expected.add(new FuncDep(det, dep));
    expected.add(new FuncDep(dep, det));

    checkFunctionalDependencies(expected, funcDep.funcDeps);
  }
Ejemplo n.º 3
0
  @Test
  public void testInference() {
    QueryTree queryTree = new QueryTree();

    JoinCondition jc1 =
        new JoinCondition(
            SAMPLED_TABLE_NAME, FOREIGN_KEY_COLUMN, FOREIGN_TABLE_NAME, FOREIGN_TABLE_KEY_COLUMN);
    queryTree.getJoinConditions().add(jc1);

    TableInfo sampledTableInfo = new TableInfo();

    sampledTableInfo.setName(SAMPLED_TABLE_NAME);
    sampledTableInfo.setColumns(columnSet);

    TableInfo foreignTableInfo = new TableInfo();
    foreignTableInfo.setName(FOREIGN_TABLE_NAME);
    foreignTableInfo.setColumns(foreignColumnSet);
    foreignTableInfo.setPrimaryKeys(new HashSet<>(Arrays.asList(FOREIGN_TABLE_KEY_COLUMN)));

    Set<TableInfo> tableInfoSet = new HashSet<TableInfo>();
    tableInfoSet.add(sampledTableInfo);
    tableInfoSet.add(foreignTableInfo);

    FuncDependencies funcDep = new FuncDependencies(queryTree, tableInfoSet);

    Set<String> det =
        new HashSet<String>(
            Arrays.asList(
                Utility.formatColumnName(SAMPLED_TABLE_NAME, KEY1),
                Utility.formatColumnName(
                    SAMPLED_TABLE_NAME, FuncDependencies.ANNOTATION_COLUMN_NAME)));
    Set<String> dep = new HashSet<>();

    columnSet.forEach(
        (columnName) -> dep.add(Utility.formatColumnName(SAMPLED_TABLE_NAME, columnName)));
    foreignColumnSet.forEach(
        (columnName) -> dep.add(Utility.formatColumnName(FOREIGN_TABLE_NAME, columnName)));

    /*Infer that P.KEY1, P.pi ----> HEAD(P) and HEAD(Q)*/
    Assert.assertTrue("Inferrence failed", funcDep.infer(det, dep));
  }