Exemple #1
0
  @Test
  public final void testCtasWithoutTableDefinition() throws Exception {
    ResultSet res = executeQuery();
    res.close();

    String tableName = CatalogUtil.normalizeIdentifier("testCtasWithoutTableDefinition");
    CatalogService catalog = testBase.getTestingCluster().getMaster().getCatalog();
    String qualifiedTableName = buildFQName(DEFAULT_DATABASE_NAME, tableName);
    TableDesc desc = catalog.getTableDesc(qualifiedTableName);
    assertTrue(catalog.existsTable(qualifiedTableName));

    assertTrue(desc.getSchema().contains("default.testctaswithouttabledefinition.col1"));
    PartitionMethodDesc partitionDesc = desc.getPartitionMethod();
    assertEquals(partitionDesc.getPartitionType(), CatalogProtos.PartitionType.COLUMN);
    assertEquals(
        "key", partitionDesc.getExpressionSchema().getRootColumns().get(0).getSimpleName());

    FileSystem fs = FileSystem.get(testBase.getTestingCluster().getConfiguration());
    Path path = new Path(desc.getUri());
    assertTrue(fs.isDirectory(path));
    assertTrue(fs.isDirectory(new Path(path.toUri() + "/key=17.0")));
    assertTrue(fs.isDirectory(new Path(path.toUri() + "/key=36.0")));
    assertTrue(fs.isDirectory(new Path(path.toUri() + "/key=38.0")));
    assertTrue(fs.isDirectory(new Path(path.toUri() + "/key=45.0")));
    assertTrue(fs.isDirectory(new Path(path.toUri() + "/key=49.0")));
    if (!testingCluster.isHiveCatalogStoreRunning()) {
      assertEquals(5, desc.getStats().getNumRows().intValue());
    }

    ResultSet res2 = executeFile("check1.sql");

    Map<Double, int[]> resultRows1 = Maps.newHashMap();
    resultRows1.put(45.0d, new int[] {3, 2});
    resultRows1.put(38.0d, new int[] {2, 2});

    int i = 0;
    while (res2.next()) {
      assertEquals(resultRows1.get(res2.getDouble(3))[0], res2.getInt(1));
      assertEquals(resultRows1.get(res2.getDouble(3))[1], res2.getInt(2));
      i++;
    }
    res2.close();
    assertEquals(2, i);
  }
 public Object clone() throws CloneNotSupportedException {
   TableDesc desc = (TableDesc) super.clone();
   desc.builder = TableDescProto.newBuilder();
   desc.tableName = tableName;
   desc.schema = (Schema) schema.clone();
   desc.meta = (TableMeta) meta.clone();
   desc.uri = uri;
   desc.stats = stats != null ? (TableStats) stats.clone() : null;
   desc.partitionMethodDesc =
       partitionMethodDesc != null ? (PartitionMethodDesc) partitionMethodDesc.clone() : null;
   return desc;
 }
Exemple #3
0
  private boolean isClonedTable(String orignalTable, String newTable) throws Exception {
    assertTableExists(newTable);
    TableDesc origTableDesc = client.getTableDesc(orignalTable);
    TableDesc newTableDesc = client.getTableDesc(newTable);

    if (isClonedSchema(origTableDesc.getSchema(), newTableDesc.getSchema()) == false) {
      fail("Schema of input tables do not match");
      return false;
    }

    // Check partition information
    PartitionMethodDesc origPartMethod = origTableDesc.getPartitionMethod();
    PartitionMethodDesc newPartMethod = newTableDesc.getPartitionMethod();
    if (origPartMethod != null) {
      if (newPartMethod == null) {
        fail("New table does not have partition info");
        return false;
      }
      if (isClonedSchema(origPartMethod.getExpressionSchema(), newPartMethod.getExpressionSchema())
          == false) {
        fail("Partition columns of input tables do not match");
        return false;
      }

      if (origPartMethod.getPartitionType().equals(newPartMethod.getPartitionType()) == false) {
        fail("Partition type of input tables do not match");
        return false;
      }
    }

    // Check external flag
    if (origTableDesc.isExternal() != newTableDesc.isExternal()) {
      fail("External table flag on input tables not equal");
      return false;
    }

    if (origTableDesc.getMeta() != null) {
      TableMeta origMeta = origTableDesc.getMeta();
      TableMeta newMeta = newTableDesc.getMeta();
      if (origMeta.getDataFormat().equals(newMeta.getDataFormat()) == false) {
        fail("Store type of input tables not equal");
        return false;
      }

      KeyValueSet origOptions = origMeta.getPropertySet();
      KeyValueSet newOptions = newMeta.getPropertySet();
      if (origOptions.equals(newOptions) == false) {
        fail("Meta options of input tables not equal");
        return false;
      }
    }
    return true;
  }