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

FEAT: [OmnisciDB] Support add_columns and drop_columns for OmnisciDB table #2094

Merged
merged 53 commits into from
Mar 24, 2020

Conversation

YarShev
Copy link
Contributor

@YarShev YarShev commented Feb 25, 2020

No description provided.

@pep8speaks
Copy link

pep8speaks commented Feb 25, 2020

Hello @YarShev! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-03-24 18:30:42 UTC

@anmyachev
Copy link
Contributor

@YarShev please fix docstrings

@YarShev
Copy link
Contributor Author

YarShev commented Feb 26, 2020

@YarShev please fix docstrings

thanks, fixed

-------
string
"""
unsupported_types = ['POINT',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why these types are unsupported? Omnisci supports geo functions and types, there are tests for them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read it at the Omnisci documentation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found it in examples from doc page
ALTER TABLE t ADD COLUMN pt_dropoff POINT DEFAULT 'point(0 0)';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clause 'Note' say that "Currently, OmniSci does not support adding a geo column type (POINT, LINESTRING, POLYGON, or MULTIPOLYGON) to a table"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, didn't notice

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked it, it is working fine on omnisci master branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then may delete it, thanks

@@ -905,6 +905,44 @@ def drop_table(self, table_name, database=None, force=False):
self._execute(statement, False)
self.set_database(_database)

def add_column(self, table_name, column_name, data_type):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is possible to add several columns at a time through giving a list of column names and a list of data types. How do you like it? Can you implement it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be implemented, but I think it's enough.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will allow getting more performance because we will send and execute one query while adding several columns. It's not so difficult to do so I suggest doing it. It's up to you.

Copy link
Contributor Author

@YarShev YarShev Feb 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will implement method for some columns.

@anmyachev
Copy link
Contributor

@YarShev do make develop to avoiding code style issues

Examples
--------
>>> table_name = 'my_table'
>>> columns_with_types = my_column_1 = 'INTEGER',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems this line is raising an error on doctest tests.
maybe you could use a dictionary here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

problem was relating to writing multiple lines.

ibis/omniscidb/ddl.py Outdated Show resolved Hide resolved
Copy link
Contributor

@xmnlab xmnlab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YarShev thanks for working on that!

I just added some comments here. thanks!

ibis/omniscidb/ddl.py Outdated Show resolved Hide resolved
ibis/omniscidb/ddl.py Outdated Show resolved Hide resolved
@@ -100,6 +100,53 @@ def test_union_op(alltypes):
expr.compile()


def test_add_column(con):
table_name = 'my_table'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add test for:

  • 0 field
  • 1 field (done)
  • 2 or more fields (with different types)

thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YarShev thanks for adding more parameters for the tests here!

I think you could to refactor a little bit your code here. you can try something like this:

@pytest.mark.parametrize(
    'cols_with_types',
    [
        {},
        {'c': 'double'},
        {'c': 'double', 'd': 'string', 'e': 'point', 'f': 'polygon', 'g': 'int16'},
    ],
)
def test_add_column(con, new_cols):
    table_name = 'my_table'
    con.drop_table(table_name, force=True)

    schema = ibis.schema([('a', 'float'), ('b', 'int8')])

    con.create_table(table_name, schema=schema)

    if len(new_cols) == 0:
        with pytest.raises(IbisInputError):
            con.add_column(table_name, cols_with_types)
        return con.drop_table(table_name)

    con.add_column(table_name, new_cols)

    schema_new_cols = ibis.schema(new_cols.items())
    schema_new = schema.append(schema_new_cols)

    try:
        t = con.table(table_name)
        assert schema == schema_new
    finally:
        con.drop_table(table_name)

note: probably for ddl we should use the same type names used by ibis expressions .. not the ones directly used by omniscidb. it could be a little bit confusing . I have a WIP PR that I was adding the add_columns op too. As you are working on that I will just remove that from my code ... but for now you can take a look how I was treating the datatypes there: #2086


con.create_table(table_name, schema=schema)

dict_cols_with_types = {'c': 'DOUBLE', 'd': 'TEXT'}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to test adding columns with more types, at least one with geo type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@xmnlab xmnlab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YarShev thanks! it seems it is almost ready :) I added some more comments. thanks again!

@@ -100,6 +100,53 @@ def test_union_op(alltypes):
expr.compile()


def test_add_column(con):
table_name = 'my_table'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YarShev thanks for adding more parameters for the tests here!

I think you could to refactor a little bit your code here. you can try something like this:

@pytest.mark.parametrize(
    'cols_with_types',
    [
        {},
        {'c': 'double'},
        {'c': 'double', 'd': 'string', 'e': 'point', 'f': 'polygon', 'g': 'int16'},
    ],
)
def test_add_column(con, new_cols):
    table_name = 'my_table'
    con.drop_table(table_name, force=True)

    schema = ibis.schema([('a', 'float'), ('b', 'int8')])

    con.create_table(table_name, schema=schema)

    if len(new_cols) == 0:
        with pytest.raises(IbisInputError):
            con.add_column(table_name, cols_with_types)
        return con.drop_table(table_name)

    con.add_column(table_name, new_cols)

    schema_new_cols = ibis.schema(new_cols.items())
    schema_new = schema.append(schema_new_cols)

    try:
        t = con.table(table_name)
        assert schema == schema_new
    finally:
        con.drop_table(table_name)

note: probably for ddl we should use the same type names used by ibis expressions .. not the ones directly used by omniscidb. it could be a little bit confusing . I have a WIP PR that I was adding the add_columns op too. As you are working on that I will just remove that from my code ... but for now you can take a look how I was treating the datatypes there: #2086

ibis/omniscidb/tests/test_client.py Outdated Show resolved Hide resolved
@YarShev YarShev changed the title FEAT: Support add column and drop column FEAT: [OmnisciDB] Support add_column and drop_column for OmnisciDB table Mar 15, 2020
@YarShev YarShev changed the title FEAT: [OmnisciDB] Support add_column and drop_column for OmnisciDB table FEAT: [OmnisciDB] Support add_columns and drop_columns for OmnisciDB table Mar 16, 2020
@YarShev
Copy link
Contributor Author

YarShev commented Mar 16, 2020

@jreback , just friendly reminder.

@YarShev YarShev requested a review from jreback March 19, 2020 06:40
@YarShev
Copy link
Contributor Author

YarShev commented Mar 20, 2020

@jreback , just friendly reminder to review this PR.

@jreback
Copy link
Contributor

jreback commented Mar 20, 2020

make sure the PR is all green before a ping

@YarShev YarShev force-pushed the dev/yigoshev-add-drop-column branch from 92fdbdc to 34d9502 Compare March 20, 2020 12:31
@YarShev
Copy link
Contributor Author

YarShev commented Mar 20, 2020

@jreback , sorry, I didn't notice the problem relates with doc. Now, CI is green.

@YarShev YarShev closed this Mar 20, 2020
@YarShev YarShev reopened this Mar 20, 2020
@jreback
Copy link
Contributor

jreback commented Mar 20, 2020

this should come after #2086 which moves around the dtype mappings.

@YarShev
Copy link
Contributor Author

YarShev commented Mar 20, 2020

Ok, I will be waiting for this PR.

@jreback
Copy link
Contributor

jreback commented Mar 23, 2020

can you merge master and fix conflicts

@YarShev
Copy link
Contributor Author

YarShev commented Mar 23, 2020

@jreback , thanks for reminder, merged master and fixed conflicts

@YarShev
Copy link
Contributor Author

YarShev commented Mar 24, 2020

@jreback , just a friendly reminder.

@jreback jreback added this to the Next Feature Release milestone Mar 24, 2020
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @YarShev nice patch!

@jreback jreback merged commit b2df7cc into ibis-project:master Mar 24, 2020
@YarShev YarShev deleted the dev/yigoshev-add-drop-column branch March 24, 2020 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ddl Issues related to creating or altering data definitions feature Features or general enhancements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants