Skip to content
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

Update metadata export logic for join derivation #879

Merged
merged 32 commits into from
Dec 6, 2024
Merged

Conversation

yuli-han
Copy link
Collaborator

@yuli-han yuli-han commented Nov 20, 2024

Summary

Update the metadata export logic for join with derivation. Use derived columns as exported features.

Why / Goal

Test Plan

  • Added Unit Tests
  • Covered by existing CI
  • Integration tested

Testing result using Airbnb internal config https://docs.google.com/document/d/1RYMioAdAZxAqEjyfgQBenFFGXprAlhUsfHhJaYA-L8Y/edit?tab=t.0

Checklist

  • Documentation update

Reviewers

@hzding621 @pengyu-hou @SophieYu41

tableUtils.createDatabase(namespace)
val viewsGroupBy = getViewsGroupBy(suffix = "cumulative", makeCumulative = true, namespace)
val joinConf = getEventsEventsTemporal("cumulative", namespace)
joinConf.setJoinParts(Seq(Builders.JoinPart(groupBy = viewsGroupBy)).asJava)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a test case that contains external parts?

StructType(derivedDummyOutputDf.schema.filterNot(f => keyAndPartitionFields.map(_.name).contains(f.name))))
ListBuffer(columns.map { tup => toAggregationMetadata(tup._1, tup._2, joinConf.hasDerivations) }: _*)
} else {
aggregationsMetadata
Copy link
Collaborator

@hzding621 hzding621 Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rename agg because agg is specific to group_by, but now we have external parts and derivations

  • aggMetadata => joinOutputFieldsMetadata
  • aggregationsMetadata => joinIntermediateFieldsMetadata

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The concept of this aggMetadata is more like output features(not including keys). It will be used as the source data of features on MLI tool. I am thinking of maybe renaming this to featuresMetadata or joinOutputValuesMetadata.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yuli-han rename?

  • aggMetadata => joinOutputValuesMetadata
  • aggregationsMetadata => joinIntermediateValuesMetadata

expression = "*"
), Derivation(
name = "test_feature_name",
expression = f"${viewsGroupBy.metaData.name}_time_spent_ms_average"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some derivations that use ts and ds as inputs?

Copy link
Collaborator

@hzding621 hzding621 Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, can we add a test case for key columns as output?
such as

Derivation(
  name = "event_id",
  expression = "ext_contextual_event_id"
)

Copy link
Collaborator

@pengyu-hou pengyu-hou Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plus one on the ts and ds expressions. Those values will be derived from the request time.

val finalOutputColumns = joinConf.derivationsScala.finalOutputColumn(dummyOutputDf.columns).toSeq
val derivedDummyOutputDf = dummyOutputDf.select(finalOutputColumns: _*)
val columns = SparkConversions.toChrononSchema(
StructType(derivedDummyOutputDf.schema.filterNot(f => keyAndPartitionFields.map(_.name).contains(f.name))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the filterNot necessary here? I think we should keep everything that users included in derivations. For example, we should allow key columns to be in the output if users explicitly included it in derivations.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aggMetadata are actually features, so the purpose of this line is to exclude the keys from the features list.
But this may not apply to the case where the users rename an external feature to a key name, if that happens the key(which is actually an external feature) will be filtered out here 🤔

Map("ts" -> api.StringType, "ds" -> api.StringType)
}
val sparkSchema = {
val keySchema = leftSchema.filter(tup => keyColumns.contains(tup._1))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will need to handle key mapping here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handled in above code

val keyCols: Seq[String] = joinPart.groupBy.keyColumns.toScala
if (joinPart.keyMapping == null || joinPart.keyMapping.isEmpty) keyCols
else {
keyCols.map(key => joinPart.keyMapping.getOrDefault(key, key))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yuli-han keyMapping is a mapping from left_key to right_key, but here you are doing the reverse

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's include this in a unit test

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for catching! Updated the code and also added a unit test to cover it. Also tested locally using a manually created testing config and attached the result in the above testing result doc.

Comment on lines 418 to 423
val findKey = joinPart.keyMapping.toScala.find(_._2 == key)
if (findKey.isDefined) {
findKey.get._1
} else {
key
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yuli-han yuli-han merged commit 9798af6 into main Dec 6, 2024
8 checks passed
@yuli-han yuli-han deleted the ylh--join-derivation branch December 6, 2024 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants