@Override
protected Node visitShowTables(ShowTables showTables, Void context)
{
CatalogSchemaName schema = createCatalogSchemaName(session, showTables, showTables.getSchema());
accessControl.checkCanShowTablesMetadata(session.getRequiredTransactionId(), session.getIdentity(), schema);
if (!metadata.catalogExists(session, schema.getCatalogName())) {
throw new SemanticException(MISSING_CATALOG, showTables, "Catalog '%s' does not exist", schema.getCatalogName());
}
if (!metadata.schemaExists(session, schema)) {
throw new SemanticException(MISSING_SCHEMA, showTables, "Schema '%s' does not exist", schema.getSchemaName());
}
Expression predicate = equal(identifier("table_schema"), new StringLiteral(schema.getSchemaName()));
Optional<String> likePattern = showTables.getLikePattern();
if (likePattern.isPresent()) {
Expression likePredicate = new LikePredicate(
identifier("table_name"),
new StringLiteral(likePattern.get()),
showTables.getEscape().map(StringLiteral::new));
predicate = logicalAnd(predicate, likePredicate);
}
return simpleQuery(
selectList(aliasedName("table_name", "Table")),
from(schema.getCatalogName(), TABLE_TABLES),
predicate,
ordering(ascending("table_name")));
}