@Override protected Void visitShowTables(ShowTables node, Integer context) { builder.append("SHOW TABLES"); node.getSchema().ifPresent(value -> builder.append(" FROM ") .append(formatName(value))); node.getLikePattern().ifPresent(value -> builder.append(" LIKE ") .append(formatStringLiteral(value))); node.getEscape().ifPresent(value -> builder.append(" ESCAPE ") .append(formatStringLiteral(value))); return null; }
@Override public Node visitShowTables(SqlBaseParser.ShowTablesContext context) { return new ShowTables( getLocation(context), Optional.ofNullable(context.qualifiedName()) .map(this::getQualifiedName), getTextIfPresent(context.pattern) .map(AstBuilder::unquote), getTextIfPresent(context.escape) .map(AstBuilder::unquote)); }
@Override protected Void visitShowTables(ShowTables node, Integer context) { builder.append("SHOW TABLES"); node.getSchema().ifPresent(value -> builder.append(" FROM ") .append(formatName(value))); node.getLikePattern().ifPresent(value -> builder.append(" LIKE ") .append(formatStringLiteral(value))); return null; }
@Override protected Void visitShowTables(ShowTables node, Integer context) { builder.append("SHOW TABLES"); node.getSchema().ifPresent((value) -> builder.append(" FROM ") .append(value)); node.getLikePattern().ifPresent((value) -> builder.append(" LIKE ") .append(formatStringLiteral(value))); return null; }
@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"))); }
@Override protected Void visitShowTables(ShowTables node, Integer context) { builder.append("SHOW TABLES"); node.getSchema().ifPresent((value) -> builder.append(" FROM ") .append(value)); node.getLikePattern().ifPresent((value) -> builder.append(" LIKE ") .append(formatStringLiteral(value))); return null; }
@Test public void testShowTables() { assertStatement("SHOW TABLES", new ShowTables(Optional.empty(), Optional.empty(), Optional.empty())); assertStatement("SHOW TABLES FROM a", new ShowTables(Optional.of(QualifiedName.of("a")), Optional.empty(), Optional.empty())); assertStatement("SHOW TABLES FROM \"awesome schema\"", new ShowTables(Optional.of(QualifiedName.of("awesome schema")), Optional.empty(), Optional.empty())); assertStatement("SHOW TABLES IN a LIKE '%$_%' ESCAPE '$'", new ShowTables(Optional.of(QualifiedName.of("a")), Optional.of("%$_%"), Optional.of("$"))); }
@Override protected Void visitShowTables(ShowTables node, Integer context) { builder.append("SHOW TABLES"); node.getSchema().ifPresent(value -> builder.append(" FROM ") .append(formatName(value))); node.getLikePattern().ifPresent(value -> builder.append(" LIKE ") .append(formatStringLiteral(value))); node.getEscape().ifPresent(value -> builder.append(" ESCAPE ") .append(formatStringLiteral(value))); return null; }
String schemaName = session.getSchema().orElse(null); Optional<QualifiedName> schema = showTables.getSchema(); if (schema.isPresent()) { List<String> parts = schema.get().getParts(); Optional<String> likePattern = showTables.getLikePattern(); if (likePattern.isPresent()) { Expression likePredicate = new LikePredicate(nameReference("table_name"), new StringLiteral(likePattern.get()), null);
@Override public Node visitShowTables(SqlBaseParser.ShowTablesContext context) { return new ShowTables( getLocation(context), Optional.ofNullable(context.qualifiedName()) .map(this::getQualifiedName), getTextIfPresent(context.pattern) .map(AstBuilder::unquote)); }
@Override public Node visitShowTables(SqlBaseParser.ShowTablesContext context) { return new ShowTables( getLocation(context), Optional.ofNullable(context.qualifiedName()) .map(this::getQualifiedName), getTextIfPresent(context.pattern) .map(AstBuilder::unquote), getTextIfPresent(context.escape) .map(AstBuilder::unquote)); }
@Test public void testShowTables() { assertStatement("SHOW TABLES", new ShowTables(Optional.empty(), Optional.empty(), Optional.empty())); assertStatement("SHOW TABLES FROM a", new ShowTables(Optional.of(QualifiedName.of("a")), Optional.empty(), Optional.empty())); assertStatement("SHOW TABLES FROM \"awesome schema\"", new ShowTables(Optional.of(QualifiedName.of("awesome schema")), Optional.empty(), Optional.empty())); assertStatement("SHOW TABLES IN a LIKE '%$_%' ESCAPE '$'", new ShowTables(Optional.of(QualifiedName.of("a")), Optional.of("%$_%"), Optional.of("$"))); }
@Test public void testShowTables() throws Exception { assertStatement("SHOW TABLES", new ShowTables(Optional.empty(), Optional.empty())); assertStatement("SHOW TABLES FROM a", new ShowTables(Optional.of(QualifiedName.of("a")), Optional.empty())); assertStatement("SHOW TABLES IN a LIKE '%'", new ShowTables(Optional.of(QualifiedName.of("a")), Optional.of("%"))); }