Skip to content

Commit

Permalink
Test access operations for CREATE OR REPLACE TABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
findinpath authored and ebyhr committed Oct 27, 2023
1 parent c2807e7 commit 8df5a63
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,26 @@ public void testCreateTable()
.build());
}

@Test
public void testCreateOrReplaceTable()
{
assertFileSystemAccesses("CREATE OR REPLACE TABLE test_create_or_replace (id VARCHAR, age INT)",
ImmutableMultiset.<FileOperation>builder()
.add(new FileOperation(METADATA_JSON, OUTPUT_FILE_CREATE))
.add(new FileOperation(SNAPSHOT, INPUT_FILE_GET_LENGTH))
.add(new FileOperation(SNAPSHOT, INPUT_FILE_NEW_STREAM))
.add(new FileOperation(SNAPSHOT, OUTPUT_FILE_CREATE_OR_OVERWRITE))
.build());
assertFileSystemAccesses("CREATE OR REPLACE TABLE test_create_or_replace (id VARCHAR, age INT)",
ImmutableMultiset.<FileOperation>builder()
.add(new FileOperation(METADATA_JSON, OUTPUT_FILE_CREATE))
.add(new FileOperation(METADATA_JSON, INPUT_FILE_NEW_STREAM))
.add(new FileOperation(SNAPSHOT, INPUT_FILE_GET_LENGTH))
.add(new FileOperation(SNAPSHOT, INPUT_FILE_NEW_STREAM))
.add(new FileOperation(SNAPSHOT, OUTPUT_FILE_CREATE_OR_OVERWRITE))
.build());
}

@Test
public void testCreateTableAsSelect()
{
Expand Down Expand Up @@ -157,6 +177,35 @@ public void testCreateTableAsSelect()
.build());
}

@Test
public void testCreateOrReplaceTableAsSelect()
{
assertFileSystemAccesses(
"CREATE OR REPLACE TABLE test_create_or_replace_as_select AS SELECT 1 col_name",
ImmutableMultiset.<FileOperation>builder()
.addCopies(new FileOperation(METADATA_JSON, OUTPUT_FILE_CREATE), 2)
.add(new FileOperation(METADATA_JSON, INPUT_FILE_NEW_STREAM))
.add(new FileOperation(SNAPSHOT, INPUT_FILE_GET_LENGTH))
.add(new FileOperation(SNAPSHOT, INPUT_FILE_NEW_STREAM))
.add(new FileOperation(SNAPSHOT, OUTPUT_FILE_CREATE_OR_OVERWRITE))
.add(new FileOperation(MANIFEST, OUTPUT_FILE_CREATE_OR_OVERWRITE))
.add(new FileOperation(STATS, OUTPUT_FILE_CREATE))
.build());

assertFileSystemAccesses(
"CREATE OR REPLACE TABLE test_create_or_replace_as_select AS SELECT 1 col_name",
ImmutableMultiset.<FileOperation>builder()
.addCopies(new FileOperation(METADATA_JSON, OUTPUT_FILE_CREATE), 2)
.addCopies(new FileOperation(METADATA_JSON, INPUT_FILE_NEW_STREAM), 2)
.addCopies(new FileOperation(SNAPSHOT, INPUT_FILE_NEW_STREAM), 2)
.addCopies(new FileOperation(SNAPSHOT, INPUT_FILE_GET_LENGTH), 2)
.add(new FileOperation(SNAPSHOT, OUTPUT_FILE_CREATE_OR_OVERWRITE))
.add(new FileOperation(MANIFEST, OUTPUT_FILE_CREATE_OR_OVERWRITE))
.add(new FileOperation(MANIFEST, INPUT_FILE_NEW_STREAM))
.add(new FileOperation(STATS, OUTPUT_FILE_CREATE))
.build());
}

@Test
public void testSelect()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,23 @@ public void testCreateTable()
.build());
}

@Test
public void testCreateOrReplaceTable()
{
assertMetastoreInvocations("CREATE OR REPLACE TABLE test_create_or_replace (id VARCHAR, age INT)",
ImmutableMultiset.builder()
.add(CREATE_TABLE)
.add(GET_DATABASE)
.add(GET_TABLE)
.build());
assertMetastoreInvocations("CREATE OR REPLACE TABLE test_create_or_replace (id VARCHAR, age INT)",
ImmutableMultiset.builder()
.add(GET_DATABASE)
.add(REPLACE_TABLE)
.add(GET_TABLE)
.build());
}

@Test
public void testCreateTableAsSelect()
{
Expand All @@ -131,6 +148,27 @@ public void testCreateTableAsSelect()
.build());
}

@Test
public void testCreateOrReplaceTableAsSelect()
{
assertMetastoreInvocations(
"CREATE OR REPLACE TABLE test_cortas AS SELECT 1 AS age",
ImmutableMultiset.builder()
.add(GET_DATABASE)
.add(CREATE_TABLE)
.addCopies(GET_TABLE, 4)
.add(REPLACE_TABLE)
.build());

assertMetastoreInvocations(
"CREATE OR REPLACE TABLE test_cortas AS SELECT 1 AS age",
ImmutableMultiset.builder()
.add(GET_DATABASE)
.addCopies(GET_TABLE, 3)
.addCopies(REPLACE_TABLE, 2)
.build());
}

@Test
public void testSelect()
{
Expand Down

0 comments on commit 8df5a63

Please sign in to comment.