Skip to content

Commit

Permalink
fix: andys comments
Browse files Browse the repository at this point in the history
  • Loading branch information
agavra committed Jan 17, 2020
1 parent 911761a commit 79dff2f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public Void visitCreateArrayExpression(
if (sqlTypes.size() == 0) {
throw new KsqlException("Cannot construct an array with all NULL elements "
+ "(see https://github.com/confluentinc/ksql/issues/4239). As a workaround, you may "
+ "cast the NULL value to a desired type.");
+ "cast a NULL value to the desired type.");
}

if (new HashSet<>(sqlTypes).size() != 1) {
Expand All @@ -383,7 +383,7 @@ public Void visitCreateMapExpression(
+ "value pair (see https://github.com/confluentinc/ksql/issues/4239).");
}

final List<SqlType> gkeyTypes = exp.getMap()
final List<SqlType> keyTypes = exp.getMap()
.keySet()
.stream()
.map(key -> {
Expand All @@ -392,11 +392,11 @@ public Void visitCreateMapExpression(
})
.collect(Collectors.toList());

if (gkeyTypes.stream().anyMatch(type -> !SqlTypes.STRING.equals(type))) {
throw new KsqlException("Only STRING keys are supported in maps but got: " + gkeyTypes);
if (keyTypes.stream().anyMatch(type -> !SqlTypes.STRING.equals(type))) {
throw new KsqlException("Only STRING keys are supported in maps but got: " + keyTypes);
}

final List<SqlType> sqlTypes = exp.getMap()
final List<SqlType> valueTypes = exp.getMap()
.values()
.stream()
.map(val -> {
Expand All @@ -406,19 +406,20 @@ public Void visitCreateMapExpression(
.distinct()
.collect(Collectors.toList());

if (sqlTypes.size() != 1) {
if (valueTypes.size() != 1) {
throw new KsqlException(
String.format(
"Cannot construct a map with mismatching value types (%s) from expression %s.",
sqlTypes,
valueTypes,
exp));
}

if (sqlTypes.get(0) == null) {
throw new KsqlException("Cannot construct a map with NULL values.");
if (valueTypes.get(0) == null) {
throw new KsqlException("Cannot construct MAP with NULL values. As a workaround, you "
+ "may cast a NULL value to the desired type.");
}

context.setSqlType(SqlMap.of(sqlTypes.get(0)));
context.setSqlType(SqlMap.of(valueTypes.get(0)));
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ public void shouldThrowOnMapOfNullValues() {

// Expect
expectedException.expect(KsqlException.class);
expectedException.expectMessage("Cannot construct a map with NULL values");
expectedException.expectMessage("Cannot construct MAP with NULL values");

// When:
expressionTypeManager.getExpressionSqlType(expression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlException",
"message": "Cannot construct an array with all NULL elements (see https://github.com/confluentinc/ksql/issues/4239). As a workaround, you may cast the NULL value to a desired type."
"message": "Cannot construct an array with all NULL elements (see https://github.com/confluentinc/ksql/issues/4239). As a workaround, you may cast a NULL value to the desired type."
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
{
"name": "should handle arbitrary nested expressions",
"statements": [
"CREATE STREAM TEST (I INT, A ARRAY<ARRAY<INT>>) WITH (kafka_topic='test_topic', value_format='JSON');",
"CREATE STREAM TEST (I INT, A ARRAY<ARRAY<BIGINT>>) WITH (kafka_topic='test_topic', value_format='JSON');",
"INSERT INTO TEST (I, A) VALUES (-1, ARRAY[ARRAY[1]]);"
],
"inputs": [
Expand All @@ -249,7 +249,7 @@
{
"name": "should handle map expressions",
"statements": [
"CREATE STREAM TEST (I INT, A MAP<VARCHAR, INT>) WITH (kafka_topic='test_topic', value_format='JSON');",
"CREATE STREAM TEST (I INT, A MAP<VARCHAR, BIGINT>) WITH (kafka_topic='test_topic', value_format='JSON');",
"INSERT INTO TEST (I, A) VALUES (-1, MAP('a':=0, 'b':=1));"
],
"inputs": [
Expand Down

0 comments on commit 79dff2f

Please sign in to comment.