-
Notifications
You must be signed in to change notification settings - Fork 53
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
Metadata cleanup #272
Closed
+1,796
−2,393
Closed
Metadata cleanup #272
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6a17569
created new TSIndex and TSSchema classes to represent TSDF metadata.
tnixon 3c3e5f8
saving progess to this point
tnixon 9ceac4d
Merge branch 'master' into metadata_cleanup
tnixon 5519daf
getting tsdf_tests.BasicTests to pass
tnixon 6084277
big search & replace: partition_cols -> series_ids
tnixon 0dd3b43
all as_of tests passing but 1
tnixon 8199b60
Merge branch 'v0.2-integration' into metadata_cleanup
tnixon c2ef72b
checkpoint save of current progress...
tnixon ef1f4ee
Revert "checkpoint save of current progress..."
tnixon 0c9e32a
Merge branch 'v0.2-integration' into metadata_cleanup
tnixon f5de397
Merge branch 'v0.2-integration' into metadata_cleanup
tnixon 99c5e9c
merging changes from integration branch
tnixon ab1ff0c
Merge branch 'v0.2-integration' into metadata_cleanup
tnixon 1459ff5
black code formatting
tnixon c924f16
Merge branch 'v0.2-integration' into metadata_cleanup
tnixon f2d2669
Standardizing pyspark.sql.functions as Fn
tnixon ea47327
Merge branch 'v0.2-integration' into metadata_cleanup
tnixon b8e8f8e
committing WIP - migrating to new laptop
tnixon e9578be
merging non-code changes from master (via v0.2-integration)
tnixon 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
Next
Next commit
created new TSIndex and TSSchema classes to represent TSDF metadata.
First round of TSDF code changes to use the new classes
commit 6a175697339cca91ad6979b9776e15b130354906
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,99 @@ | ||
from typing import Collection | ||
|
||
from pyspark.sql.types import * | ||
|
||
|
||
class TSIndex: | ||
# Valid types for time index columns | ||
__valid_ts_types = ( | ||
DateType(), | ||
TimestampType(), | ||
ByteType(), | ||
ShortType(), | ||
IntegerType(), | ||
LongType(), | ||
DecimalType(), | ||
FloatType(), | ||
DoubleType(), | ||
) | ||
|
||
def __init__(self, name: str, dataType: DataType) -> None: | ||
if dataType not in self.__valid_ts_types: | ||
raise TypeError(f"DataType {dataType} is not valid for a Timeseries Index") | ||
self.name = name | ||
self.dataType = dataType | ||
|
||
@classmethod | ||
def fromField(cls, ts_field: StructField) -> "TSIndex": | ||
return cls(ts_field.name, ts_field.dataType) | ||
|
||
|
||
class TSSchema: | ||
""" | ||
Schema type for a :class:`TSDF` class. | ||
""" | ||
|
||
# Valid types for metric columns | ||
__metric_types = ( | ||
BooleanType(), | ||
ByteType(), | ||
ShortType(), | ||
IntegerType(), | ||
LongType(), | ||
DecimalType(), | ||
FloatType(), | ||
DoubleType(), | ||
) | ||
|
||
def __init__( | ||
self, | ||
ts_idx: TSIndex, | ||
series_ids: Collection[str] = None, | ||
user_ts_col: str = None, | ||
subsequence_col: str = None, | ||
) -> None: | ||
self.ts_idx = ts_idx | ||
self.series_ids = list(series_ids) | ||
self.user_ts_col = user_ts_col | ||
self.subsequence_col = subsequence_col | ||
|
||
@classmethod | ||
def fromDFSchema( | ||
cls, df_schema: StructType, ts_col: str, series_ids: Collection[str] = None | ||
) -> "TSSchema": | ||
# construct a TSIndex for the given ts_col | ||
ts_idx = TSIndex.fromField(df_schema[ts_col]) | ||
return cls(ts_idx, series_ids) | ||
|
||
@property | ||
def ts_index(self) -> str: | ||
return self.ts_idx.name | ||
|
||
@property | ||
def structural_columns(self) -> set[str]: | ||
""" | ||
Structural columns are those that define the structure of the :class:`TSDF`. This includes the timeseries column, | ||
a timeseries index (if different), any subsequence column (if present), and the series ID columns. | ||
:return: a set of column names corresponding the structural columns of a :class:`TSDF` | ||
""" | ||
struct_cols = {self.ts_index, self.user_ts_col, self.subsequence_col}.union( | ||
self.series_ids | ||
) | ||
struct_cols.discard(None) | ||
return struct_cols | ||
|
||
def validate(self, df_schema: StructType) -> None: | ||
pass | ||
|
||
def find_observational_columns(self, df_schema: StructType) -> list[StructField]: | ||
return [ | ||
col for col in df_schema.fields if col.name not in self.structural_columns | ||
] | ||
|
||
def find_metric_columns(self, df_schema: StructType) -> list[StructField]: | ||
return [ | ||
col | ||
for col in self.find_observational_columns(df_schema) | ||
if col.dataType in self.__metric_types | ||
] |
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.
What's the scenario where we would not want to validate the schema?
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 see there are some protected methods where we don't validate schema, but seems like exposing this arg could cause issues if set to
False
when users initialize a TSDF.I also don't think it hurts to validate the schema each time we manipulate the underlying DF in any way, even protected args.
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.
Most TSDF transformer methods make some changes to the underlying DF and then return it wrapped in a new TSDF object. I think of this validation as primarily for end-users who might need guidance on how they're building a TSDF. Internal transformations should already be safe, so shouldn't require validation.
However, I'm open to doing validation on every constructor. I dont' think it'll be a hugely heavy function.