Skip to content

Commit

Permalink
add tests for singular partition transform functions
Browse files Browse the repository at this point in the history
  • Loading branch information
clettieri committed Aug 1, 2023
1 parent 78fe3f1 commit ed0dcbb
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,82 @@ public void testAddHoursPartition() {
Assert.assertEquals("Should have new spec field", expected, table.spec());
}

@Test
public void testAddYearPartition() {
sql(
"CREATE TABLE %s (id bigint NOT NULL, category string, ts timestamp, data string) USING iceberg",
tableName);
Table table = validationCatalog.loadTable(tableIdent);

Assert.assertTrue("Table should start unpartitioned", table.spec().isUnpartitioned());

sql("ALTER TABLE %s ADD PARTITION FIELD year(ts)", tableName);

table.refresh();

PartitionSpec expected =
PartitionSpec.builderFor(table.schema()).withSpecId(1).year("ts").build();

Assert.assertEquals("Should have new spec field", expected, table.spec());
}

@Test
public void testAddMonthPartition() {
sql(
"CREATE TABLE %s (id bigint NOT NULL, category string, ts timestamp, data string) USING iceberg",
tableName);
Table table = validationCatalog.loadTable(tableIdent);

Assert.assertTrue("Table should start unpartitioned", table.spec().isUnpartitioned());

sql("ALTER TABLE %s ADD PARTITION FIELD month(ts)", tableName);

table.refresh();

PartitionSpec expected =
PartitionSpec.builderFor(table.schema()).withSpecId(1).month("ts").build();

Assert.assertEquals("Should have new spec field", expected, table.spec());
}

@Test
public void testAddDayPartition() {
sql(
"CREATE TABLE %s (id bigint NOT NULL, category string, ts timestamp, data string) USING iceberg",
tableName);
Table table = validationCatalog.loadTable(tableIdent);

Assert.assertTrue("Table should start unpartitioned", table.spec().isUnpartitioned());

sql("ALTER TABLE %s ADD PARTITION FIELD day(ts)", tableName);

table.refresh();

PartitionSpec expected =
PartitionSpec.builderFor(table.schema()).withSpecId(1).day("ts").build();

Assert.assertEquals("Should have new spec field", expected, table.spec());
}

@Test
public void testAddHourPartition() {
sql(
"CREATE TABLE %s (id bigint NOT NULL, category string, ts timestamp, data string) USING iceberg",
tableName);
Table table = validationCatalog.loadTable(tableIdent);

Assert.assertTrue("Table should start unpartitioned", table.spec().isUnpartitioned());

sql("ALTER TABLE %s ADD PARTITION FIELD hour(ts)", tableName);

table.refresh();

PartitionSpec expected =
PartitionSpec.builderFor(table.schema()).withSpecId(1).hour("ts").build();

Assert.assertEquals("Should have new spec field", expected, table.spec());
}

