Skip to content

Commit

Permalink
fix: give hint when source name has extra/lacks dquotes (#9594)
Browse files Browse the repository at this point in the history
  • Loading branch information
aliehsaeedii committed Sep 23, 2022
1 parent 6541744 commit f6ec16a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ private static SourceDescriptionWithWarnings describeSource(
final DataSource dataSource = ksqlExecutionContext.getMetaStore().getSource(name);
if (dataSource == null) {
throw new KsqlStatementException(String.format(
"Could not find STREAM/TABLE '%s' in the Metastore",
"Could not find STREAM/TABLE '%s' in the Metastore"
+ ksqlExecutionContext.getMetaStore().checkAlternatives(
name, Optional.empty()),
name.text()
), statement.getMaskedStatementText());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,48 @@ public void shouldThrowOnDescribeMissingSource() {
"Could not find STREAM/TABLE 'S' in the Metastore"));
}

@Test
public void shouldThrowOnDescribeSourceNameWithoutQuotes() {
// Given:
engine.givenSource(DataSourceType.KTABLE, "table1");

// When:
final Exception e = assertThrows(
KsqlStatementException.class,
() -> CustomExecutors.SHOW_COLUMNS.execute(
engine.configure("DESCRIBE table1;"),
SESSION_PROPERTIES,
engine.getEngine(),
engine.getServiceContext()
)
);

// Then:
assertThat(e.getMessage(), containsString(
"Could not find STREAM/TABLE 'TABLE1' in the Metastore\nDid you mean \"table1\"? Hint: wrap the source name in double quotes to make it case-sensitive."));
}

@Test
public void shouldThrowOnDescribeSourceNameWithQuotes() {
// Given:
engine.givenSource(DataSourceType.KSTREAM, "STREAM1");

// When:
final Exception e = assertThrows(
KsqlStatementException.class,
() -> CustomExecutors.SHOW_COLUMNS.execute(
engine.configure("DESCRIBE \"stream1\";"),
SESSION_PROPERTIES,
engine.getEngine(),
engine.getServiceContext()
)
);

// Then:
assertThat(e.getMessage(), containsString(
"Could not find STREAM/TABLE 'stream1' in the Metastore\nDid you mean STREAM1? Hint: try removing double quotes from the source name."));
}

@Test
public void shouldNotCallTopicClientForExtendedDescription() {
// Given:
Expand Down

0 comments on commit f6ec16a

Please sign in to comment.