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

convert_base doesn't seem to work #10852

Open
1 task done
ophiry opened this issue Feb 16, 2025 · 2 comments
Open
1 task done

convert_base doesn't seem to work #10852

ophiry opened this issue Feb 16, 2025 · 2 comments
Labels
feature Features or general enhancements

Comments

@ophiry
Copy link

ophiry commented Feb 16, 2025

What happened?

trying to apply the convert_base method, and it fails

code to reproduce:

ibis.memtable({'a': ['10']}).select(_.a.convert_base(10,10)).preview()

error message:

OperationNotDefinedError: Compilation rule for 'BaseConvert' operation is not defined

What version of ibis are you using?

10.0.0

What backend(s) are you using, if any?

memtable (the provided example) and also DuckDB

Relevant log output

---------------------------------------------------------------------------
OperationNotDefinedError                  Traceback (most recent call last)
Cell In[17], line 1
----> 1 ibis.memtable({'a': ['10']}).select(_.a.convert_base(10,10)).preview()

File ~/Library/Caches/pypoetry/virtualenvs/shared-poetry-ampl-V-CqdIrx-py3.10/lib/python3.10/site-packages/ibis/expr/types/relations.py:563, in Table.preview(self, max_rows, max_columns, max_length, max_string, max_depth, console_width)
    513 """Return a subset as a Rich Table.
    514 
    515 This is an explicit version of what you get when you inspect
   (...)
    559 └─────────┴──────────┴───┘
    560 """
    561 from ibis.expr.types.pretty import to_rich
--> 563 return to_rich(
    564     self,
    565     max_columns=max_columns,
    566     max_rows=max_rows,
    567     max_length=max_length,
    568     max_string=max_string,
    569     max_depth=max_depth,
    570     console_width=console_width,
    571 )

File ~/Library/Caches/pypoetry/virtualenvs/shared-poetry-ampl-V-CqdIrx-py3.10/lib/python3.10/site-packages/ibis/expr/types/pretty.py:279, in to_rich(expr, max_rows, max_columns, max_length, max_string, max_depth, console_width)
    275     return _to_rich_scalar(
    276         expr, max_length=max_length, max_string=max_string, max_depth=max_depth
    277     )
    278 else:
--> 279     return _to_rich_table(
    280         expr,
    281         max_rows=max_rows,
    282         max_columns=max_columns,
    283         max_length=max_length,
    284         max_string=max_string,
    285         max_depth=max_depth,
    286         console_width=console_width,
    287     )

File ~/Library/Caches/pypoetry/virtualenvs/shared-poetry-ampl-V-CqdIrx-py3.10/lib/python3.10/site-packages/ibis/expr/types/pretty.py:358, in _to_rich_table(tablish, max_rows, max_columns, max_length, max_string, max_depth, console_width)
    355     if orig_ncols > len(computed_cols):
    356         table = table.select(*computed_cols)
--> 358 result = table.limit(max_rows + 1).to_pyarrow()
    359 # Now format the columns in order, stopping if the console width would
    360 # be exceeded.
    361 col_info = []

File ~/Library/Caches/pypoetry/virtualenvs/shared-poetry-ampl-V-CqdIrx-py3.10/lib/python3.10/site-packages/ibis/expr/types/core.py:579, in Expr.to_pyarrow(self, params, limit, **kwargs)
    551 @experimental
    552 def to_pyarrow(
    553     self,
   (...)
    557     **kwargs: Any,
    558 ) -> pa.Table:
    559     """Execute expression and return results in as a pyarrow table.
    560 
    561     This method is eager and will execute the associated expression
   (...)
    577         A pyarrow table holding the results of the executed expression.
    578     """
--> 579     return self._find_backend(use_default=True).to_pyarrow(
    580         self, params=params, limit=limit, **kwargs
    581     )

File ~/Library/Caches/pypoetry/virtualenvs/shared-poetry-ampl-V-CqdIrx-py3.10/lib/python3.10/site-packages/ibis/backends/duckdb/__init__.py:1312, in Backend.to_pyarrow(self, expr, params, limit, **kwargs)
   1303 def to_pyarrow(
   1304     self,
   1305     expr: ir.Expr,
   (...)
   1310     **kwargs: Any,
   1311 ) -> pa.Table:
-> 1312     table = self._to_duckdb_relation(
   1313         expr, params=params, limit=limit, **kwargs
   1314     ).arrow()
   1315     return expr.__pyarrow_result__(table, data_mapper=DuckDBPyArrowData)

File ~/Library/Caches/pypoetry/virtualenvs/shared-poetry-ampl-V-CqdIrx-py3.10/lib/python3.10/site-packages/ibis/backends/duckdb/__init__.py:1258, in Backend._to_duckdb_relation(self, expr, params, limit, **kwargs)
   1256 self._run_pre_execute_hooks(expr)
   1257 table_expr = expr.as_table()
-> 1258 sql = self.compile(table_expr, limit=limit, params=params, **kwargs)
   1259 if table_expr.schema().geospatial:
   1260     self._load_extensions(["spatial"])

