Exemple #1
0
  @Test
  public void testAnnotationFuncDependency() {
    QueryTree queryTree = new QueryTree();
    TableInfo tableInfo = new TableInfo();

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

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

    FuncDependencies funcDep = new FuncDependencies(queryTree, tableInfoSet);

    Set<String> annotation =
        new HashSet<String>(
            Arrays.asList(
                Utility.formatColumnName(
                    SAMPLED_TABLE_NAME, FuncDependencies.ANNOTATION_COLUMN_NAME)));
    Set<String> columns =
        new HashSet<String>(
            Arrays.asList(
                Utility.formatColumnName(SAMPLED_TABLE_NAME, "col1"),
                Utility.formatColumnName(SAMPLED_TABLE_NAME, KEY1),
                Utility.formatColumnName(SAMPLED_TABLE_NAME, KEY2)));

    FuncDep fd1 = new FuncDep(annotation, columns);
    FuncDep fd2 = new FuncDep(columns, annotation);

    Set<FuncDep> expected = new HashSet<FuncDep>();
    expected.add(fd1);
    expected.add(fd2);

    checkFunctionalDependencies(expected, funcDep.funcDeps);
  }
Exemple #2
0
  @Test
  public void testPrimaryKeyFuncDependency() {
    QueryTree queryTree = new QueryTree();
    TableInfo tableInfo = new TableInfo();

    tableInfo.setName(TABLE_NAME);
    tableInfo.setColumns(columnSet);
    tableInfo.setPrimaryKeys(new HashSet<String>(Arrays.asList(KEY1, KEY2)));

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

    FuncDependencies funcDep = new FuncDependencies(queryTree, tableInfoSet);

    Assert.assertEquals("Wrong number of funcDeps received", 1, funcDep.funcDeps.size());

    FuncDep fd1 =
        new FuncDep(
            new HashSet<String>(
                Arrays.asList(
                    Utility.formatColumnName(TABLE_NAME, KEY1),
                    Utility.formatColumnName(TABLE_NAME, KEY2))),
            new HashSet<String>(Arrays.asList(Utility.formatColumnName(TABLE_NAME, "col1"))));

    for (FuncDep result : funcDep.funcDeps) {
      Assert.assertEquals("Funcdep not found :(", fd1, result);
    }
  }
Exemple #3
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);
  }
Exemple #4
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);
  }
Exemple #5
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));
  }
Exemple #6
0
 public String toString() {
   return String.format(
       format,
       Utility.formatColumnName(LeftTable, LeftColumn),
       Utility.formatColumnName(RightTable, RightColumn));
 }