diff --git a/docs/source/reference/evaql/create.rst b/docs/source/reference/evaql/create.rst index bc64c3aa8..de1545a31 100644 --- a/docs/source/reference/evaql/create.rst +++ b/docs/source/reference/evaql/create.rst @@ -35,19 +35,57 @@ Examples CREATE TABLE ------------ -To create a table, specify the schema of the table. +To create a table, we can specify the schema of the table. + +.. code-block:: + + CREATE TABLE [IF NOT EXISTS] table_name ( [ + column_name data_type + [, ... ] + ] ); + +Blew is an example: .. code:: mysql CREATE TABLE IF NOT EXISTS MyCSV ( - id INTEGER UNIQUE, - frame_id INTEGER, - video_id INTEGER, - dataset_name TEXT(30), - label TEXT(30), - bbox NDARRAY FLOAT32(4), - object_id INTEGER - ); + id INTEGER UNIQUE, + frame_id INTEGER, + video_id INTEGER, + dataset_name TEXT, + label TEXT, + bbox NDARRAY FLOAT32(4), + object_id INTEGER + ); + +Below are all supported column types: + +* INTEGER +* TEXT +* FLOAT +* NDARRAY +* BOOLEAN + +.. note:: + + Check `NdArrayType `_ for available NDARRAY types. + +We can also create table from the output of a ``SELECT`` query. + +.. code-block:: + + CREATE TABLE [IF NOT EXISTS] table_name + AS select_query + +Below is an example: + +.. code-block:: sql + + CREATE TABLE UADETRAC_FastRCNN AS + SELECT id, FastRCNNObjectDetector(frame).labels + FROM UADETRAC + WHERE id<5; + <<<<<<< HEAD CREATE INDEX @@ -187,14 +225,3 @@ Where the `parameter` is ``key value`` pair. >>>>>>> 40a10ce1 (Bump v0.3.4+ dev) >>>>>>> eva-master -CREATE MATERIALIZED VIEW ------------------------- - -To create a view with materialized results -- like the outputs of deep learning model, use the following template: - -.. code-block:: sql - - CREATE MATERIALIZED VIEW UADETRAC_FastRCNN (id, labels) AS - SELECT id, FastRCNNObjectDetector(frame).labels - FROM UADETRAC - WHERE id<5; diff --git a/docs/source/shared/postgresql.rst b/docs/source/shared/postgresql.rst index 364e866f1..802cb23c6 100644 --- a/docs/source/shared/postgresql.rst +++ b/docs/source/shared/postgresql.rst @@ -5,12 +5,16 @@ We will assume that you have a ``PostgreSQL`` database server running locally th EvaDB lets you connect to your favorite databases, data warehouses, data lakes, etc., via the ``CREATE DATABASE`` statement. In this query, we connect EvaDB to an existing ``PostgreSQL`` server: +<<<<<<< HEAD <<<<<<< HEAD ======= <<<<<<< HEAD <<<<<<< HEAD >>>>>>> eva-master .. code-block:: text +======= +.. code-block:: +>>>>>>> aeb9a3be (Remove dimensions from `TEXT` and `FLOAT` (#1261)) CREATE DATABASE postgres_data WITH ENGINE = 'postgres', diff --git a/evadb/parser/lark_visitor/_create_statements.py b/evadb/parser/lark_visitor/_create_statements.py index 644667413..3d76019b8 100644 --- a/evadb/parser/lark_visitor/_create_statements.py +++ b/evadb/parser/lark_visitor/_create_statements.py @@ -155,9 +155,10 @@ def dimension_data_type(self, tree): token = tree.children[0] if str.upper(token) == "FLOAT": data_type = ColumnType.FLOAT - dimensions = self.visit(tree.children[1]) elif str.upper(token) == "TEXT": data_type = ColumnType.TEXT + + if len(tree.children) > 1: dimensions = self.visit(tree.children[1]) return data_type, array_type, dimensions diff --git a/test/unit_tests/parser/test_parser.py b/test/unit_tests/parser/test_parser.py index 371e611d0..be4771218 100644 --- a/test/unit_tests/parser/test_parser.py +++ b/test/unit_tests/parser/test_parser.py @@ -244,6 +244,51 @@ def test_explain_ddl_statement(self): def test_create_table_statement(self): parser = Parser() + single_queries = [] + single_queries.append( + """CREATE TABLE IF NOT EXISTS Persons ( + Frame_ID INTEGER UNIQUE, + Frame_Data TEXT, + Frame_Value FLOAT, + Frame_Array NDARRAY UINT8(5, 100, 2432, 4324, 100) + );""" + ) + + expected_cci = ColConstraintInfo() + expected_cci.nullable = True + unique_cci = ColConstraintInfo() + unique_cci.unique = True + unique_cci.nullable = False + expected_stmt = CreateTableStatement( + TableInfo("Persons"), + True, + [ + ColumnDefinition("Frame_ID", ColumnType.INTEGER, None, (), unique_cci), + ColumnDefinition("Frame_Data", ColumnType.TEXT, None, (), expected_cci), + ColumnDefinition( + "Frame_Value", ColumnType.FLOAT, None, (), expected_cci + ), + ColumnDefinition( + "Frame_Array", + ColumnType.NDARRAY, + NdArrayType.UINT8, + (5, 100, 2432, 4324, 100), + expected_cci, + ), + ], + ) + + for query in single_queries: + evadb_statement_list = parser.parse(query) + self.assertIsInstance(evadb_statement_list, list) + self.assertEqual(len(evadb_statement_list), 1) + self.assertIsInstance(evadb_statement_list[0], AbstractStatement) + self.assertEqual(evadb_statement_list[0], expected_stmt) + + def test_create_table_with_dimension_statement(self): + # The test is for backwards compatibility + parser = Parser() + single_queries = [] single_queries.append( """CREATE TABLE IF NOT EXISTS Persons (