-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[Load CDK] test improvements #50406
Merged
edgao
merged 3 commits into
master
from
edgao/avro_parquet_data_dumping_without_coercion
Jan 3, 2025
Merged
[Load CDK] test improvements #50406
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
69 changes: 69 additions & 0 deletions
69
...ad-avro/src/testFixtures/kotlin/io/airbyte/cdk/load/data/avro/AvroExpectedRecordMapper.kt
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,69 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.load.data.avro | ||
|
||
import io.airbyte.cdk.load.data.AirbyteType | ||
import io.airbyte.cdk.load.data.AirbyteValue | ||
import io.airbyte.cdk.load.data.ArrayValue | ||
import io.airbyte.cdk.load.data.DateValue | ||
import io.airbyte.cdk.load.data.IntegerValue | ||
import io.airbyte.cdk.load.data.ObjectValue | ||
import io.airbyte.cdk.load.data.TimeWithTimezoneValue | ||
import io.airbyte.cdk.load.data.TimeWithoutTimezoneValue | ||
import io.airbyte.cdk.load.data.TimestampWithTimezoneValue | ||
import io.airbyte.cdk.load.data.TimestampWithoutTimezoneValue | ||
import io.airbyte.cdk.load.test.util.ExpectedRecordMapper | ||
import io.airbyte.cdk.load.test.util.OutputRecord | ||
import java.time.LocalDate | ||
import java.time.ZoneOffset | ||
import java.time.temporal.ChronoField | ||
import java.time.temporal.TemporalAccessor | ||
|
||
object AvroExpectedRecordMapper : ExpectedRecordMapper { | ||
override fun mapRecord(expectedRecord: OutputRecord, schema: AirbyteType): OutputRecord { | ||
return expectedRecord.copy(data = timestampsToInteger(expectedRecord.data) as ObjectValue) | ||
} | ||
|
||
/** | ||
* Avro doesn't have true temporal types. Instead, we write dates as epoch days, and other | ||
* temporal types as epochMicros. Therefore, in expected records, we should convert from real | ||
* temporal types to IntegerValue. | ||
*/ | ||
private fun timestampsToInteger(value: AirbyteValue): AirbyteValue = | ||
when (value) { | ||
is DateValue -> IntegerValue(value.value.toEpochDay()) | ||
is TimestampWithTimezoneValue -> { | ||
val micros = getMicros(value.value) | ||
val epochSecond = value.value.toEpochSecond() | ||
integerValue(epochSecond, micros) | ||
} | ||
is TimestampWithoutTimezoneValue -> { | ||
val micros = getMicros(value.value) | ||
val epochSecond = value.value.toEpochSecond(ZoneOffset.UTC) | ||
integerValue(epochSecond, micros) | ||
} | ||
is TimeWithTimezoneValue -> { | ||
val micros = getMicros(value.value) | ||
val epochSecond = value.value.toEpochSecond(LocalDate.EPOCH) | ||
integerValue(epochSecond, micros) | ||
} | ||
is TimeWithoutTimezoneValue -> { | ||
val micros = getMicros(value.value) | ||
val epochSecond = value.value.toEpochSecond(LocalDate.EPOCH, ZoneOffset.UTC) | ||
integerValue(epochSecond, micros) | ||
} | ||
is ArrayValue -> ArrayValue(value.values.map { timestampsToInteger(it) }) | ||
is ObjectValue -> | ||
ObjectValue( | ||
value.values.mapValuesTo(linkedMapOf()) { (_, v) -> timestampsToInteger(v) } | ||
) | ||
else -> value | ||
} | ||
|
||
private fun getMicros(value: TemporalAccessor) = value.getLong(ChronoField.MICRO_OF_SECOND) | ||
|
||
private fun integerValue(epochSecond: Long, micros: Long) = | ||
IntegerValue(epochSecond * 1_000_000 + micros) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
adding an explicit
id
field helps RecordDiffer generate a nicer diff (i.e. instead of saying "there was an extra record, and also a missing record", it'll be able to match the records together + diff their fields)