You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.
The idea of this function is to be able to update a model table after it has been run (as an after-hook).
An example scenario would be:
-- models/tickets/tickets_with_sentiment.sqlSELECT*,
-- NOTE: will be filled by fal in sentiment_analysis.pyNULLAS label,
NULLAS score
FROM {{ ref('tickets') }}
Then, the after-hook:
# models/tickets/sentiment_analysis.pyticket_data=ref(context.current_model)
ticket_descriptions=list(ticket_data.description)
classifier=pipeline("sentiment-analysis")
description_sentiment_analysis=classifier(ticket_descriptions)
rows= []
forid, sentimentinzip(ticket_data.id, description_sentiment_analysis):
rows.append((int(id), sentiment["label"], sentiment["score"]))
records=np.array(rows, dtype=[("id", int), ("label", "U8"), ("score", float)])
sentiment_df=pd.DataFrame.from_records(records)
print("Uploading\n", sentiment_df)
write_to_model(
dataframe=sentiment_df,
# needed because function has no context of where it is being called from# we just have to document very well# (btw, what would happen if people used it "wrong"?)ref=context.current_model,
id_column='id', # must be the same in df and table, used for knowing WHICH row to updatecolumns=['label', 'score'] # defaults to ALL columns in dataframe?
)
How would the actual SQL statement look?
SQL does not match this kind of operation of inserting data on already existing rows very well. So you usually are updating data based on other database data or not doing it in big batches as we will.
The following SQL statement should work. However, more ideas may come up.
Initial proposal
The idea of this function is to be able to update a model table after it has been run (as an after-hook).
An example scenario would be:
Then, the after-hook:
How would the actual SQL statement look?
SQL does not match this kind of operation of inserting data on already existing rows very well. So you usually are updating data based on other database data or not doing it in big batches as we will.
The following SQL statement should work. However, more ideas may come up.
The text was updated successfully, but these errors were encountered: