-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
refactor(pinot): The python_date_format
for a temporal column was not being passed to get_timestamp_expr
#24942
Merged
Merged
Changes from 14 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
d60873e
implementation notes
ege-st 2367233
Initial work to fix bug
ege-st 78d43a9
clean up code
ege-st 0fd9b9e
Code cleanup
ege-st 1301e22
Code cleanup
ege-st ccdfe8d
Add comment
ege-st c83dc2b
Simpler code
ege-st b7d494a
Fixed a bug where the date format for a temporal column was not being…
ege-st 912fc24
Apply recommendations from PR feedback
ege-st 61ddf51
Merge branch 'master' into pinot-bug-fix
ege-st 01a041c
Do not use alias on select
ege-st 52268a1
undo unneeded changes
ege-st f9ef8e4
undo unneeded changes
ege-st 8fa3524
add tests and fix linting errors
ege-st e1c2a75
working on unit tests
ege-st 31d36cf
Fixing unit tests
ege-st 8a9ed76
Remove unused import
ege-st 81b8801
Use constants for time grains
ege-st 6e51f04
fix linting errors
ege-st 0042027
formatting
ege-st 399abf7
fixed formatting
ege-st 15fc982
fix integration test
ege-st 1e5cfc9
formatting
ege-st 4c6af11
fixing integration test
ege-st 88f3f23
Fix integration tests
ege-st 45d5c60
Fixing linter errors
ege-st 6c779ee
Fixing linter errors
ege-st File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
from datetime import datetime | ||
from typing import Optional | ||
from unittest import mock | ||
|
||
import pytest | ||
from sqlalchemy import column | ||
|
||
from tests.unit_tests.db_engine_specs.utils import assert_convert_dttm | ||
from tests.unit_tests.fixtures.common import dttm | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"target_type,expected_result", | ||
[ | ||
("Date", "CAST(TIME_PARSE('2019-01-02') AS DATE)"), | ||
("DateTime", "TIME_PARSE('2019-01-02T03:04:05')"), | ||
("TimeStamp", "TIME_PARSE('2019-01-02T03:04:05')"), | ||
("UnknownType", None), | ||
], | ||
) | ||
def test_convert_dttm( | ||
target_type: str, expected_result: Optional[str], dttm: datetime | ||
) -> None: | ||
from superset.db_engine_specs.pinot import PinotEngineSpec as spec | ||
|
||
assert_convert_dttm(spec, target_type, expected_result, dttm) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"time_grain,expected_result", | ||
[ | ||
("PT1S", "TIME_FLOOR(CAST(col AS TIMESTAMP), 'PT1S')"), | ||
("PT5M", "TIME_FLOOR(CAST({col} AS TIMESTAMP), 'PT5M')"), | ||
( | ||
"P1W/1970-01-03T00:00:00Z", | ||
"TIME_SHIFT(TIME_FLOOR(TIME_SHIFT(CAST(col AS TIMESTAMP), 'P1D', 1), 'P1W'), 'P1D', 5)", | ||
), | ||
( | ||
"1969-12-28T00:00:00Z/P1W", | ||
"TIME_SHIFT(TIME_FLOOR(TIME_SHIFT(CAST(col AS TIMESTAMP), 'P1D', 1), 'P1W'), 'P1D', -1)", | ||
), | ||
], | ||
) | ||
def test_timegrain_expressions(time_grain: str, expected_result: str) -> None: | ||
""" | ||
DB Eng Specs (druid): Test time grain expressions | ||
""" | ||
from superset.db_engine_specs.pinot import PinotEngineSpec as spec | ||
|
||
assert str( | ||
spec.get_timestamp_expr( | ||
col=column("col"), pdf=None, time_grain=time_grain | ||
) | ||
) | ||
|
||
|
||
def test_extras_without_ssl() -> None: | ||
from superset.db_engine_specs.pinot import PinotEngineSpec as spec | ||
from tests.integration_tests.fixtures.database import default_db_extra | ||
|
||
db = mock.Mock() | ||
db.extra = default_db_extra | ||
db.server_cert = None | ||
extras = spec.get_extra_params(db) | ||
assert "connect_args" not in extras["engine_params"] | ||
|
||
|
||
def test_extras_with_ssl() -> None: | ||
from superset.db_engine_specs.pinot import PinotEngineSpec as spec | ||
from tests.integration_tests.fixtures.certificates import ssl_certificate | ||
from tests.integration_tests.fixtures.database import default_db_extra | ||
|
||
db = mock.Mock() | ||
db.extra = default_db_extra | ||
db.server_cert = ssl_certificate | ||
extras = spec.get_extra_params(db) | ||
connect_args = extras["engine_params"]["connect_args"] | ||
assert connect_args["scheme"] == "https" | ||
assert "ssl_verify_cert" in connect_args |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we keep the enums here, eg,
TimeGrain.SECOND
instead ofPT1S
? It makes it much easier to read.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.
Thank you!