Răsfoiți Sursa

SQL: Remove slightly used meta commands (#37506)

Remove SYS CATALOGS and SYS TABLE TYPES as they are a subset of SYS
TABLES (and thus somewhat redundant) and used only by JDBC.

Close #37409
Costin Leau 6 ani în urmă
părinte
comite
023bb2f1e4
17 a modificat fișierele cu 244 adăugiri și 595 ștergeri
  1. 28 4
      x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/JdbcDatabaseMetaData.java
  2. 19 2
      x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/DatabaseMetaDataTestCase.java
  3. 2 2
      x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlUsageTestCase.java
  4. 2 10
      x-pack/plugin/sql/qa/src/main/resources/setup_mock_metadata_get_table_types.sql
  5. 15 0
      x-pack/plugin/sql/qa/src/main/resources/setup_mock_metadata_get_types_of_table.sql
  6. 0 2
      x-pack/plugin/sql/src/main/antlr/SqlBase.g4
  7. 0 14
      x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/CommandBuilder.java
  8. 0 24
      x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/SqlBaseBaseListener.java
  9. 0 14
      x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/SqlBaseBaseVisitor.java
  10. 0 24
      x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/SqlBaseListener.java
  11. 177 236
      x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/SqlBaseParser.java
  12. 0 14
      x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/SqlBaseVisitor.java
  13. 0 64
      x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plan/logical/command/sys/SysCatalogs.java
  14. 0 70
      x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plan/logical/command/sys/SysTableTypes.java
  15. 0 61
      x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/plan/logical/command/sys/SysCatalogsTests.java
  16. 0 52
      x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/plan/logical/command/sys/SysTableTypesTests.java
  17. 1 2
      x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/stats/VerifierMetricsTests.java

+ 28 - 4
x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/JdbcDatabaseMetaData.java

@@ -773,12 +773,16 @@ class JdbcDatabaseMetaData implements DatabaseMetaData, JdbcWrapper {
 
 
     @Override
     @Override
     public ResultSet getCatalogs() throws SQLException {
     public ResultSet getCatalogs() throws SQLException {
-        return con.createStatement().executeQuery("SYS CATALOGS");
+        // TABLE_CAT is the first column
+        Object[][] data = queryColumn(con, "SYS TABLES CATALOG LIKE '%'", 1);
+        return memorySet(con.cfg, columnInfo("", "TABLE_CAT"), data);
     }
     }
 
 
     @Override
     @Override
     public ResultSet getTableTypes() throws SQLException {
     public ResultSet getTableTypes() throws SQLException {
-        return con.createStatement().executeQuery("SYS TABLE TYPES");
+        // TABLE_TYPE (4)
+        Object[][] data = queryColumn(con, "SYS TABLES TYPE '%'", 4);
+        return memorySet(con.cfg, columnInfo("", "TABLE_TYPE"), data);
     }
     }
 
 
     @Override
     @Override
@@ -1114,6 +1118,26 @@ class JdbcDatabaseMetaData implements DatabaseMetaData, JdbcWrapper {
         return false;
         return false;
     }
     }
 
 
+    //
+    // Utility methods
+    //
+
+    private static Object[][] queryColumn(JdbcConnection con, String query, int... cols) throws SQLException {
+        List<Object[]> data = new ArrayList<>();
+        try (ResultSet rs = con.createStatement().executeQuery(query)) {
+            while (rs.next()) {
+                Object[] row = new Object[cols.length];
+                for (int i = 0; i < cols.length; i++) {
+                    row[i] = rs.getObject(cols[i]);
+                }
+                data.add(row);
+            }
+        }
+        
+        return data.toArray(new Object[][] {});
+    }
+
+
     private static List<JdbcColumnInfo> columnInfo(String tableName, Object... cols) throws JdbcSQLException {
     private static List<JdbcColumnInfo> columnInfo(String tableName, Object... cols) throws JdbcSQLException {
         List<JdbcColumnInfo> columns = new ArrayList<>();
         List<JdbcColumnInfo> columns = new ArrayList<>();
 
 
@@ -1156,7 +1180,7 @@ class JdbcDatabaseMetaData implements DatabaseMetaData, JdbcWrapper {
         return new JdbcResultSet(cfg, null, new InMemoryCursor(columns, data));
         return new JdbcResultSet(cfg, null, new InMemoryCursor(columns, data));
     }
     }
 
 
-    static class InMemoryCursor implements Cursor {
+    private static class InMemoryCursor implements Cursor {
 
 
         private final List<JdbcColumnInfo> columns;
         private final List<JdbcColumnInfo> columns;
         private final Object[][] data;
         private final Object[][] data;
@@ -1197,4 +1221,4 @@ class JdbcDatabaseMetaData implements DatabaseMetaData, JdbcWrapper {
             // this cursor doesn't hold any resource - no need to clean up
             // this cursor doesn't hold any resource - no need to clean up
         }
         }
     }
     }
-}
+}

