-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sean Kao <[email protected]>
- Loading branch information
1 parent
8523ad8
commit 9e2a9ff
Showing
10 changed files
with
255 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
============= | ||
describe | ||
============= | ||
|
||
.. rubric:: Table of contents | ||
|
||
.. contents:: | ||
:local: | ||
:depth: 2 | ||
|
||
|
||
Description | ||
============ | ||
| Using ``describe`` command to query metadata of the index. ``describe`` command could be only used as the first command in the PPL query. | ||
|
||
Syntax | ||
============ | ||
describe <index> | ||
|
||
* index: mandatory. describe command must specify which index to query from. | ||
|
||
|
||
Example 1: Fetch all the metadata | ||
================================= | ||
|
||
The example describes accounts index. | ||
|
||
PPL query:: | ||
|
||
os> describe 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 2: Fetch metadata with condition and filter | ||
=================================================== | ||
|
||
The example retrieves columns with type long in accounts index. | ||
|
||
PPL query:: | ||
|
||
os> describe accounts | where TYPE_NAME="long" | fields COLUMN_NAME; | ||
fetched rows / total rows = 3/3 | ||
+----------------+ | ||
| COLUMN_NAME | | ||
|----------------| | ||
| account_number | | ||
| balance | | ||
| age | | ||
+----------------+ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
integ-test/src/test/java/org/opensearch/sql/ppl/DescribeCommandIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
|
||
package org.opensearch.sql.ppl; | ||
|
||
import org.json.JSONObject; | ||
import org.junit.jupiter.api.Test; | ||
import org.opensearch.client.Request; | ||
import org.opensearch.client.ResponseException; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DOG; | ||
import static org.opensearch.sql.util.MatcherUtils.columnName; | ||
import static org.opensearch.sql.util.MatcherUtils.verifyColumn; | ||
import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; | ||
|
||
public class DescribeCommandIT extends PPLIntegTestCase { | ||
|
||
@Override | ||
public void init() throws IOException { | ||
loadIndex(Index.DOG); | ||
} | ||
|
||
@Test | ||
public void testDescribeAllFields() throws IOException { | ||
JSONObject result = executeQuery(String.format("describe %s", TEST_INDEX_DOG)); | ||
verifyColumn( | ||
result, | ||
columnName("TABLE_CAT"), | ||
columnName("TABLE_SCHEM"), | ||
columnName("TABLE_NAME"), | ||
columnName("COLUMN_NAME"), | ||
columnName("DATA_TYPE"), | ||
columnName("TYPE_NAME"), | ||
columnName("COLUMN_SIZE"), | ||
columnName("BUFFER_LENGTH"), | ||
columnName("DECIMAL_DIGITS"), | ||
columnName("NUM_PREC_RADIX"), | ||
columnName("NULLABLE"), | ||
columnName("REMARKS"), | ||
columnName("COLUMN_DEF"), | ||
columnName("SQL_DATA_TYPE"), | ||
columnName("SQL_DATETIME_SUB"), | ||
columnName("CHAR_OCTET_LENGTH"), | ||
columnName("ORDINAL_POSITION"), | ||
columnName("IS_NULLABLE"), | ||
columnName("SCOPE_CATALOG"), | ||
columnName("SCOPE_SCHEMA"), | ||
columnName("SCOPE_TABLE"), | ||
columnName("SOURCE_DATA_TYPE"), | ||
columnName("IS_AUTOINCREMENT"), | ||
columnName("IS_GENERATEDCOLUMN") | ||
); | ||
} | ||
|
||
@Test | ||
public void testDescribeFilterFields() throws IOException { | ||
JSONObject result = executeQuery(String.format("describe %s | fields TABLE_NAME, COLUMN_NAME, TYPE_NAME", TEST_INDEX_DOG)); | ||
verifyColumn( | ||
result, | ||
columnName("TABLE_NAME"), | ||
columnName("COLUMN_NAME"), | ||
columnName("TYPE_NAME") | ||
); | ||
} | ||
|
||
@Test | ||
public void testDescribeWithSpecialIndexName() throws IOException { | ||
executeRequest(new Request("PUT", "/logs-2021.01.11")); | ||
verifyDataRows(executeQuery("describe logs-2021.01.11")); | ||
|
||
executeRequest(new Request("PUT", "/logs-7.10.0-2021.01.11")); | ||
verifyDataRows(executeQuery("describe logs-7.10.0-2021.01.11")); | ||
} | ||
|
||
@Test | ||
public void describeCommandWithoutIndexShouldFailToParse() throws IOException { | ||
try { | ||
executeQuery("describe"); | ||
fail(); | ||
} catch (ResponseException e) { | ||
assertTrue(e.getMessage().contains("RuntimeException")); | ||
assertTrue(e.getMessage().contains("Failed to parse query due to offending symbol")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.