Пример #1
0
  private void verifyViewCreation() {
    // replace works for new view
    doCreateView(temporaryCreateView, true);

    // replace works for existing view
    doCreateView(temporaryCreateView, true);

    // create fails for existing view
    try {
      doCreateView(temporaryCreateView, false);
      fail("create existing should fail");
    } catch (ViewAlreadyExistsException e) {
      assertEquals(e.getViewName(), temporaryCreateView);
    }

    // drop works when view exists
    metadata.dropView(SESSION, temporaryCreateView);
    assertEquals(metadata.getViews(SESSION, temporaryCreateView.toSchemaTablePrefix()).size(), 0);
    assertFalse(
        metadata
            .listViews(SESSION, temporaryCreateView.getSchemaName())
            .contains(temporaryCreateView));

    // drop fails when view does not exist
    try {
      metadata.dropView(SESSION, temporaryCreateView);
      fail("drop non-existing should fail");
    } catch (ViewNotFoundException e) {
      assertEquals(e.getViewName(), temporaryCreateView);
    }

    // create works for new view
    doCreateView(temporaryCreateView, false);
  }
Пример #2
0
  private void doCreateView(SchemaTableName viewName, boolean replace) {
    String viewData = "test data";

    metadata.createView(SESSION, viewName, viewData, replace);

    Map<SchemaTableName, String> views = metadata.getViews(SESSION, viewName.toSchemaTablePrefix());
    assertEquals(views.size(), 1);
    assertEquals(views.get(viewName), viewData);

    assertTrue(metadata.listViews(SESSION, viewName.getSchemaName()).contains(viewName));
  }
Пример #3
0
 @Test
 public void testListUnknownSchema() {
   assertNull(
       metadata.getTableHandle(SESSION, new SchemaTableName(INVALID_DATABASE, INVALID_TABLE)));
   assertEquals(metadata.listTables(SESSION, INVALID_DATABASE), ImmutableList.of());
   assertEquals(
       metadata.listTableColumns(SESSION, new SchemaTablePrefix(INVALID_DATABASE, INVALID_TABLE)),
       ImmutableMap.of());
   assertEquals(metadata.listViews(SESSION, INVALID_DATABASE), ImmutableList.of());
   assertEquals(
       metadata.getViews(SESSION, new SchemaTablePrefix(INVALID_DATABASE, INVALID_TABLE)),
       ImmutableMap.of());
 }