You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[sqlalchemy] [Feature Request] Support default values #324
DatabaseError: (databricks.sql.exc.ServerOperationError) [INTERNAL_ERROR] The Spark SQL phase planning failed with an internal error. You hit a bug in Spark or the Spark plugins you use. Please, report this bug to the corresponding communities or vendors, and provide the full stack trace.
[SQL:
CREATE TABLE test.`ModelMetadata` (
pkid BIGINT GENERATED ALWAYS AS IDENTITY,
name STRING NOT NULL,
version STRING NOT NULL,
insert_timestamp TIMESTAMP_NTZ DEFAULT CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY (pkid)
) USING DELTA
]
(Background on this error at: https://sqlalche.me/e/20/4xp6)
Edit:
It looks like the internal error is created by having a TIMESTAMP_NTZ type with the CURRENT_TIMESTAMP default. Using the correct TIMESTAMP type for the column then gives the table feature was not enabled error.
To work around the latter error requires setting the table properties, which AFAICS can't be done from sqlalchemy, at least not directly.
CREATETABLEtest.`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').
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?
Activity
wibbico commentedon Jan 22, 2024
try to use
sa.func.now()dhirschfeld commentedon Jan 22, 2024
Thanks to this thread I ws able to find out the magic syntax:
...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?dhirschfeld commentedon Jan 22, 2024
With
sa.func.now()sqlalchemyemits the below SQL:...which gives the below error:
dhirschfeld commentedon Jan 22, 2024
Or, even better, just enable
allowColumnDefaultsby default so it Just Works without having to touch thesqlalchemycompiler.dhirschfeld commentedon Jan 22, 2024
In my specific case it appears I can hack around it with:
...but that's a bit gross 🤢
It would be nice for the standard
sqlalchemyserver_defaultto Just Work with no hacks required (by the end-user!)susodapop commentedon Jan 22, 2024
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?[-][Feature Request] Support default values[/-][+][sqlalchemy] [Feature Request] Support default values[/+]