-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Dttm format #506
Closed
Closed
Dttm format #506
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
439b7a1
time format minor features added
axeisghost cec723a
add description for datetime format input
404a2fd
db version bug walkaround
yxjames 4336f83
removed unecessary comments and fixed minor bug
axeisghost 34b6278
Merge branch 'master' into dttm_format
joshwalters eba364d
fixed code style
axeisghost 2ff5cc1
minor fix
axeisghost 5816d01
fixed missing time format column in DruidDatasource
axeisghost 7360fd2
Merge branch 'master' into dttm_format
joshwalters 6897c38
Update models.py
joshwalters adcafad
Merge branch 'master' into dttm_format
joshwalters 7218303
Revert "Update models.py"
joshwalters e91507a
removed timestamp_format from druid and removed try catch in migration
axeisghost c610dc0
Using spaces, not tabs
joshwalters 55bf3e0
Merge branch 'master' of https://github.com/airbnb/caravel into dttm_…
axeisghost 53d7b24
get the most updated migration and add the migration on the head of it
axeisghost 09d0b9e
remove vscode setting file
axeisghost 669cc77
Merge branch 'master' into dttm_format
joshwalters d8552b0
Merge branch 'master' into dttm_format
yxjames 7a6310e
Merge branch 'master' into dttm_format
joshwalters 9c5419a
Merge branch 'master' into dttm_format
joshwalters 646542a
Merge branch 'master' into dttm_format
joshwalters 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
22 changes: 22 additions & 0 deletions
22
caravel/migrations/versions/c9f8bef6f6a0_add_timestamp_format_for_tables.py
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,22 @@ | ||
"""Add timestamp format for tables | ||
|
||
Revision ID: c9f8bef6f6a0 | ||
Revises: 1226819ee0e3 | ||
Create Date: 2016-06-02 16:42:24.573924 | ||
|
||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'c9f8bef6f6a0' | ||
down_revision = '1226819ee0e3' | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
def upgrade(): | ||
op.add_column('tables', sa.Column('timestamp_format', sa.String(length=256), nullable=True)) | ||
|
||
|
||
def downgrade(): | ||
op.drop_column('tables', 'timestamp_format') |
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
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 |
---|---|---|
|
@@ -133,14 +133,20 @@ def get_df(self, query_obj=None): | |
self.results = None | ||
|
||
# The datasource here can be different backend but the interface is common | ||
# timestamp_format is not necessary for Druid side, so when the datasource | ||
# is not table, timestamp_format is set as None | ||
timestamp_format = None | ||
if self.datasource.type == 'table': | ||
timestamp_format = self.datasource.timestamp_format | ||
self.results = self.datasource.query(**query_obj) | ||
self.query = self.results.query | ||
df = self.results.df | ||
if df is None or df.empty: | ||
raise Exception("No data, review your incantations!") | ||
else: | ||
if 'timestamp' in df.columns: | ||
df.timestamp = pd.to_datetime(df.timestamp, utc=False) | ||
df.timestamp = pd.to_datetime( | ||
df.timestamp, utc=False, format=timestamp_format) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this here as opposed to relying on pandas's |
||
if self.datasource.offset: | ||
df.timestamp += timedelta(hours=self.datasource.offset) | ||
df = df.fillna(0) | ||
|
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.
i think this previous approach had shortcomings to start with. It assumed that the casting required could be defined on a per-database basis where it cannot since even within a single table you could represent dates in different fashion (epoch, string, native DATETIME, DATE or TIMESTAMP types...).