Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

SQLAlchemy 2: Add support for TINYINT#265

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
susodapop merged 1 commit intomainfromsqla-types-work
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletionssrc/databricks/sqlalchemy/README.tests.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,8 @@ We maintain three files of test cases that we import from the SQLAlchemy source

In some cases, only certain tests in class should be skipped with a `SkipReason` or `FutureFeature` justification. In those cases, we import the class into `_regression.py`, then import it from there into one or both of `_future.py` and `_unsupported.py`. If a class needs to be "touched" by regression, unsupported, and future, the class will be imported in that order. If an entire class should be skipped, then we do not import it into `_regression.py` at all.

We maintain `_extra.py` with test cases that depend on SQLAlchemy's reusable dialect test fixtures but which are specific to Databricks (e.g TinyIntegerTest).

## Running the reusable dialect tests

```
Expand Down
3 changes: 3 additions & 0 deletionssrc/databricks/sqlalchemy/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
from databricks.sqlalchemy.base import DatabricksDialect
from databricks.sqlalchemy._types import TINYINT

__all__ = ["TINYINT"]
12 changes: 12 additions & 0 deletionssrc/databricks/sqlalchemy/_types.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -212,3 +212,15 @@ def process(value):
return "%s" % _step2

return process


class TINYINT(sqlalchemy.types.TypeDecorator):
"""Represents 1-byte signed integers

Acts like a sqlalchemy SmallInteger() in Python but writes to a TINYINT field in Databricks

https://docs.databricks.com/en/sql/language-manual/data-types/tinyint-type.html
"""

impl = sqlalchemy.types.SmallInteger
cache_ok = True
48 changes: 48 additions & 0 deletionssrc/databricks/sqlalchemy/test/_extra.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
"""Additional tests authored by Databricks that use SQLAlchemy's test fixtures
"""

from sqlalchemy.testing.suite.test_types import (
_LiteralRoundTripFixture,
fixtures,
testing,
eq_,
select,
Table,
Column,
config,
)
from databricks.sqlalchemy import TINYINT


class TinyIntegerTest(_LiteralRoundTripFixture, fixtures.TestBase):
__backend__ = True

def test_literal(self, literal_round_trip):
literal_round_trip(TINYINT, [5], [5])

@testing.fixture
def integer_round_trip(self, metadata, connection):
def run(datatype, data):
int_table = Table(
"tiny_integer_table",
metadata,
Column(
"id",
TINYINT,
primary_key=True,
test_needs_autoincrement=False,
),
Column("tiny_integer_data", datatype),
)

metadata.create_all(config.db)

connection.execute(int_table.insert(), {"id": 1, "integer_data": data})

row = connection.execute(select(int_table.c.integer_data)).first()

eq_(row, (data,))

assert isinstance(row[0], int)

return run
1 change: 1 addition & 0 deletionssrc/databricks/sqlalchemy/test/test_suite.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,3 +9,4 @@
from databricks.sqlalchemy.test._regression import *
from databricks.sqlalchemy.test._unsupported import *
from databricks.sqlalchemy.test._future import *
from databricks.sqlalchemy.test._extra import TinyIntegerTest
2 changes: 2 additions & 0 deletionssrc/databricks/sqlalchemy/test_local/test_types.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@
import sqlalchemy

from databricks.sqlalchemy.base import DatabricksDialect
from databricks.sqlalchemy._types import TINYINT


class DatabricksDataType(enum.Enum):
Expand DownExpand Up@@ -127,6 +128,7 @@ def test_numeric_renders_as_decimal_with_precision_and_scale(self):
sqlalchemy.types.INT: DatabricksDataType.INT,
sqlalchemy.types.SMALLINT: DatabricksDataType.SMALLINT,
sqlalchemy.types.TIMESTAMP: DatabricksDataType.TIMESTAMP,
TINYINT: DatabricksDataType.TINYINT,
}


Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp