Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dimensions from TEXT and FLOAT #1261

Merged
merged 8 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;


CREATE INDEX
------------
Expand Down Expand Up @@ -119,14 +157,3 @@ Where the `parameter` is ``key value`` pair.

Go over :ref:`hf`, :ref:`ludwig`, and :ref:`forecast` to check examples for creating function via type.

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;
2 changes: 1 addition & 1 deletion docs/source/shared/postgresql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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:

.. code-block:: text
.. code-block::

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 @@ -225,6 +225,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