Skip to content

Commit

Permalink
MINOR: improve error message for missing key (#9246)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjsax authored Jul 12, 2022
1 parent a80c6f1 commit f2e4991
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public static GrammaticalJoiner and() {
return new GrammaticalJoiner(", ", " and ");
}

public static GrammaticalJoiner comma() {
return new GrammaticalJoiner(", ", ", ");
}

private GrammaticalJoiner(final String separator, final String lastSeparator) {
this.separator = requireNonNull(separator, "separator");
this.lastSeparator = requireNonNull(lastSeparator, "lastSeparator");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ public void shouldHandleNulls() {
public void shouldBuildWithAnd() {
assertThat(GrammaticalJoiner.and().join(Arrays.asList(1, 2, 3)), is("1, 2 and 3"));
}

@Test
public void shouldBuildWithComma() {
assertThat(GrammaticalJoiner.comma().join(Arrays.asList(1, 2, 3)), is("1, 2, 3"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,15 @@ static void throwKeysNotIncludedError(
+ "This expression must be included in the projection and may be aliased. "
: "";

throw new KsqlException("Key" + keyPostfix + " missing from projection. "
throw new KsqlException("Key" + keyPostfix + " missing from projection (ie, SELECT). "
+ additional1
+ System.lineSeparator()
+ "The query used to build " + sinkName
+ " must include the " + types + " " + joined + " in its projection."
+ additional2
+ "The query used to build " + sinkName + " must include the " + types + " " + joined
+ " in its projection (eg, SELECT "
+ (requireAll
? GrammaticalJoiner.comma().join(requiredKeys)
: requiredKeys.stream().findFirst().get())
+ "...)." + additional2
);
}

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

// Then:
assertThat(e.getMessage(), containsString("The query used to build `datasource` must include "
+ "the key columns k0 and k1 in its projection."));
+ "the key columns k0 and k1 in its projection (eg, SELECT k0, k1...)."));
}

@Test
Expand All @@ -450,7 +450,7 @@ public void shouldThrowIfProjectionDoesNotContainAllKeyColumns() {

// Then:
assertThat(e.getMessage(), containsString("The query used to build `datasource` must include " +
"the key columns k0 and k1 in its projection."));
"the key columns k0 and k1 in its projection (eg, SELECT k0, k1...)."));
}

private void givenNodeWithMockSource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ public void shouldTestExpressionForBothOriginalAndRewrittenJoinKeys() {
@Test
public void shouldThrowIfProjectionDoesNotIncludeAnyJoinColumns() {
// Given:
final JoinNode joinNode = new JoinNode(nodeId, LEFT, joinKey, true, left, right,
final JoinNode joinNode = new JoinNode(nodeId, LEFT, joinKey, true, left, right,
empty(),"KAFKA");

when(joinKey.getAllViableKeys(any()))
Expand All @@ -929,7 +929,7 @@ public void shouldThrowIfProjectionDoesNotIncludeAnyJoinColumns() {
// Then:
assertThat(e.getMessage(), containsString("The query used to build `sink` "
+ "must include the join expressions expression1, expression1 or expression2 "
+ "in its projection."));
+ "in its projection (eg, SELECT expression1..."));
}

@SuppressWarnings({"unchecked", "rawtypes"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void shouldThrowIfProjectionMissingPartitionBy() {

// Then:
assertThat(e.getMessage(), containsString("The query used to build `S1` "
+ "must include the partitioning expression T.ID in its projection."));
+ "must include the partitioning expression T.ID in its projection (eg, SELECT T.ID..."));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the join expressions LEFT_TABLE.ID1 or RIGHT_TABLE.ID3 in its projection."
"message": "The query used to build `OUTPUT` must include the join expressions LEFT_TABLE.ID1 or RIGHT_TABLE.ID3 in its projection (eg, SELECT LEFT_TABLE.ID1...)."
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the grouping expression NAME in its projection."
"message": "The query used to build `OUTPUT` must include the grouping expression NAME in its projection (eg, SELECT NAME...)."
}
},
{
Expand All @@ -876,7 +876,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the grouping expression NAME in its projection."
"message": "The query used to build `OUTPUT` must include the grouping expression NAME in its projection (eg, SELECT NAME...)."
}
},
{
Expand All @@ -887,7 +887,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the grouping expression F1 in its projection."
"message": "The query used to build `OUTPUT` must include the grouping expression F1 in its projection (eg, SELECT F1...)."
}
},
{
Expand All @@ -909,7 +909,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the grouping expressions F1, F2 and F3 in its projection."
"message": "The query used to build `OUTPUT` must include the grouping expressions F1, F2 and F3 in its projection (eg, SELECT F1, F2, F3...)."
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the join expressions L.A or R.A in its projection."
"message": "The query used to build `OUTPUT` must include the join expressions L.A or R.A in its projection (eg, SELECT L.A...)."
}
},
{
Expand All @@ -255,7 +255,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "Key missing from projection. See https://cnfl.io/2LV7ouS.\nThe query used to build `OUTPUT` must include the join expression ROWKEY in its projection.\nROWKEY was added as a synthetic key column because the join criteria did not match any source column. This expression must be included in the projection and may be aliased."
"message": "Key missing from projection (ie, SELECT). See https://cnfl.io/2LV7ouS.\nThe query used to build `OUTPUT` must include the join expression ROWKEY in its projection (eg, SELECT ROWKEY...).\nROWKEY was added as a synthetic key column because the join criteria did not match any source column. This expression must be included in the projection and may be aliased."
}
},
{
Expand Down Expand Up @@ -348,7 +348,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the join expressions L.A or R.A in its projection."
"message": "The query used to build `OUTPUT` must include the join expressions L.A or R.A in its projection (eg, SELECT L.A...)."
}
},
{
Expand All @@ -360,7 +360,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the join expression R.A in its projection."
"message": "The query used to build `OUTPUT` must include the join expression R.A in its projection (eg, SELECT R.A...)."
}
},
{
Expand All @@ -372,7 +372,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "Key missing from projection. See https://cnfl.io/2LV7ouS.\nThe query used to build `OUTPUT` must include the join expression ROWKEY in its projection.\nROWKEY was added as a synthetic key column because the join criteria did not match any source column."
"message": "Key missing from projection (ie, SELECT). See https://cnfl.io/2LV7ouS.\nThe query used to build `OUTPUT` must include the join expression ROWKEY in its projection (eg, SELECT ROWKEY...).\nROWKEY was added as a synthetic key column because the join criteria did not match any source column."
}
},
{
Expand Down Expand Up @@ -405,7 +405,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the join expression ROWKEY in its projection.\nROWKEY was added as a synthetic key column because the join criteria did not match any source column."
"message": "The query used to build `OUTPUT` must include the join expression ROWKEY in its projection (eg, SELECT ROWKEY...).\nROWKEY was added as a synthetic key column because the join criteria did not match any source column."
}
},
{
Expand All @@ -417,7 +417,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the join expressions L.A or R.A in its projection."
"message": "The query used to build `OUTPUT` must include the join expressions L.A or R.A in its projection (eg, SELECT L.A...)."
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the key columns K and K2 in its projection."
"message": "The query used to build `OUTPUT` must include the key columns K and K2 in its projection (eg, SELECT K, K2...)."
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the join expressions S1.ID, T2.ID or T3.ID in its projection."
"message": "The query used to build `OUTPUT` must include the join expressions S1.ID, T2.ID or T3.ID in its projection (eg, SELECT S1.ID...)."
}
},
{
Expand All @@ -115,7 +115,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the join expressions S1.ID or T3.ID in its projection."
"message": "The query used to build `OUTPUT` must include the join expressions S1.ID or T3.ID in its projection (eg, SELECT S1.ID...)."
}
},
{
Expand All @@ -128,7 +128,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the join expression T3.ID in its projection."
"message": "The query used to build `OUTPUT` must include the join expression T3.ID in its projection (eg, SELECT T3.ID...)."
}
},
{
Expand All @@ -141,7 +141,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the join expressions S1.ID, T2.ID or T3.ID in its projection."
"message": "The query used to build `OUTPUT` must include the join expressions S1.ID, T2.ID or T3.ID in its projection (eg, SELECT S1.ID...)."
}
},
{
Expand All @@ -154,7 +154,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the join expressions S1.ID or T3.ID in its projection."
"message": "The query used to build `OUTPUT` must include the join expressions S1.ID or T3.ID in its projection (eg, SELECT S1.ID...)."
}
},
{
Expand All @@ -167,7 +167,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the join expression T3.ID in its projection."
"message": "The query used to build `OUTPUT` must include the join expression T3.ID in its projection (eg, SELECT T3.ID...)."
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the partitioning expression ABS(INPUT.ID) in its projection."
"message": "The query used to build `OUTPUT` must include the partitioning expression ABS(INPUT.ID) in its projection (eg, SELECT ABS(INPUT.ID)...)."
}
},
{
Expand All @@ -233,7 +233,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the partitioning expression INPUT.ID in its projection."
"message": "The query used to build `OUTPUT` must include the partitioning expression INPUT.ID in its projection (eg, SELECT INPUT.ID...)."
}
},
{
Expand Down Expand Up @@ -1385,7 +1385,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the partitioning expressions INPUT.ID and INPUT.AGE in its projection."
"message": "The query used to build `OUTPUT` must include the partitioning expressions INPUT.ID and INPUT.AGE in its projection (eg, SELECT INPUT.ID, INPUT.AGE...)."
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the key column ID in its projection."
"message": "The query used to build `OUTPUT` must include the key column ID in its projection (eg, SELECT ID...)."
}
},
{
Expand All @@ -472,7 +472,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the key columns ID and ID2 in its projection."
"message": "The query used to build `OUTPUT` must include the key columns ID and ID2 in its projection (eg, SELECT ID, ID2...)."
}
},
{
Expand All @@ -483,7 +483,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the key column ID in its projection."
"message": "The query used to build `OUTPUT` must include the key column ID in its projection (eg, SELECT ID...)."
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "The query used to build `OUTPUT` must include the key column ID in its projection."
"message": "The query used to build `OUTPUT` must include the key column ID in its projection (eg, SELECT ID...)"
}
},
{
Expand Down

0 comments on commit f2e4991

Please sign in to comment.