Skip to content

Commit

Permalink
Fix: raise an error if an array is inserted into an objects
Browse files Browse the repository at this point in the history
field which is not of type array
  • Loading branch information
Philipp Bogensberger committed Oct 27, 2014
1 parent 68aca73 commit 3bbc7fe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
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 Data
Unreleased
==========

- Fix: raise an error if an array is inserted into an objects
field which is not of type array

- Throw an error while using unknown root columns on SELECT

2014/10/21 0.44.8
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/io/crate/types/StringType.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.elasticsearch.common.io.stream.StreamOutput;

import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Locale;
import java.util.Map;

Expand Down Expand Up @@ -71,7 +70,7 @@ public BytesRef value(Object value) {
return new BytesRef("f");
}
}
if (value instanceof Map || value instanceof Array) {
if (value instanceof Map || value.getClass().isArray()) {
throw new IllegalArgumentException(
String.format(Locale.ENGLISH, "cannot cast %s to string", value));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

package io.crate.integrationtests;

import com.carrotsearch.randomizedtesting.annotations.Repeat;
import io.crate.action.sql.SQLAction;
import io.crate.action.sql.SQLActionException;
import io.crate.action.sql.SQLRequest;
Expand Down Expand Up @@ -284,6 +283,17 @@ public void testGetRequestMapping() throws Exception {
}
}

@Test
public void testInsertObjectIntoString() throws Exception {
execute("create table t1 (o object)");
ensureGreen();
execute("insert into t1 values ({a='abc'})");
refresh();
expectedException.expect(SQLActionException.class);
expectedException.expectMessage("Validation failed for o.a: Invalid string");
execute("insert into t1 values ({a=['123', '456']})");
}

@Test
public void testInsertNewColumn() throws Exception {
setUpSimple();
Expand Down

0 comments on commit 3bbc7fe

Please sign in to comment.