Skip to content

Commit

Permalink
Support unpartitioned tables in Kudu
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjian2664 committed Jan 10, 2025
1 parent bdd4503 commit 2c165e3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ else if (!hashColumns2.isEmpty()) {

@SuppressWarnings("unchecked")
List<String> rangeColumns = (List<String>) tableProperties.get(PARTITION_BY_RANGE_COLUMNS);
if (!rangeColumns.isEmpty()) {
// un-partitioned table
if (!rangeColumns.isEmpty() || !design.hasPartitions()) {
design.setRange(new RangePartitionDefinition(rangeColumns));
}

Expand Down Expand Up @@ -228,6 +229,12 @@ public static Map<String, Object> toMap(KuduTable table)
properties.put(PARTITION_BY_RANGE_COLUMNS, partitionDesign.getRange().columns());
}

// un-partitioned table
if (!partitionDesign.hasPartitions()) {
properties.put(PARTITION_BY_HASH_COLUMNS, ImmutableList.of());
properties.put(PARTITION_BY_RANGE_COLUMNS, ImmutableList.of());
}

String partitionRangesValue = mapper.writeValueAsString(rangePartitionList);
properties.put(RANGE_PARTITIONS, partitionRangesValue);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,29 @@ public static String createKuduTableForWrites(String createTable)
format("WITH (partition_by_hash_columns = ARRAY['%s'], partition_by_hash_buckets = 2)", column);
}

@Test
public void testUnPartitionedTable()
{
String tableName = "test_unpartitioned_table" + randomNameSuffix();
// success create the table without partition keys
assertUpdate("CREATE TABLE " + tableName + " (id int WITH (primary_key=true), val varchar)");

assertQuery("SELECT COUNT(*) FROM " + tableName, "VALUES 0");
assertUpdate("INSERT INTO " + tableName + " VALUES (1, 'hello'), (2, 'world')", 2);
assertQuery("SELECT COUNT(*) FROM " + tableName, "VALUES 2");

assertUpdate("DELETE FROM " + tableName + " WHERE id = 1", 1);
assertQuery("SELECT * FROM " + tableName, "VALUES (2, 'world')");

String sqlStatement = (String) computeScalar("SHOW CREATE TABLE " + tableName);
String tableProperties = sqlStatement.split("\\)\\s*WITH\\s*\\(")[1];
// empty partition keys
assertTableProperty(tableProperties, "partition_by_hash_columns", Pattern.quote("ARRAY[]"));
assertTableProperty(tableProperties, "partition_by_range_columns", Pattern.quote("ARRAY[]"));

assertUpdate("DROP TABLE " + tableName);
}

@Test
@Override
public void testCreateSchema()
Expand Down

0 comments on commit 2c165e3

Please sign in to comment.