Skip to content

Commit

Permalink
Remove dimensions from TEXT and FLOAT (georgia-tech-db#1261)
Browse files Browse the repository at this point in the history
Users can now create a table with just `FLOAT` without providing the
dimensions.

Earlier:
```sql
CREATE TABLE ETTM1 (
        date TEXT(30),
        hufl FLOAT(5,7),
        hull FLOAT(5,7),
        mufl FLOAT(5,7),
        mull FLOAT(5,7),
        lufl FLOAT(5,7),
        lull FLOAT(5,7),
        ot FLOAT(5,7));
```

Now:
```sql
CREATE TABLE ETTM1 (
        date TEXT,
        hufl FLOAT,
        hull FLOAT,
        mufl FLOAT,
        mull FLOAT,
        lufl FLOAT,
        lull FLOAT,
        ot FLOAT);
```

Fixes georgia-tech-db#1260.

---------

Co-authored-by: Andy Xu <[email protected]>
  • Loading branch information
2 people authored and a0x8o committed Oct 30, 2023
1 parent 173efea commit 6351098
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 21 deletions.
67 changes: 47 additions & 20 deletions docs/source/reference/evaql/create.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/georgia-tech-db/evadb/blob/staging/evadb/catalog/catalog_type.py>`_ 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
Expand Down Expand Up @@ -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;
4 changes: 4 additions & 0 deletions docs/source/shared/postgresql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion evadb/parser/lark_visitor/_create_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions test/unit_tests/parser/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 6351098

Please sign in to comment.