+ 19 - 2
x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/DatabaseMetaDataTestCase.java

@@ -71,12 +71,12 @@ public class DatabaseMetaDataTestCase extends JdbcIntegrationTestCase {
         }
         }
     }
     }
 
 
-    public void testGetTableTypes() throws Exception {
+    public void testGetTypeOfTables() throws Exception {
         index("test1", body -> body.field("name", "bob"));
         index("test1", body -> body.field("name", "bob"));
         index("test2", body -> body.field("name", "bob"));
         index("test2", body -> body.field("name", "bob"));
 
 
         try (Connection h2 = LocalH2.anonymousDb(); Connection es = esJdbc()) {
         try (Connection h2 = LocalH2.anonymousDb(); Connection es = esJdbc()) {
-            h2.createStatement().executeUpdate("RUNSCRIPT FROM 'classpath:/setup_mock_metadata_get_table_types.sql'");
+            h2.createStatement().executeUpdate("RUNSCRIPT FROM 'classpath:/setup_mock_metadata_get_types_of_table.sql'");
 
 
             CheckedSupplier<ResultSet, SQLException> all = () -> h2.createStatement()
             CheckedSupplier<ResultSet, SQLException> all = () -> h2.createStatement()
                     .executeQuery("SELECT '" + clusterName() + "' AS TABLE_CAT, * FROM mock");
                     .executeQuery("SELECT '" + clusterName() + "' AS TABLE_CAT, * FROM mock");
@@ -88,6 +88,23 @@ public class DatabaseMetaDataTestCase extends JdbcIntegrationTestCase {
         }
         }
     }
     }
 
 
+    public void testGetTableTypes() throws Exception {
+        index("test1", body -> body.field("name", "bob"));
+        index("test2", body -> body.field("name", "bob"));
+
+        try (Connection h2 = LocalH2.anonymousDb(); Connection es = esJdbc()) {
+            h2.createStatement().executeUpdate("RUNSCRIPT FROM 'classpath:/setup_mock_metadata_get_table_types.sql'");
+            assertResultSets(h2.createStatement().executeQuery("SELECT * FROM mock"), es.getMetaData().getTableTypes());
+        }
+    }
+
+    public void testGetCatalogs() throws Exception {
+        try (Connection h2 = LocalH2.anonymousDb(); Connection es = esJdbc()) {
+            assertResultSets(h2.createStatement().executeQuery("SELECT '" + clusterName() + "' AS TABLE_CAT"),
+                    es.getMetaData().getCatalogs());
+        }
+    }
+
     public void testColumns() throws Exception {
     public void testColumns() throws Exception {
         index("test1", body -> body.field("name", "bob"));
         index("test1", body -> body.field("name", "bob"));
         index("test2", body -> {
         index("test2", body -> {

+ 2 - 2
x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlUsageTestCase.java

@@ -160,8 +160,8 @@ public abstract class RestSqlUsageTestCase extends ESRestTestCase {
         allTotalQueries += randomCommandExecutions;
         allTotalQueries += randomCommandExecutions;
         for (int i = 0; i < randomCommandExecutions; i++) {
         for (int i = 0; i < randomCommandExecutions; i++) {
             runSql(randomFrom("SHOW FUNCTIONS", "SHOW COLUMNS FROM library", "SHOW SCHEMAS",
             runSql(randomFrom("SHOW FUNCTIONS", "SHOW COLUMNS FROM library", "SHOW SCHEMAS",
-                                 "SHOW TABLES", "SYS CATALOGS", "SYS COLUMNS LIKE '%name'",
-                                 "SYS TABLES", "SYS TYPES"));
+                                 "SHOW TABLES", "SYS TABLES", "SYS COLUMNS LIKE '%name'",
+                                 "SYS TABLES TYPE '%'", "SYS TYPES"));
         }
         }
         responseAsMap = getStats();
         responseAsMap = getStats();
         assertFeatureMetric(baseMetrics.get("command") + randomCommandExecutions, responseAsMap, "command");
         assertFeatureMetric(baseMetrics.get("command") + randomCommandExecutions, responseAsMap, "command");

+ 2 - 10
x-pack/plugin/sql/qa/src/main/resources/setup_mock_metadata_get_table_types.sql

@@ -1,15 +1,7 @@
 CREATE TABLE mock (
 CREATE TABLE mock (
-  TABLE_SCHEM VARCHAR,
-  TABLE_NAME VARCHAR,
   TABLE_TYPE VARCHAR,
   TABLE_TYPE VARCHAR,
-  REMARKS VARCHAR,
-  TYPE_CAT VARCHAR,
-  TYPE_SCHEM VARCHAR,
-  TYPE_NAME VARCHAR,
-  SELF_REFERENCING_COL_NAME VARCHAR,
-  REF_GENERATION VARCHAR
 ) AS
 ) AS
-SELECT '', 'test1', 'BASE TABLE', '', null, null, null, null, null FROM DUAL
+SELECT 'ALIAS' FROM DUAL
 UNION ALL
 UNION ALL
-SELECT '', 'test2', 'BASE TABLE', '', null, null, null, null, null FROM DUAL
+SELECT 'BASE TABLE' FROM DUAL
 ;
 ;

+ 15 - 0
x-pack/plugin/sql/qa/src/main/resources/setup_mock_metadata_get_types_of_table.sql

@@ -0,0 +1,15 @@
+CREATE TABLE mock (
+  TABLE_SCHEM VARCHAR,
+  TABLE_NAME VARCHAR,
+  TABLE_TYPE VARCHAR,
+  REMARKS VARCHAR,
+  TYPE_CAT VARCHAR,
+  TYPE_SCHEM VARCHAR,
+  TYPE_NAME VARCHAR,
+  SELF_REFERENCING_COL_NAME VARCHAR,
+  REF_GENERATION VARCHAR
+) AS
+SELECT '', 'test1', 'BASE TABLE', '', null, null, null, null, null FROM DUAL
+UNION ALL
+SELECT '', 'test2', 'BASE TABLE', '', null, null, null, null, null FROM DUAL
+;

+ 0 - 2
x-pack/plugin/sql/src/main/antlr/SqlBase.g4

@@ -55,7 +55,6 @@ statement
     | (DESCRIBE | DESC) (tableLike=likePattern | tableIdent=tableIdentifier)                              #showColumns
     | (DESCRIBE | DESC) (tableLike=likePattern | tableIdent=tableIdentifier)                              #showColumns
     | SHOW FUNCTIONS (likePattern)?                                                                       #showFunctions
     | SHOW FUNCTIONS (likePattern)?                                                                       #showFunctions
     | SHOW SCHEMAS                                                                                        #showSchemas
     | SHOW SCHEMAS                                                                                        #showSchemas
-    | SYS CATALOGS                                                                                        #sysCatalogs
     | SYS TABLES (CATALOG clusterLike=likePattern)?
     | SYS TABLES (CATALOG clusterLike=likePattern)?
                  (tableLike=likePattern | tableIdent=tableIdentifier)?
                  (tableLike=likePattern | tableIdent=tableIdentifier)?
                  (TYPE string (',' string)* )?                                                            #sysTables
                  (TYPE string (',' string)* )?                                                            #sysTables
@@ -63,7 +62,6 @@ statement
                   (TABLE tableLike=likePattern | tableIdent=tableIdentifier)?
                   (TABLE tableLike=likePattern | tableIdent=tableIdentifier)?
                   (columnPattern=likePattern)?                                                            #sysColumns
                   (columnPattern=likePattern)?                                                            #sysColumns
     | SYS TYPES ((PLUS | MINUS)?  type=number)?                                                           #sysTypes
     | SYS TYPES ((PLUS | MINUS)?  type=number)?                                                           #sysTypes
-    | SYS TABLE TYPES                                                                                     #sysTableTypes  
     ;
     ;
     
     
 query
 query

+ 0 - 14
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/CommandBuilder.java

@@ -16,9 +16,7 @@ import org.elasticsearch.xpack.sql.parser.SqlBaseParser.ShowFunctionsContext;
 import org.elasticsearch.xpack.sql.parser.SqlBaseParser.ShowSchemasContext;
 import org.elasticsearch.xpack.sql.parser.SqlBaseParser.ShowSchemasContext;
 import org.elasticsearch.xpack.sql.parser.SqlBaseParser.ShowTablesContext;
 import org.elasticsearch.xpack.sql.parser.SqlBaseParser.ShowTablesContext;
 import org.elasticsearch.xpack.sql.parser.SqlBaseParser.StringContext;
 import org.elasticsearch.xpack.sql.parser.SqlBaseParser.StringContext;
-import org.elasticsearch.xpack.sql.parser.SqlBaseParser.SysCatalogsContext;
 import org.elasticsearch.xpack.sql.parser.SqlBaseParser.SysColumnsContext;
 import org.elasticsearch.xpack.sql.parser.SqlBaseParser.SysColumnsContext;
-import org.elasticsearch.xpack.sql.parser.SqlBaseParser.SysTableTypesContext;
 import org.elasticsearch.xpack.sql.parser.SqlBaseParser.SysTablesContext;
 import org.elasticsearch.xpack.sql.parser.SqlBaseParser.SysTablesContext;
 import org.elasticsearch.xpack.sql.parser.SqlBaseParser.SysTypesContext;
 import org.elasticsearch.xpack.sql.parser.SqlBaseParser.SysTypesContext;
 import org.elasticsearch.xpack.sql.plan.TableIdentifier;
 import org.elasticsearch.xpack.sql.plan.TableIdentifier;
@@ -29,9 +27,7 @@ import org.elasticsearch.xpack.sql.plan.logical.command.ShowColumns;
 import org.elasticsearch.xpack.sql.plan.logical.command.ShowFunctions;
 import org.elasticsearch.xpack.sql.plan.logical.command.ShowFunctions;
 import org.elasticsearch.xpack.sql.plan.logical.command.ShowSchemas;
 import org.elasticsearch.xpack.sql.plan.logical.command.ShowSchemas;
 import org.elasticsearch.xpack.sql.plan.logical.command.ShowTables;
 import org.elasticsearch.xpack.sql.plan.logical.command.ShowTables;
-import org.elasticsearch.xpack.sql.plan.logical.command.sys.SysCatalogs;
 import org.elasticsearch.xpack.sql.plan.logical.command.sys.SysColumns;
 import org.elasticsearch.xpack.sql.plan.logical.command.sys.SysColumns;
-import org.elasticsearch.xpack.sql.plan.logical.command.sys.SysTableTypes;
 import org.elasticsearch.xpack.sql.plan.logical.command.sys.SysTables;
 import org.elasticsearch.xpack.sql.plan.logical.command.sys.SysTables;
 import org.elasticsearch.xpack.sql.plan.logical.command.sys.SysTypes;
 import org.elasticsearch.xpack.sql.plan.logical.command.sys.SysTypes;
 import org.elasticsearch.xpack.sql.proto.SqlTypedParamValue;
 import org.elasticsearch.xpack.sql.proto.SqlTypedParamValue;
@@ -144,11 +140,6 @@ abstract class CommandBuilder extends LogicalPlanBuilder {
         return new ShowColumns(source(ctx), index, visitLikePattern(ctx.likePattern()));
         return new ShowColumns(source(ctx), index, visitLikePattern(ctx.likePattern()));
     }
     }
 
 
-    @Override
-    public Object visitSysCatalogs(SysCatalogsContext ctx) {
-        return new SysCatalogs(source(ctx));
-    }
-
     @Override
     @Override
     public SysTables visitSysTables(SysTablesContext ctx) {
     public SysTables visitSysTables(SysTablesContext ctx) {
         List<IndexType> types = new ArrayList<>();
         List<IndexType> types = new ArrayList<>();
@@ -199,9 +190,4 @@ abstract class CommandBuilder extends LogicalPlanBuilder {
 
 
         return new SysTypes(source(ctx), Integer.valueOf(type));
         return new SysTypes(source(ctx), Integer.valueOf(type));
     }
     }
-
-    @Override
-    public Object visitSysTableTypes(SysTableTypesContext ctx) {
-        return new SysTableTypes(source(ctx));
-    }
 }
 }

+ 0 - 24
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/SqlBaseBaseListener.java

@@ -119,18 +119,6 @@ class SqlBaseBaseListener implements SqlBaseListener {
    * <p>The default implementation does nothing.</p>
    * <p>The default implementation does nothing.</p>
    */
    */
   @Override public void exitShowSchemas(SqlBaseParser.ShowSchemasContext ctx) { }
   @Override public void exitShowSchemas(SqlBaseParser.ShowSchemasContext ctx) { }
-  /**
-   * {@inheritDoc}
-   *
-   * <p>The default implementation does nothing.</p>
-   */
-  @Override public void enterSysCatalogs(SqlBaseParser.SysCatalogsContext ctx) { }
-  /**
-   * {@inheritDoc}
-   *
-   * <p>The default implementation does nothing.</p>
-   */
-  @Override public void exitSysCatalogs(SqlBaseParser.SysCatalogsContext ctx) { }
   /**
   /**
    * {@inheritDoc}
    * {@inheritDoc}
    *
    *
@@ -167,18 +155,6 @@ class SqlBaseBaseListener implements SqlBaseListener {
    * <p>The default implementation does nothing.</p>
    * <p>The default implementation does nothing.</p>
    */
    */
   @Override public void exitSysTypes(SqlBaseParser.SysTypesContext ctx) { }
   @Override public void exitSysTypes(SqlBaseParser.SysTypesContext ctx) { }
-  /**
-   * {@inheritDoc}
-   *
-   * <p>The default implementation does nothing.</p>
-   */
-  @Override public void enterSysTableTypes(SqlBaseParser.SysTableTypesContext ctx) { }
-  /**
-   * {@inheritDoc}
-   *
-   * <p>The default implementation does nothing.</p>
-   */
-  @Override public void exitSysTableTypes(SqlBaseParser.SysTableTypesContext ctx) { }
   /**
   /**
    * {@inheritDoc}
    * {@inheritDoc}
    *
    *

+ 0 - 14
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/SqlBaseBaseVisitor.java

@@ -74,13 +74,6 @@ class SqlBaseBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements SqlBa
    * {@link #visitChildren} on {@code ctx}.</p>
    * {@link #visitChildren} on {@code ctx}.</p>
    */
    */
   @Override public T visitShowSchemas(SqlBaseParser.ShowSchemasContext ctx) { return visitChildren(ctx); }
   @Override public T visitShowSchemas(SqlBaseParser.ShowSchemasContext ctx) { return visitChildren(ctx); }
-  /**
-   * {@inheritDoc}
-   *
-   * <p>The default implementation returns the result of calling
-   * {@link #visitChildren} on {@code ctx}.</p>
-   */
-  @Override public T visitSysCatalogs(SqlBaseParser.SysCatalogsContext ctx) { return visitChildren(ctx); }
   /**
   /**
    * {@inheritDoc}
    * {@inheritDoc}
    *
    *
@@ -102,13 +95,6 @@ class SqlBaseBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements SqlBa
    * {@link #visitChildren} on {@code ctx}.</p>
    * {@link #visitChildren} on {@code ctx}.</p>
    */
    */
   @Override public T visitSysTypes(SqlBaseParser.SysTypesContext ctx) { return visitChildren(ctx); }
   @Override public T visitSysTypes(SqlBaseParser.SysTypesContext ctx) { return visitChildren(ctx); }
-  /**
-   * {@inheritDoc}
-   *
-   * <p>The default implementation returns the result of calling
-   * {@link #visitChildren} on {@code ctx}.</p>
-   */
-  @Override public T visitSysTableTypes(SqlBaseParser.SysTableTypesContext ctx) { return visitChildren(ctx); }
   /**
   /**
    * {@inheritDoc}
    * {@inheritDoc}
    *
    *

+ 0 - 24
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/SqlBaseListener.java

@@ -111,18 +111,6 @@ interface SqlBaseListener extends ParseTreeListener {
    * @param ctx the parse tree
    * @param ctx the parse tree
    */
    */
   void exitShowSchemas(SqlBaseParser.ShowSchemasContext ctx);
   void exitShowSchemas(SqlBaseParser.ShowSchemasContext ctx);
-  /**
-   * Enter a parse tree produced by the {@code sysCatalogs}
-   * labeled alternative in {@link SqlBaseParser#statement}.
-   * @param ctx the parse tree
-   */
-  void enterSysCatalogs(SqlBaseParser.SysCatalogsContext ctx);
-  /**
-   * Exit a parse tree produced by the {@code sysCatalogs}
-   * labeled alternative in {@link SqlBaseParser#statement}.
-   * @param ctx the parse tree
-   */
-  void exitSysCatalogs(SqlBaseParser.SysCatalogsContext ctx);
   /**
   /**
    * Enter a parse tree produced by the {@code sysTables}
    * Enter a parse tree produced by the {@code sysTables}
    * labeled alternative in {@link SqlBaseParser#statement}.
    * labeled alternative in {@link SqlBaseParser#statement}.
@@ -159,18 +147,6 @@ interface SqlBaseListener extends ParseTreeListener {
    * @param ctx the parse tree
    * @param ctx the parse tree
    */
    */
   void exitSysTypes(SqlBaseParser.SysTypesContext ctx);
   void exitSysTypes(SqlBaseParser.SysTypesContext ctx);
-  /**
-   * Enter a parse tree produced by the {@code sysTableTypes}
-   * labeled alternative in {@link SqlBaseParser#statement}.
-   * @param ctx the parse tree
-   */
-  void enterSysTableTypes(SqlBaseParser.SysTableTypesContext ctx);
-  /**
-   * Exit a parse tree produced by the {@code sysTableTypes}
-   * labeled alternative in {@link SqlBaseParser#statement}.
-   * @param ctx the parse tree
-   */
-  void exitSysTableTypes(SqlBaseParser.SysTableTypesContext ctx);
   /**
   /**
    * Enter a parse tree produced by {@link SqlBaseParser#query}.
    * Enter a parse tree produced by {@link SqlBaseParser#query}.
    * @param ctx the parse tree
    * @param ctx the parse tree

Fișier diff suprimat deoarece este prea mare
+ 177 - 236
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/SqlBaseParser.java


+ 0 - 14
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/SqlBaseVisitor.java

@@ -71,13 +71,6 @@ interface SqlBaseVisitor<T> extends ParseTreeVisitor<T> {
    * @return the visitor result
    * @return the visitor result
    */
    */
   T visitShowSchemas(SqlBaseParser.ShowSchemasContext ctx);
   T visitShowSchemas(SqlBaseParser.ShowSchemasContext ctx);
-  /**
-   * Visit a parse tree produced by the {@code sysCatalogs}
-   * labeled alternative in {@link SqlBaseParser#statement}.
-   * @param ctx the parse tree
-   * @return the visitor result
-   */
-  T visitSysCatalogs(SqlBaseParser.SysCatalogsContext ctx);
   /**
   /**
    * Visit a parse tree produced by the {@code sysTables}
    * Visit a parse tree produced by the {@code sysTables}
    * labeled alternative in {@link SqlBaseParser#statement}.
    * labeled alternative in {@link SqlBaseParser#statement}.
@@ -99,13 +92,6 @@ interface SqlBaseVisitor<T> extends ParseTreeVisitor<T> {
    * @return the visitor result
    * @return the visitor result
    */
    */
   T visitSysTypes(SqlBaseParser.SysTypesContext ctx);
   T visitSysTypes(SqlBaseParser.SysTypesContext ctx);
-  /**
-   * Visit a parse tree produced by the {@code sysTableTypes}
-   * labeled alternative in {@link SqlBaseParser#statement}.
-   * @param ctx the parse tree
-   * @return the visitor result
-   */
-  T visitSysTableTypes(SqlBaseParser.SysTableTypesContext ctx);
   /**
   /**
    * Visit a parse tree produced by {@link SqlBaseParser#query}.
    * Visit a parse tree produced by {@link SqlBaseParser#query}.
    * @param ctx the parse tree
    * @param ctx the parse tree

+ 0 - 64
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plan/logical/command/sys/SysCatalogs.java

@@ -1,64 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-package org.elasticsearch.xpack.sql.plan.logical.command.sys;
-
-import org.elasticsearch.action.ActionListener;
-import org.elasticsearch.xpack.sql.expression.Attribute;
-import org.elasticsearch.xpack.sql.plan.logical.command.Command;
-import org.elasticsearch.xpack.sql.session.Rows;
-import org.elasticsearch.xpack.sql.session.SchemaRowSet;
-import org.elasticsearch.xpack.sql.session.SqlSession;
-import org.elasticsearch.xpack.sql.tree.Source;
-import org.elasticsearch.xpack.sql.tree.NodeInfo;
-
-import java.util.List;
-
-import static java.util.Collections.singletonList;
-
-/**
- * System command returning the catalogs (clusters) available.
- * Currently returns only the current cluster name.
- */
-public class SysCatalogs extends Command {
-
-    public SysCatalogs(Source source) {
-        super(source);
-    }
-
-    @Override
-    protected NodeInfo<SysCatalogs> info() {
-        return NodeInfo.create(this);
-    }
-
-    @Override
-    public List<Attribute> output() {
-        return singletonList(keyword("TABLE_CAT"));
-    }
-
-    @Override
-    public final void execute(SqlSession session, ActionListener<SchemaRowSet> listener) {
-        String cluster = session.indexResolver().clusterName();
-        listener.onResponse(Rows.of(output(), singletonList(singletonList(cluster))));
-    }
-
-    @Override
-    public int hashCode() {
-        return getClass().hashCode();
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-
-        if (obj == null || getClass() != obj.getClass()) {
-            return false;
-        }
-
-        return true;
-    }
-}

+ 0 - 70
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plan/logical/command/sys/SysTableTypes.java

@@ -1,70 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-package org.elasticsearch.xpack.sql.plan.logical.command.sys;
-
-import org.elasticsearch.action.ActionListener;
-import org.elasticsearch.xpack.sql.analysis.index.IndexResolver.IndexType;
-import org.elasticsearch.xpack.sql.expression.Attribute;
-import org.elasticsearch.xpack.sql.plan.logical.command.Command;
-import org.elasticsearch.xpack.sql.session.Rows;
-import org.elasticsearch.xpack.sql.session.SchemaRowSet;
-import org.elasticsearch.xpack.sql.session.SqlSession;
-import org.elasticsearch.xpack.sql.tree.Source;
-import org.elasticsearch.xpack.sql.tree.NodeInfo;
-
-import java.util.Comparator;
-import java.util.List;
-
-import static java.util.Collections.singletonList;
-import static java.util.stream.Collectors.toList;
-
-/**
- * System command returning the types of tables supported,
- * index and alias.
- */
-public class SysTableTypes extends Command {
-
-    public SysTableTypes(Source source) {
-        super(source);
-    }
-
-    @Override
-    protected NodeInfo<SysTableTypes> info() {
-        return NodeInfo.create(this);
-    }
-
-    @Override
-    public List<Attribute> output() {
-        return singletonList(keyword("TABLE_TYPE"));
-    }
-
-    @Override
-    public final void execute(SqlSession session, ActionListener<SchemaRowSet> listener) {
-        listener.onResponse(Rows.of(output(), IndexType.VALID.stream()
-                // *DBC requires ascending order
-                .sorted(Comparator.comparing(t -> t.toSql()))
-                .map(t -> singletonList(t.toSql()))
-                .collect(toList())));
-    }
-
-    @Override
-    public int hashCode() {
-        return getClass().hashCode();
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-
-        if (obj == null || getClass() != obj.getClass()) {
-            return false;
-        }
-
-        return true;
-    }
-}

+ 0 - 61
x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/plan/logical/command/sys/SysCatalogsTests.java

@@ -1,61 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-package org.elasticsearch.xpack.sql.plan.logical.command.sys;
-
-import org.elasticsearch.action.ActionListener;
-import org.elasticsearch.common.collect.Tuple;
-import org.elasticsearch.test.ESTestCase;
-import org.elasticsearch.xpack.sql.TestUtils;
-import org.elasticsearch.xpack.sql.analysis.analyzer.Analyzer;
-import org.elasticsearch.xpack.sql.analysis.analyzer.Verifier;
-import org.elasticsearch.xpack.sql.analysis.index.EsIndex;
-import org.elasticsearch.xpack.sql.analysis.index.IndexResolution;
-import org.elasticsearch.xpack.sql.analysis.index.IndexResolver;
-import org.elasticsearch.xpack.sql.expression.function.FunctionRegistry;
-import org.elasticsearch.xpack.sql.parser.SqlParser;
-import org.elasticsearch.xpack.sql.plan.logical.command.Command;
-import org.elasticsearch.xpack.sql.session.SqlSession;
-import org.elasticsearch.xpack.sql.stats.Metrics;
-import org.elasticsearch.xpack.sql.type.TypesTests;
-
-import static java.util.Collections.singletonList;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class SysCatalogsTests extends ESTestCase {
-
-    private final SqlParser parser = new SqlParser();
-
-    @SuppressWarnings({ "rawtypes", "unchecked" })
-    private Tuple<Command, SqlSession> sql(String sql) {
-        EsIndex test = new EsIndex("test", TypesTests.loadMapping("mapping-multi-field-with-nested.json", true));
-        Analyzer analyzer = new Analyzer(TestUtils.TEST_CFG, new FunctionRegistry(), IndexResolution.valid(test),
-                                         new Verifier(new Metrics()));
-        Command cmd = (Command) analyzer.analyze(parser.createStatement(sql), true);
-
-        IndexResolver resolver = mock(IndexResolver.class);
-        when(resolver.clusterName()).thenReturn("cluster");
-
-        doAnswer(invocation -> {
-            ((ActionListener) invocation.getArguments()[2]).onResponse(singletonList(test));
-            return Void.TYPE;
-        }).when(resolver).resolveAsSeparateMappings(any(), any(), any());
-
-        SqlSession session = new SqlSession(null, null, null, resolver, null, null, null, null);
-        return new Tuple<>(cmd, session);
-    }
-
-    public void testSysCatalogs() throws Exception {
-        Tuple<Command, SqlSession> sql = sql("SYS CATALOGS");
-
-        sql.v1().execute(sql.v2(), ActionListener.wrap(r -> {
-            assertEquals(1, r.size());
-            assertEquals("cluster", r.column(0));
-        }, ex -> fail(ex.getMessage())));
-    }
-}

+ 0 - 52
x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/plan/logical/command/sys/SysTableTypesTests.java

@@ -1,52 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-package org.elasticsearch.xpack.sql.plan.logical.command.sys;
-
-import org.elasticsearch.action.ActionListener;
-import org.elasticsearch.common.collect.Tuple;
-import org.elasticsearch.test.ESTestCase;
-import org.elasticsearch.xpack.sql.TestUtils;
-import org.elasticsearch.xpack.sql.analysis.analyzer.Analyzer;
-import org.elasticsearch.xpack.sql.analysis.analyzer.Verifier;
-import org.elasticsearch.xpack.sql.analysis.index.EsIndex;
-import org.elasticsearch.xpack.sql.analysis.index.IndexResolution;
-import org.elasticsearch.xpack.sql.analysis.index.IndexResolver;
-import org.elasticsearch.xpack.sql.expression.function.FunctionRegistry;
-import org.elasticsearch.xpack.sql.parser.SqlParser;
-import org.elasticsearch.xpack.sql.plan.logical.command.Command;
-import org.elasticsearch.xpack.sql.session.SqlSession;
-import org.elasticsearch.xpack.sql.stats.Metrics;
-import org.elasticsearch.xpack.sql.type.TypesTests;
-
-import static org.mockito.Mockito.mock;
-
-public class SysTableTypesTests extends ESTestCase {
-
-    private final SqlParser parser = new SqlParser();
-
-    private Tuple<Command, SqlSession> sql(String sql) {
-        EsIndex test = new EsIndex("test", TypesTests.loadMapping("mapping-multi-field-with-nested.json", true));
-        Analyzer analyzer = new Analyzer(TestUtils.TEST_CFG, new FunctionRegistry(), IndexResolution.valid(test),
-                                         new Verifier(new Metrics()));
-        Command cmd = (Command) analyzer.analyze(parser.createStatement(sql), true);
-
-        IndexResolver resolver = mock(IndexResolver.class);
-        SqlSession session = new SqlSession(null, null, null, resolver, null, null, null, null);
-        return new Tuple<>(cmd, session);
-    }
-
-    public void testSysTableTypes() throws Exception {
-        Tuple<Command, SqlSession> sql = sql("SYS TABLE TYPES");
-
-        sql.v1().execute(sql.v2(), ActionListener.wrap(r -> {
-            assertEquals(2, r.size());
-            assertEquals("ALIAS", r.column(0));
-            assertTrue(r.advanceRow());
-            assertEquals("BASE TABLE", r.column(0));
-        }, ex -> fail(ex.getMessage())));
-    }
-
-}

+ 1 - 2
x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/stats/VerifierMetricsTests.java

@@ -93,8 +93,7 @@ public class VerifierMetricsTests extends ESTestCase {
     
     
     public void testCommand() {
     public void testCommand() {
         Counters c = sql(randomFrom("SHOW FUNCTIONS", "SHOW COLUMNS FROM library", "SHOW SCHEMAS",
         Counters c = sql(randomFrom("SHOW FUNCTIONS", "SHOW COLUMNS FROM library", "SHOW SCHEMAS",
-                                    "SHOW TABLES", "SYS CATALOGS", "SYS COLUMNS LIKE '%name'",
-                                    "SYS TABLES", "SYS TYPES"));
+                                    "SHOW TABLES", "SYS COLUMNS LIKE '%name'", "SYS TABLES", "SYS TYPES"));
         assertEquals(0, where(c));
         assertEquals(0, where(c));
         assertEquals(0, limit(c));
         assertEquals(0, limit(c));
         assertEquals(0, groupby(c));
         assertEquals(0, groupby(c));

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff