Comments (6)
try to use
sa.func.now()
from databricks-sql-python.
Hey folks thanks for the write-up and debugging! I'm pleased to see that you worked out how to hack this together using event.listens_for
. The sqlalchemy events system is a powerful tool, since nearly every behaviour of a given dialect can be patched in this way. I agree that this belongs in the dialect itself.
@dhirschfeld would you shoot an email to [email protected]
referencing this GitHub issue so we can track it and add it to the pipeline for enhancements to the dialect?
from databricks-sql-python.
Thanks to this thread I ws able to find out the magic syntax:
CREATE TABLE test.`ModelMetadata` (
pkid BIGINT GENERATED ALWAYS AS IDENTITY,
name STRING NOT NULL,
version STRING NOT NULL,
insert_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY (pkid)
) USING DELTA
TBLPROPERTIES(
'delta.minReaderVersion' = '1',
'delta.minWriterVersion'='7',
'delta.feature.allowColumnDefaults' = 'enabled'
);
...but I don't really know how to integrate that with sqlalchemy
.
If that is required for defaults then I guess this projects needs to implement a custom compiler to add the required TBLPROPERTIES
?
from databricks-sql-python.
With sa.func.now()
sqlalchemy
emits the below SQL:
CREATE TABLE test.`ModelMetadata` (
pkid BIGINT GENERATED ALWAYS AS IDENTITY,
name STRING NOT NULL,
version STRING NOT NULL,
insert_timestamp TIMESTAMP DEFAULT now() NOT NULL,
PRIMARY KEY (pkid)
) USING DELTA;
...which gives the below error:
[WRONG_COLUMN_DEFAULTS_FOR_DELTA_FEATURE_NOT_ENABLED]
Failed to execute CREATE TABLE command because it assigned a column DEFAULT value, but the corresponding table feature was not enabled.
Please retry the command again after executing ALTER TABLE tableName SET TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported').
from databricks-sql-python.
If that is required for defaults then I guess this projects needs to implement a custom compiler to add the required
TBLPROPERTIES
?
Or, even better, just enable allowColumnDefaults
by default so it Just Works without having to touch the sqlalchemy
compiler.
from databricks-sql-python.
In my specific case it appears I can hack around it with:
@event.listens_for(Base.metadata, "after_create")
def set_default_insert_timestamp(target, connection, **kw):
for table in target.tables:
connection.execute(DDL(f"""
ALTER TABLE {table} SET TBLPROPERTIES(
'delta.feature.allowColumnDefaults' = 'enabled'
);
"""))
connection.execute(DDL(f"""
ALTER TABLE {table}
ALTER COLUMN insert_timestamp
SET DEFAULT CURRENT_TIMESTAMP;
"""))
...but that's a bit gross 🤢
It would be nice for the standard sqlalchemy
server_default
to Just Work with no hacks required (by the end-user!)
from databricks-sql-python.
Related Issues (20)
- Proxy authentication not working
- Is it possible to insert an arrow table? HOT 2
- Insert performance is woeful! 😢 HOT 11
- cursor.execute returing error 'NoneType' object is not iterable HOT 15
- [Document] Support databricks-cli authentication HOT 1
- Dash/Minus in column name causes UNBOUND_SQL_PARAMETER in bind values HOT 2
- Extremely slow import times on Python 3.12 HOT 9
- [sqlalchemy] execute("select 1") gives TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType' HOT 8
- `databricks.sql.connect` hangs in a long retrying loop when an invalid access token is used HOT 3
- Idea: arrow_record_batches cursor method
- SQLAlchemy engine from workspace level service principle? HOT 2
- Unable to write list/array type data HOT 2
- Issue with version 3.1.1
- Failure on cursor.fetchall() HOT 2
- Fixing a couple type problems. (adding py.typed, typing connect, returning Any from fetchall (which I failed to fix!)) HOT 2
- Connector reads 0 rows although Cluster returned results HOT 18
- support new Cursor attribute that provides information on completed commands HOT 1
- loosen, update, or widen pyarrow dependencies HOT 2
- ImportError: cannot import name 'sql' from partially initialized module 'databricks' HOT 2
- Unpin Thrift
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from databricks-sql-python.