From 1b58f7d07fd4f002e57a0b7121d32a40e013a489 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Wed, 4 Jan 2023 09:27:14 -0800 Subject: [PATCH] Disallow unquoted literals in `LIKE` clause in `DESCRIBE` statement (#1181) * Allow quoted literals only in `DESCRIBE` and `SHOW` clauses. Tests. Signed-off-by: Yury-Fridlyand * Fix doctest after rebase. Signed-off-by: Yury-Fridlyand * Fix doctest after rebase. - Typo fix. Signed-off-by: Yury-Fridlyand * Update syntax section. Signed-off-by: Yury-Fridlyand Signed-off-by: Yury-Fridlyand Signed-off-by: Yury-Fridlyand --- docs/category.json | 3 +- docs/user/dql/metadata.rst | 120 ++++++++---------- docs/user/img/rdd/showFilter.png | Bin 6355 -> 0 bytes docs/user/img/rdd/showStatement.png | Bin 8542 -> 0 bytes .../java/org/opensearch/sql/sql/AdminIT.java | 44 +++++-- sql/src/main/antlr/OpenSearchSQLParser.g4 | 7 +- .../sql/sql/parser/AstExpressionBuilder.java | 6 +- .../sql/sql/antlr/SQLSyntaxParserTest.java | 33 +++++ .../sql/sql/parser/AstBuilderTest.java | 35 +---- 9 files changed, 129 insertions(+), 119 deletions(-) delete mode 100644 docs/user/img/rdd/showFilter.png delete mode 100644 docs/user/img/rdd/showStatement.png diff --git a/docs/category.json b/docs/category.json index b8feaa654a..e90c674a2e 100644 --- a/docs/category.json +++ b/docs/category.json @@ -46,6 +46,7 @@ "user/dql/window.rst", "user/beyond/partiql.rst", "user/dql/aggregations.rst", - "user/dql/complex.rst" + "user/dql/complex.rst", + "user/dql/metadata.rst" ] } diff --git a/docs/user/dql/metadata.rst b/docs/user/dql/metadata.rst index 7ffc2ffe38..5b34455974 100644 --- a/docs/user/dql/metadata.rst +++ b/docs/user/dql/metadata.rst @@ -21,13 +21,11 @@ You can query your indices metadata by ``SHOW`` and ``DESCRIBE`` statement. Thes Syntax ------ -Rule ``showStatement``: +``SHOW TABLES LIKE ""`` -.. image:: /docs/user/img/rdd/showStatement.png +``DESCRIBE TABLES LIKE "" [COLUMNS LIKE ""]`` -Rule ``showFilter``: - -.. image:: /docs/user/img/rdd/showFilter.png +Pattern accepts SQL style wildcards where `_` mathes any character and `%` matches any characters. Example 1: Show All Indices Information --------------------------------------- @@ -36,21 +34,19 @@ Example 1: Show All Indices Information SQL query:: - POST /_plugins/_sql - { - "query" : "SHOW TABLES LIKE %" - } - -Result set: - -+---------+-----------+----------------+----------+-------+--------+----------+---------+-------------------------+--------------+ -|TABLE_CAT|TABLE_SCHEM| TABLE_NAME|TABLE_TYPE|REMARKS|TYPE_CAT|TYPE_SCHEM|TYPE_NAME|SELF_REFERENCING_COL_NAME|REF_GENERATION| -+=========+===========+================+==========+=======+========+==========+=========+=========================+==============+ -|integTest| null| accounts|BASE TABLE| null| null| null| null| null| null| -+---------+-----------+----------------+----------+-------+--------+----------+---------+-------------------------+--------------+ -|integTest| null|employees_nested|BASE TABLE| null| null| null| null| null| null| -+---------+-----------+----------------+----------+-------+--------+----------+---------+-------------------------+--------------+ - + os> SHOW TABLES LIKE '%' + fetched rows / total rows = 7/7 + +----------------+---------------+--------------+--------------+-----------+------------+--------------+-------------+-----------------------------+------------------+ + | TABLE_CAT | TABLE_SCHEM | TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_CAT | TYPE_SCHEM | TYPE_NAME | SELF_REFERENCING_COL_NAME | REF_GENERATION | + |----------------+---------------+--------------+--------------+-----------+------------+--------------+-------------+-----------------------------+------------------| + | docTestCluster | null | account2 | BASE TABLE | null | null | null | null | null | null | + | docTestCluster | null | accounts | BASE TABLE | null | null | null | null | null | null | + | docTestCluster | null | apache | BASE TABLE | null | null | null | null | null | null | + | docTestCluster | null | books | BASE TABLE | null | null | null | null | null | null | + | docTestCluster | null | nyc_taxi | BASE TABLE | null | null | null | null | null | null | + | docTestCluster | null | people | BASE TABLE | null | null | null | null | null | null | + | docTestCluster | null | wildcard | BASE TABLE | null | null | null | null | null | null | + +----------------+---------------+--------------+--------------+-----------+------------+--------------+-------------+-----------------------------+------------------+ Example 2: Show Specific Index Information ------------------------------------------ @@ -59,19 +55,14 @@ Here is an example that searches metadata for index name prefixed by 'acc'. Besi SQL query:: - POST /_plugins/_sql - { - "query" : "SHOW TABLES LIKE acc%" - } - -Result set: - -+---------+-----------+----------+----------+-------+--------+----------+---------+-------------------------+--------------+ -|TABLE_CAT|TABLE_SCHEM|TABLE_NAME|TABLE_TYPE|REMARKS|TYPE_CAT|TYPE_SCHEM|TYPE_NAME|SELF_REFERENCING_COL_NAME|REF_GENERATION| -+=========+===========+==========+==========+=======+========+==========+=========+=========================+==============+ -|integTest| null| accounts|BASE TABLE| null| null| null| null| null| null| -+---------+-----------+----------+----------+-------+--------+----------+---------+-------------------------+--------------+ - + os> SHOW TABLES LIKE "acc%" + fetched rows / total rows = 2/2 + +----------------+---------------+--------------+--------------+-----------+------------+--------------+-------------+-----------------------------+------------------+ + | TABLE_CAT | TABLE_SCHEM | TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_CAT | TYPE_SCHEM | TYPE_NAME | SELF_REFERENCING_COL_NAME | REF_GENERATION | + |----------------+---------------+--------------+--------------+-----------+------------+--------------+-------------+-----------------------------+------------------| + | docTestCluster | null | account2 | BASE TABLE | null | null | null | null | null | null | + | docTestCluster | null | accounts | BASE TABLE | null | null | null | null | null | null | + +----------------+---------------+--------------+--------------+-----------+------------+--------------+-------------+-----------------------------+------------------+ Example 3: Describe Index Fields Information -------------------------------------------- @@ -80,37 +71,36 @@ Example 3: Describe Index Fields Information SQL query:: - POST /_plugins/_sql - { - "query" : "DESCRIBE TABLES LIKE accounts" - } - -Result set: - -+---------+-----------+----------+--------------+---------+---------+-----------+-------------+--------------+--------------+--------+-------+----------+-------------+----------------+-----------------+----------------+-----------+-------------+------------+-----------+----------------+----------------+------------------+ -|TABLE_CAT|TABLE_SCHEM|TABLE_NAME| COLUMN_NAME|DATA_TYPE|TYPE_NAME|COLUMN_SIZE|BUFFER_LENGTH|DECIMAL_DIGITS|NUM_PREC_RADIX|NULLABLE|REMARKS|COLUMN_DEF|SQL_DATA_TYPE|SQL_DATETIME_SUB|CHAR_OCTET_LENGTH|ORDINAL_POSITION|IS_NULLABLE|SCOPE_CATALOG|SCOPE_SCHEMA|SCOPE_TABLE|SOURCE_DATA_TYPE|IS_AUTOINCREMENT|IS_GENERATEDCOLUMN| -+=========+===========+==========+==============+=========+=========+===========+=============+==============+==============+========+=======+==========+=============+================+=================+================+===========+=============+============+===========+================+================+==================+ -|integTest| null| accounts|account_number| null| long| null| null| null| 10| 2| null| null| null| null| null| 1| | null| null| null| null| NO| | -+---------+-----------+----------+--------------+---------+---------+-----------+-------------+--------------+--------------+--------+-------+----------+-------------+----------------+-----------------+----------------+-----------+-------------+------------+-----------+----------------+----------------+------------------+ -|integTest| null| accounts| firstname| null| text| null| null| null| 10| 2| null| null| null| null| null| 2| | null| null| null| null| NO| | -+---------+-----------+----------+--------------+---------+---------+-----------+-------------+--------------+--------------+--------+-------+----------+-------------+----------------+-----------------+----------------+-----------+-------------+------------+-----------+----------------+----------------+------------------+ -|integTest| null| accounts| address| null| text| null| null| null| 10| 2| null| null| null| null| null| 3| | null| null| null| null| NO| | -+---------+-----------+----------+--------------+---------+---------+-----------+-------------+--------------+--------------+--------+-------+----------+-------------+----------------+-----------------+----------------+-----------+-------------+------------+-----------+----------------+----------------+------------------+ -|integTest| null| accounts| balance| null| long| null| null| null| 10| 2| null| null| null| null| null| 4| | null| null| null| null| NO| | -+---------+-----------+----------+--------------+---------+---------+-----------+-------------+--------------+--------------+--------+-------+----------+-------------+----------------+-----------------+----------------+-----------+-------------+------------+-----------+----------------+----------------+------------------+ -|integTest| null| accounts| gender| null| text| null| null| null| 10| 2| null| null| null| null| null| 5| | null| null| null| null| NO| | -+---------+-----------+----------+--------------+---------+---------+-----------+-------------+--------------+--------------+--------+-------+----------+-------------+----------------+-----------------+----------------+-----------+-------------+------------+-----------+----------------+----------------+------------------+ -|integTest| null| accounts| city| null| text| null| null| null| 10| 2| null| null| null| null| null| 6| | null| null| null| null| NO| | -+---------+-----------+----------+--------------+---------+---------+-----------+-------------+--------------+--------------+--------+-------+----------+-------------+----------------+-----------------+----------------+-----------+-------------+------------+-----------+----------------+----------------+------------------+ -|integTest| null| accounts| employer| null| text| null| null| null| 10| 2| null| null| null| null| null| 7| | null| null| null| null| NO| | -+---------+-----------+----------+--------------+---------+---------+-----------+-------------+--------------+--------------+--------+-------+----------+-------------+----------------+-----------------+----------------+-----------+-------------+------------+-----------+----------------+----------------+------------------+ -|integTest| null| accounts| state| null| text| null| null| null| 10| 2| null| null| null| null| null| 8| | null| null| null| null| NO| | -+---------+-----------+----------+--------------+---------+---------+-----------+-------------+--------------+--------------+--------+-------+----------+-------------+----------------+-----------------+----------------+-----------+-------------+------------+-----------+----------------+----------------+------------------+ -|integTest| null| accounts| age| null| long| null| null| null| 10| 2| null| null| null| null| null| 9| | null| null| null| null| NO| | -+---------+-----------+----------+--------------+---------+---------+-----------+-------------+--------------+--------------+--------+-------+----------+-------------+----------------+-----------------+----------------+-----------+-------------+------------+-----------+----------------+----------------+------------------+ -|integTest| null| accounts| email| null| text| null| null| null| 10| 2| null| null| null| null| null| 10| | null| null| null| null| NO| | -+---------+-----------+----------+--------------+---------+---------+-----------+-------------+--------------+--------------+--------+-------+----------+-------------+----------------+-----------------+----------------+-----------+-------------+------------+-----------+----------------+----------------+------------------+ -|integTest| null| accounts| lastname| null| text| null| null| null| 10| 2| null| null| null| null| null| 11| | null| null| null| null| NO| | -+---------+-----------+----------+--------------+---------+---------+-----------+-------------+--------------+--------------+--------+-------+----------+-------------+----------------+-----------------+----------------+-----------+-------------+------------+-----------+----------------+----------------+------------------+ + os> DESCRIBE TABLES LIKE 'accounts' + fetched rows / total rows = 11/11 + +----------------+---------------+--------------+----------------+-------------+-------------+---------------+-----------------+------------------+------------------+------------+-----------+--------------+-----------------+--------------------+---------------------+--------------------+---------------+-----------------+----------------+---------------+--------------------+--------------------+----------------------+ + | TABLE_CAT | TABLE_SCHEM | TABLE_NAME | COLUMN_NAME | DATA_TYPE | TYPE_NAME | COLUMN_SIZE | BUFFER_LENGTH | DECIMAL_DIGITS | NUM_PREC_RADIX | NULLABLE | REMARKS | COLUMN_DEF | SQL_DATA_TYPE | SQL_DATETIME_SUB | CHAR_OCTET_LENGTH | ORDINAL_POSITION | IS_NULLABLE | SCOPE_CATALOG | SCOPE_SCHEMA | SCOPE_TABLE | SOURCE_DATA_TYPE | IS_AUTOINCREMENT | IS_GENERATEDCOLUMN | + |----------------+---------------+--------------+----------------+-------------+-------------+---------------+-----------------+------------------+------------------+------------+-----------+--------------+-----------------+--------------------+---------------------+--------------------+---------------+-----------------+----------------+---------------+--------------------+--------------------+----------------------| + | docTestCluster | null | accounts | account_number | null | long | null | null | null | 10 | 2 | null | null | null | null | null | 0 | | null | null | null | null | NO | | + | docTestCluster | null | accounts | firstname | null | text | null | null | null | 10 | 2 | null | null | null | null | null | 1 | | null | null | null | null | NO | | + | docTestCluster | null | accounts | address | null | text | null | null | null | 10 | 2 | null | null | null | null | null | 2 | | null | null | null | null | NO | | + | docTestCluster | null | accounts | balance | null | long | null | null | null | 10 | 2 | null | null | null | null | null | 3 | | null | null | null | null | NO | | + | docTestCluster | null | accounts | gender | null | text | null | null | null | 10 | 2 | null | null | null | null | null | 4 | | null | null | null | null | NO | | + | docTestCluster | null | accounts | city | null | text | null | null | null | 10 | 2 | null | null | null | null | null | 5 | | null | null | null | null | NO | | + | docTestCluster | null | accounts | employer | null | text | null | null | null | 10 | 2 | null | null | null | null | null | 6 | | null | null | null | null | NO | | + | docTestCluster | null | accounts | state | null | text | null | null | null | 10 | 2 | null | null | null | null | null | 7 | | null | null | null | null | NO | | + | docTestCluster | null | accounts | age | null | long | null | null | null | 10 | 2 | null | null | null | null | null | 8 | | null | null | null | null | NO | | + | docTestCluster | null | accounts | email | null | text | null | null | null | 10 | 2 | null | null | null | null | null | 9 | | null | null | null | null | NO | | + | docTestCluster | null | accounts | lastname | null | text | null | null | null | 10 | 2 | null | null | null | null | null | 10 | | null | null | null | null | NO | | + +----------------+---------------+--------------+----------------+-------------+-------------+---------------+-----------------+------------------+------------------+------------+-----------+--------------+-----------------+--------------------+---------------------+--------------------+---------------+-----------------+----------------+---------------+--------------------+--------------------+----------------------+ + +Example 4: Describe Index With Fields Filter +-------------------------------------------- +``DESCRIBE`` statement fields that can match the search pattern for indices that can match the search pattern. + +SQL query:: + os> DESCRIBE TABLES LIKE "accounts" COLUMNS LIKE "%name" + fetched rows / total rows = 2/2 + +----------------+---------------+--------------+---------------+-------------+-------------+---------------+-----------------+------------------+------------------+------------+-----------+--------------+-----------------+--------------------+---------------------+--------------------+---------------+-----------------+----------------+---------------+--------------------+--------------------+----------------------+ + | TABLE_CAT | TABLE_SCHEM | TABLE_NAME | COLUMN_NAME | DATA_TYPE | TYPE_NAME | COLUMN_SIZE | BUFFER_LENGTH | DECIMAL_DIGITS | NUM_PREC_RADIX | NULLABLE | REMARKS | COLUMN_DEF | SQL_DATA_TYPE | SQL_DATETIME_SUB | CHAR_OCTET_LENGTH | ORDINAL_POSITION | IS_NULLABLE | SCOPE_CATALOG | SCOPE_SCHEMA | SCOPE_TABLE | SOURCE_DATA_TYPE | IS_AUTOINCREMENT | IS_GENERATEDCOLUMN | + |----------------+---------------+--------------+---------------+-------------+-------------+---------------+-----------------+------------------+------------------+------------+-----------+--------------+-----------------+--------------------+---------------------+--------------------+---------------+-----------------+----------------+---------------+--------------------+--------------------+----------------------| + | docTestCluster | null | accounts | firstname | null | text | null | null | null | 10 | 2 | null | null | null | null | null | 1 | | null | null | null | null | NO | | + | docTestCluster | null | accounts | lastname | null | text | null | null | null | 10 | 2 | null | null | null | null | null | 10 | | null | null | null | null | NO | | + +----------------+---------------+--------------+---------------+-------------+-------------+---------------+-----------------+------------------+------------------+------------+-----------+--------------+-----------------+--------------------+---------------------+--------------------+---------------+-----------------+----------------+---------------+--------------------+--------------------+----------------------+ diff --git a/docs/user/img/rdd/showFilter.png b/docs/user/img/rdd/showFilter.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d;s_8#o019G*X9Mjz_YEeIKFtIZeKMd&1z373+qnu~uc_rj%$^!SXpn{?`Hye>acCiJg#!;#yech4q_%@pdLYu>s%32b@R8kooar|KQ-Lq2ay@ zaguFY@NUdl2%q%sS55L?h<=2dYyHlWzfE%y5A{YLDc~PnmL;0`(?4_L$~5~iO=mYH zg4VK$dS0zovXt>{h^(xv{gKZcbX!wSzJn4qp<*2E=D?PwlFZ2tz!7~VSgJc^=Ff}* zKYhF0<;?X0CF4hZ>N;An%UdP&HnLvTCV5N^Ph=5X+ZcmSgl*|J2e+c<4w>SHPo|u7 z2+ZLf_FD|HiGQq$0w5U)6XyrpI~ zdziKNq~G}pCbPt$PT%{qQ8Nff&)Z21h$UomzoVtZnUG!ZT(=8p-s&CMms9~0+HE7# z?nCc?$(@!#G`}M3SLXY^g1zAQmGM)y)#$>`S!?UeU;OkAGGXs00YpgJ-2i}j(APlL|5Cw`t$a<>8lh9st_i6zV zU?iH9z=j5zuF`m{b6a0{`)Bgp_3s9gS6WLyL7jev_zJzZWdZ;evI+=vaI^9c$w{R$ zF;?Q$rW6$1cmm<(E* zr>N)j&{Vd3*{lr;6PcZM`p0Qb5D|=pO$q_2{^8cz!$M(Bb-@;|%?`QnC>ce~Er|k4 z<>sB^?~?bCqhE!2(s&MGIzNW@2@L)wId2~^V2x@%jOPCfgrtH&qHDpWJnaS_JaqT~ z{~7JKh>lFVcE;_X;SIKPGS$uhAc^MSx{RPt;lHy0fIzuZ0bNmLhn2u#>4$wvBJafM z|6i4d_FGH&zW15S>kxnNL%r1@V75=%Kl assertThrows(SyntaxCheckException.class, + () -> parser.parse("DESCRIBE TABLES LIKE bank")), + () -> assertThrows(SyntaxCheckException.class, + () -> parser.parse("DESCRIBE TABLES LIKE %bank%")), + () -> assertThrows(SyntaxCheckException.class, + () -> parser.parse("DESCRIBE TABLES LIKE `bank`")), + () -> assertThrows(SyntaxCheckException.class, + () -> parser.parse("DESCRIBE TABLES LIKE %bank% COLUMNS LIKE %status%")), + () -> assertThrows(SyntaxCheckException.class, + () -> parser.parse("DESCRIBE TABLES LIKE 'bank' COLUMNS LIKE status")), + () -> assertNotNull(parser.parse("DESCRIBE TABLES LIKE 'bank' COLUMNS LIKE \"status\"")), + () -> assertNotNull(parser.parse("DESCRIBE TABLES LIKE \"bank\" COLUMNS LIKE 'status'")) + ); + } + + @Test + public void show_request_accepts_only_quoted_string_literals() { + assertAll( + () -> assertThrows(SyntaxCheckException.class, + () -> parser.parse("SHOW TABLES LIKE bank")), + () -> assertThrows(SyntaxCheckException.class, + () -> parser.parse("SHOW TABLES LIKE %bank%")), + () -> assertThrows(SyntaxCheckException.class, + () -> parser.parse("SHOW TABLES LIKE `bank`")), + () -> assertNotNull(parser.parse("SHOW TABLES LIKE 'bank'")), + () -> assertNotNull(parser.parse("SHOW TABLES LIKE \"bank\"")) + ); + } + @ParameterizedTest @MethodSource({ "matchPhraseComplexQueries", diff --git a/sql/src/test/java/org/opensearch/sql/sql/parser/AstBuilderTest.java b/sql/src/test/java/org/opensearch/sql/sql/parser/AstBuilderTest.java index fafb143291..64a7445dc8 100644 --- a/sql/src/test/java/org/opensearch/sql/sql/parser/AstBuilderTest.java +++ b/sql/src/test/java/org/opensearch/sql/sql/parser/AstBuilderTest.java @@ -567,10 +567,6 @@ public void can_build_show_selected_tables() { ); } - /** - * Todo, ideally the identifier (%) couldn't be used in LIKE operator, only the string literal - * is allowed. - */ @Test public void show_compatible_with_old_engine_syntax() { assertEquals( @@ -581,18 +577,7 @@ public void show_compatible_with_old_engine_syntax() { ), AllFields.of() ), - buildAST("SHOW TABLES LIKE %") - ); - } - - @Test - public void describe_compatible_with_old_engine_syntax() { - assertEquals( - project( - relation(mappingTable("a_c%")), - AllFields.of() - ), - buildAST("DESCRIBE TABLES LIKE a_c%") + buildAST("SHOW TABLES LIKE '%'") ); } @@ -621,24 +606,6 @@ public void can_build_describe_selected_tables_field_filter() { ); } - /** - * Todo, ideally the identifier (%) couldn't be used in LIKE operator, only the string literal - * is allowed. - */ - @Test - public void describe_and_column_compatible_with_old_engine_syntax() { - assertEquals( - project( - filter( - relation(mappingTable("a_c%")), - function("like", qualifiedName("COLUMN_NAME"), stringLiteral("name%")) - ), - AllFields.of() - ), - buildAST("DESCRIBE TABLES LIKE a_c% COLUMNS LIKE name%") - ); - } - @Test public void can_build_alias_by_keywords() { assertEquals(