-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add featureset spec for test (#2960)
* Add featureset spec for test * Update overwrite true * Update change checking path * Merge master
- Loading branch information
Showing
9 changed files
with
91 additions
and
8 deletions.
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
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
37 changes: 37 additions & 0 deletions
37
...python/featurestore_sample/featurestore/featuresets/transactions/spec/FeatureSetSpec.yaml
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,37 @@ | ||
feature_transformation: | ||
transformation_code: | ||
path: ./transformation_code | ||
transformer_class: transaction_transform.TransactionFeatureTransformer | ||
features: | ||
- name: transaction_3d_count | ||
type: long | ||
- name: transaction_amount_3d_sum | ||
type: double | ||
- name: transaction_amount_3d_avg | ||
type: double | ||
- name: transaction_7d_count | ||
type: long | ||
- name: transaction_amount_7d_sum | ||
type: double | ||
- name: transaction_amount_7d_avg | ||
type: double | ||
index_columns: | ||
- name: accountID | ||
type: string | ||
source: | ||
path: wasbs://[email protected]/feature-store-prp/datasources/transactions-source/*.parquet | ||
source_delay: | ||
days: 0 | ||
hours: 0 | ||
minutes: 20 | ||
timestamp_column: | ||
name: timestamp | ||
type: parquet | ||
source_lookback: | ||
days: 7 | ||
hours: 0 | ||
minutes: 0 | ||
temporal_join_lookback: | ||
days: 1 | ||
hours: 0 | ||
minutes: 0 |
46 changes: 46 additions & 0 deletions
46
...e/featurestore/featuresets/transactions/spec/transformation_code/transaction_transform.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,46 @@ | ||
from pyspark.sql import functions as F | ||
from pyspark.sql.window import Window | ||
from pyspark.ml import Transformer | ||
from pyspark.sql.dataframe import DataFrame | ||
|
||
|
||
class TransactionFeatureTransformer(Transformer): | ||
def _transform(self, df: DataFrame) -> DataFrame: | ||
days = lambda i: i * 86400 | ||
w_3d = ( | ||
Window.partitionBy("accountID") | ||
.orderBy(F.col("timestamp").cast("long")) | ||
.rangeBetween(-days(3), 0) | ||
) | ||
w_7d = ( | ||
Window.partitionBy("accountID") | ||
.orderBy(F.col("timestamp").cast("long")) | ||
.rangeBetween(-days(7), 0) | ||
) | ||
res = ( | ||
df.withColumn("transaction_7d_count", F.count("transactionID").over(w_7d)) | ||
.withColumn( | ||
"transaction_amount_7d_sum", F.sum("transactionAmount").over(w_7d) | ||
) | ||
.withColumn( | ||
"transaction_amount_7d_avg", F.avg("transactionAmount").over(w_7d) | ||
) | ||
.withColumn("transaction_3d_count", F.count("transactionID").over(w_3d)) | ||
.withColumn( | ||
"transaction_amount_3d_sum", F.sum("transactionAmount").over(w_3d) | ||
) | ||
.withColumn( | ||
"transaction_amount_3d_avg", F.avg("transactionAmount").over(w_3d) | ||
) | ||
.select( | ||
"accountID", | ||
"timestamp", | ||
"transaction_3d_count", | ||
"transaction_amount_3d_sum", | ||
"transaction_amount_3d_avg", | ||
"transaction_7d_count", | ||
"transaction_amount_7d_sum", | ||
"transaction_amount_7d_avg", | ||
) | ||
) | ||
return res |
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
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