-
Notifications
You must be signed in to change notification settings - Fork 593
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
FEAT: [OmnisciDB] Support add_columns and drop_columns for OmnisciDB table #2094
Conversation
@YarShev please fix docstrings |
thanks, fixed |
ibis/omniscidb/ddl.py
Outdated
------- | ||
string | ||
""" | ||
unsupported_types = ['POINT', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)';
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, didn't notice
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
ibis/omniscidb/client.py
Outdated
@@ -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): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@YarShev do |
ibis/omniscidb/client.py
Outdated
Examples | ||
-------- | ||
>>> table_name = 'my_table' | ||
>>> columns_with_types = my_column_1 = 'INTEGER', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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/tests/test_client.py
Outdated
@@ -100,6 +100,53 @@ def test_union_op(alltypes): | |||
expr.compile() | |||
|
|||
|
|||
def test_add_column(con): | |||
table_name = 'my_table' |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
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
|
||
con.create_table(table_name, schema=schema) | ||
|
||
dict_cols_with_types = {'c': 'DOUBLE', 'd': 'TEXT'} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this 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!
ibis/omniscidb/tests/test_client.py
Outdated
@@ -100,6 +100,53 @@ def test_union_op(alltypes): | |||
expr.compile() | |||
|
|||
|
|||
def test_add_column(con): | |||
table_name = 'my_table' |
There was a problem hiding this comment.
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
@jreback , just friendly reminder. |
@jreback , just friendly reminder to review this PR. |
make sure the PR is all green before a ping |
92fdbdc
to
34d9502
Compare
@jreback , sorry, I didn't notice the problem relates with doc. Now, CI is green. |
this should come after #2086 which moves around the dtype mappings. |
Ok, I will be waiting for this PR. |
can you merge master and fix conflicts |
@jreback , thanks for reminder, merged master and fixed conflicts |
@jreback , just a friendly reminder. |
There was a problem hiding this 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!
No description provided.