@Override protected Void visitShowSchemas(ShowSchemas node, Integer context) { builder.append("SHOW SCHEMAS"); if (node.getCatalog().isPresent()) { builder.append(" FROM ") .append(node.getCatalog().get()); } node.getLikePattern().ifPresent((value) -> builder.append(" LIKE ") .append(formatStringLiteral(value))); return null; }
@Override protected RelationType visitShowSchemas(ShowSchemas node, AnalysisContext context) { if (!node.getCatalog().isPresent() && !session.getCatalog().isPresent()) { throw new SemanticException(CATALOG_NOT_SPECIFIED, node, "Catalog must be specified when session catalog is not set"); } Query query = simpleQuery( selectList(aliasedName("schema_name", "Schema")), from(node.getCatalog().orElseGet(() -> session.getCatalog().get()), TABLE_SCHEMATA), ordering(ascending("schema_name"))); return process(query, context); }
@Override protected Void visitShowSchemas(ShowSchemas node, Integer context) { builder.append("SHOW SCHEMAS"); if (node.getCatalog().isPresent()) { builder.append(" FROM ") .append(node.getCatalog().get()); } return null; }
@Test public void testShowSchemas() throws Exception { assertStatement("SHOW SCHEMAS", new ShowSchemas(Optional.<String>empty())); assertStatement("SHOW SCHEMAS FROM foo", new ShowSchemas(Optional.of("foo"))); assertStatement("SHOW SCHEMAS IN foo", new ShowSchemas(Optional.of("foo"))); }
@Override public Node visitShowSchemas(SqlBaseParser.ShowSchemasContext context) { return new ShowSchemas(getLocation(context), getTextIfPresent(context.identifier())); }