@Test
public void testAddNamedPartition() {
sql(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,82 @@ public void testAddHoursPartition() {
Assert.assertEquals("Should have new spec field", expected, table.spec());
}

@Test
public void testAddYearPartition() {
sql(
"CREATE TABLE %s (id bigint NOT NULL, category string, ts timestamp, data string) USING iceberg",
tableName);
Table table = validationCatalog.loadTable(tableIdent);

Assert.assertTrue("Table should start unpartitioned", table.spec().isUnpartitioned());

sql("ALTER TABLE %s ADD PARTITION FIELD year(ts)", tableName);

table.refresh();

PartitionSpec expected =
PartitionSpec.builderFor(table.schema()).withSpecId(1).year("ts").build();

Assert.assertEquals("Should have new spec field", expected, table.spec());
}

@Test
public void testAddMonthPartition() {
sql(
"CREATE TABLE %s (id bigint NOT NULL, category string, ts timestamp, data string) USING iceberg",
tableName);
Table table = validationCatalog.loadTable(tableIdent);

Assert.assertTrue("Table should start unpartitioned", table.spec().isUnpartitioned());

sql("ALTER TABLE %s ADD PARTITION FIELD month(ts)", tableName);

table.refresh();

PartitionSpec expected =
PartitionSpec.builderFor(table.schema()).withSpecId(1).month("ts").build();

Assert.assertEquals("Should have new spec field", expected, table.spec());
}

@Test
public void testAddDayPartition() {
sql(
"CREATE TABLE %s (id bigint NOT NULL, category string, ts timestamp, data string) USING iceberg",
tableName);
Table table = validationCatalog.loadTable(tableIdent);

Assert.assertTrue("Table should start unpartitioned", table.spec().isUnpartitioned());

sql("ALTER TABLE %s ADD PARTITION FIELD day(ts)", tableName);

table.refresh();

PartitionSpec expected =
PartitionSpec.builderFor(table.schema()).withSpecId(1).day("ts").build();

Assert.assertEquals("Should have new spec field", expected, table.spec());
}

@Test
public void testAddHourPartition() {
sql(
"CREATE TABLE %s (id bigint NOT NULL, category string, ts timestamp, data string) USING iceberg",
tableName);
Table table = validationCatalog.loadTable(tableIdent);

Assert.assertTrue("Table should start unpartitioned", table.spec().isUnpartitioned());

sql("ALTER TABLE %s ADD PARTITION FIELD hour(ts)", tableName);

table.refresh();

PartitionSpec expected =
PartitionSpec.builderFor(table.schema()).withSpecId(1).hour("ts").build();

Assert.assertEquals("Should have new spec field", expected, table.spec());
}

@Test
public void testAddNamedPartition() {
sql(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,82 @@ public void testAddHoursPartition() {
Assert.assertEquals("Should have new spec field", expected, table.spec());
}

@Test
public void testAddYearPartition() {
sql(
"CREATE TABLE %s (id bigint NOT NULL, category string, ts timestamp, data string) USING iceberg",
tableName);
Table table = validationCatalog.loadTable(tableIdent);

Assert.assertTrue("Table should start unpartitioned", table.spec().isUnpartitioned());

sql("ALTER TABLE %s ADD PARTITION FIELD year(ts)", tableName);

table.refresh();

PartitionSpec expected =
PartitionSpec.builderFor(table.schema()).withSpecId(1).year("ts").build();

Assert.assertEquals("Should have new spec field", expected, table.spec());
}

@Test
public void testAddMonthPartition() {
sql(
"CREATE TABLE %s (id bigint NOT NULL, category string, ts timestamp, data string) USING iceberg",
tableName);
Table table = validationCatalog.loadTable(tableIdent);

Assert.assertTrue("Table should start unpartitioned", table.spec().isUnpartitioned());

sql("ALTER TABLE %s ADD PARTITION FIELD month(ts)", tableName);

table.refresh();

PartitionSpec expected =
PartitionSpec.builderFor(table.schema()).withSpecId(1).month("ts").build();

Assert.assertEquals("Should have new spec field", expected, table.spec());
}

@Test
public void testAddDayPartition() {
sql(
"CREATE TABLE %s (id bigint NOT NULL, category string, ts timestamp, data string) USING iceberg",
tableName);
Table table = validationCatalog.loadTable(tableIdent);

Assert.assertTrue("Table should start unpartitioned", table.spec().isUnpartitioned());

sql("ALTER TABLE %s ADD PARTITION FIELD day(ts)", tableName);

table.refresh();

PartitionSpec expected =
PartitionSpec.builderFor(table.schema()).withSpecId(1).day("ts").build();

Assert.assertEquals("Should have new spec field", expected, table.spec());
}

@Test
public void testAddHourPartition() {
sql(
"CREATE TABLE %s (id bigint NOT NULL, category string, ts timestamp, data string) USING iceberg",
tableName);
Table table = validationCatalog.loadTable(tableIdent);

Assert.assertTrue("Table should start unpartitioned", table.spec().isUnpartitioned());

sql("ALTER TABLE %s ADD PARTITION FIELD hour(ts)", tableName);

table.refresh();

PartitionSpec expected =
PartitionSpec.builderFor(table.schema()).withSpecId(1).hour("ts").build();

Assert.assertEquals("Should have new spec field", expected, table.spec());
}

@Test
public void testAddNamedPartition() {
sql(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,82 @@ public void testAddHoursPartition() {
Assert.assertEquals("Should have new spec field", expected, table.spec());
}

@Test
public void testAddYearPartition() {
sql(
"CREATE TABLE %s (id bigint NOT NULL, category string, ts timestamp, data string) USING iceberg",
tableName);
Table table = validationCatalog.loadTable(tableIdent);

Assert.assertTrue("Table should start unpartitioned", table.spec().isUnpartitioned());

sql("ALTER TABLE %s ADD PARTITION FIELD year(ts)", tableName);

table.refresh();

PartitionSpec expected =
PartitionSpec.builderFor(table.schema()).withSpecId(1).year("ts").build();

Assert.assertEquals("Should have new spec field", expected, table.spec());
}

@Test
public void testAddMonthPartition() {
sql(
"CREATE TABLE %s (id bigint NOT NULL, category string, ts timestamp, data string) USING iceberg",
tableName);
Table table = validationCatalog.loadTable(tableIdent);

Assert.assertTrue("Table should start unpartitioned", table.spec().isUnpartitioned());

sql("ALTER TABLE %s ADD PARTITION FIELD month(ts)", tableName);

table.refresh();

PartitionSpec expected =
PartitionSpec.builderFor(table.schema()).withSpecId(1).month("ts").build();

Assert.assertEquals("Should have new spec field", expected, table.spec());
}

@Test
public void testAddDayPartition() {
sql(
"CREATE TABLE %s (id bigint NOT NULL, category string, ts timestamp, data string) USING iceberg",
tableName);
Table table = validationCatalog.loadTable(tableIdent);

Assert.assertTrue("Table should start unpartitioned", table.spec().isUnpartitioned());

sql("ALTER TABLE %s ADD PARTITION FIELD day(ts)", tableName);

table.refresh();

PartitionSpec expected =
PartitionSpec.builderFor(table.schema()).withSpecId(1).day("ts").build();

Assert.assertEquals("Should have new spec field", expected, table.spec());
}

@Test
public void testAddHourPartition() {
sql(
"CREATE TABLE %s (id bigint NOT NULL, category string, ts timestamp, data string) USING iceberg",
tableName);
Table table = validationCatalog.loadTable(tableIdent);

Assert.assertTrue("Table should start unpartitioned", table.spec().isUnpartitioned());

sql("ALTER TABLE %s ADD PARTITION FIELD hour(ts)", tableName);

table.refresh();

PartitionSpec expected =
PartitionSpec.builderFor(table.schema()).withSpecId(1).hour("ts").build();

Assert.assertEquals("Should have new spec field", expected, table.spec());
}

@Test
public void testAddNamedPartition() {
sql(
Expand Down

0 comments on commit ed0dcbb

Please sign in to comment.