File ~/Library/Caches/pypoetry/virtualenvs/shared-poetry-ampl-V-CqdIrx-py3.10/lib/python3.10/site-packages/ibis/backends/sql/__init__.py:135, in SQLBackend.compile(self, expr, limit, params, pretty)
    108 def compile(
    109     self,
    110     expr: ir.Expr,
   (...)
    115     pretty: bool = False,
    116 ) -> str:
    117     """Compile an expression to a SQL string.
    118 
    119     Parameters
   (...)
    133         Compiled expression
    134     """
--> 135     query = self.compiler.to_sqlglot(expr, limit=limit, params=params)
    136     sql = query.sql(dialect=self.dialect, pretty=pretty, copy=False)
    137     self._log(sql)

File ~/Library/Caches/pypoetry/virtualenvs/shared-poetry-ampl-V-CqdIrx-py3.10/lib/python3.10/site-packages/ibis/backends/sql/compilers/duckdb.py:117, in DuckDBCompiler.to_sqlglot(self, expr, limit, params)
    110 def to_sqlglot(
    111     self,
    112     expr: ir.Expr,
   (...)
    115     params: Mapping[ir.Expr, Any] | None = None,
    116 ):
--> 117     sql = super().to_sqlglot(expr, limit=limit, params=params)
    119     table_expr = expr.as_table()
    120     geocols = table_expr.schema().geospatial

File ~/Library/Caches/pypoetry/virtualenvs/shared-poetry-ampl-V-CqdIrx-py3.10/lib/python3.10/site-packages/ibis/backends/sql/compilers/base.py:597, in SQLGlotCompiler.to_sqlglot(self, expr, limit, params)
    594 if params is None:
    595     params = {}
--> 597 sql = self.translate(table_expr.op(), params=params)
    598 assert not isinstance(sql, sge.Subquery)
    600 if isinstance(sql, sge.Table):

File ~/Library/Caches/pypoetry/virtualenvs/shared-poetry-ampl-V-CqdIrx-py3.10/lib/python3.10/site-packages/ibis/backends/sql/compilers/base.py:665, in SQLGlotCompiler.translate(self, op, params)
    662             return result.as_(alias, quoted=self.quoted)
    664 # apply translate rules in topological order
--> 665 results = op.map(fn)
    667 # get the root node as a sqlglot select statement
    668 out = results[op]

File ~/Library/Caches/pypoetry/virtualenvs/shared-poetry-ampl-V-CqdIrx-py3.10/lib/python3.10/site-packages/ibis/common/graph.py:305, in Node.map(self, fn, filter)
    299 for node in graph:
    300     # minor optimization to directly recurse into the children
    301     kwargs = {
    302         k: _recursive_lookup(v, results)
    303         for k, v in zip(node.__argnames__, node.__args__)
    304     }
--> 305     results[node] = fn(node, results, **kwargs)
    307 return results

File ~/Library/Caches/pypoetry/virtualenvs/shared-poetry-ampl-V-CqdIrx-py3.10/lib/python3.10/site-packages/ibis/backends/sql/compilers/base.py:645, in SQLGlotCompiler.translate.<locals>.fn(node, _, **kwargs)
    644 def fn(node, _, **kwargs):
--> 645     result = self.visit_node(node, **kwargs)
    647     # if it's not a relation then we don't need to do anything special
    648     if node is op or not isinstance(node, ops.Relation):

File ~/Library/Caches/pypoetry/virtualenvs/shared-poetry-ampl-V-CqdIrx-py3.10/lib/python3.10/site-packages/ibis/backends/sql/compilers/base.py:691, in SQLGlotCompiler.visit_node(self, op, **kwargs)
    689 method = getattr(self, f"visit_{type(op).__name__}", None)
    690 if method is not None:
--> 691     return method(op, **kwargs)
    692 else:
    693     raise com.OperationNotDefinedError(
    694         f"No translation rule for {type(op).__name__}"
    695     )

File ~/Library/Caches/pypoetry/virtualenvs/shared-poetry-ampl-V-CqdIrx-py3.10/lib/python3.10/site-packages/ibis/backends/sql/compilers/base.py:1555, in SQLGlotCompiler.visit_Undefined(self, op, **_)
   1554 def visit_Undefined(self, op, **_):
-> 1555     raise com.OperationNotDefinedError(
   1556         f"Compilation rule for {type(op).__name__!r} operation is not defined"
   1557     )

OperationNotDefinedError: Compilation rule for 'BaseConvert' operation is not defined

Code of Conduct

  • I agree to follow this project's Code of Conduct
@ophiry ophiry added the bug Incorrect behavior inside of ibis label Feb 16, 2025
@gforsyth gforsyth added feature Features or general enhancements and removed bug Incorrect behavior inside of ibis labels Feb 16, 2025
@gforsyth
Copy link
Member

Thanks for opening the issue @ophiry ! Looks like this bit of functionality is only currently available with the Impala backend. Do you have a particular need for base conversion or were you kicking the tires?

@ophiry
Copy link
Author

ophiry commented Feb 16, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Features or general enhancements
Projects
Status: backlog
Development

No branches or pull requests

2 participants