Skip to content

Commit

Permalink
fixed bug in altering partitioned tables
Browse files Browse the repository at this point in the history
The issue was caused by using ObjectMapper for Array column types.

The following sequence of SQL statements would result in an exception:

> create table foo (id int, tag array(string)) partitioned by(id)
> insert into foo (id) values (1)
> alter table foo add column name string
  • Loading branch information
kovrus committed May 20, 2016
1 parent 25df61c commit 6d01cb8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changes for Crate
Unreleased
==========

- Fixed an issue that prevented altering a partitioned table by adding a new
column if the table already contains an array column.

2016/05/12 0.54.9
=================

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@ private void parseNull(ParseContext context) throws IOException {

@Override
public void merge(Mapper mergeWith, MergeContext mergeContext) throws MergeMappingException {
innerMapper.merge(mergeWith, mergeContext);
if (mergeWith instanceof ArrayMapper) {
innerMapper.merge(((ArrayMapper) mergeWith).innerMapper, mergeContext);
} else {
innerMapper.merge(mergeWith, mergeContext);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,24 @@ public void testPartitionedTableNestedAllConstraintsRoundTrip() throws Exception
assertEquals(1L, response.rowCount());
}

@Test
public void testAlterPartitionedTableWithArrayInRootFields() {
execute("create table foo (a integer, b ARRAY(OBJECT)) partitioned by(a)");
ensureYellow();
execute("insert into foo (a) values (?)", new Object[]{1});
execute("refresh table foo");
ensureGreen();

execute("alter table foo add column c string");

execute("select column_name " +
"from information_schema.columns " +
"where schema_name = 'doc' and table_name = 'foo' " +
"order by column_name asc");

assertThat(TestingHelpers.printedTable(response.rows()), is("a\nb\nc\n"));
}

@Test
public void testAlterPartitionTable() throws Exception {
execute("create table quotes (id integer, quote string, date timestamp) " +
Expand Down

0 comments on commit 6d01cb8

Please sign in to comment.