Skip to content

Commit

Permalink
fixup! fix primary key value null check
Browse files Browse the repository at this point in the history
  • Loading branch information
mfussenegger committed Feb 5, 2015
1 parent 17668bd commit 4d6ad8f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 2 additions & 3 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ Changes for Crate
Unreleased
==========

- Fixed a minor issue with the value validation of primary keys in INSERT
statements that could lead to some internal server errors instead of a
proper error message.
- Fix: Primary key columns could be set to NULL if the primary key column is
part of an object column and the object itself is null

- Added case-insensitive regex operator ~*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ private Object processPartitionedByValues(final ColumnIdent columnIdent, Object
int idx = context.tableInfo().partitionedBy().indexOf(columnIdent);
Map<String, String> partitionMap = context.currentPartitionMap();
if (idx < 0) {
if (columnValue == null) {
return null;
}
assert columnValue instanceof Map;
Map<String, Object> mapValue = (Map<String, Object>) columnValue;
// hmpf, one or more nested partitioned by columns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -793,5 +793,14 @@ public void testInsertIntoTableWithNestedObjectPrimaryKeyAndNullInsert() throws
expectedException.expectMessage("Primary key value must not be NULL");
analyze("insert into nested_pk (o) values (null)");
}

@Test
public void testInsertIntoTableWithNestedPartitionedByColumnAndNullValue() throws Exception {
// caused an AssertionError before... now there should be an entry with value null in the partition map
InsertFromValuesAnalyzedStatement statement = ((InsertFromValuesAnalyzedStatement) analyze(
"insert into nested_parted (obj) values (null)"));
assertThat(statement.partitionMaps().get(0).containsKey("obj.name"), is(true));
assertThat(statement.partitionMaps().get(0).get("obj.name"), nullValue());
}
}

0 comments on commit 4d6ad8f

Please sign in to comment.