-
Notifications
You must be signed in to change notification settings - Fork 14
Fix missing type casting in AGG group qualifier encoding #235
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
Open
zipdoki
wants to merge
1
commit into
main
Choose a base branch
from
feat/group-field-type-casting
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+291
−12
Open
Changes from all commits
Commits
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 hidden or 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 hidden or 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
54 changes: 54 additions & 0 deletions
54
core/src/test/kotlin/com/kakao/actionbase/core/metadata/common/GroupFieldTest.kt
This file contains hidden or 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,54 @@ | ||
| package com.kakao.actionbase.core.metadata.common | ||
|
|
||
| import com.kakao.actionbase.core.types.PrimitiveType | ||
|
|
||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertIs | ||
|
|
||
| import org.junit.jupiter.api.Nested | ||
| import org.junit.jupiter.api.Test | ||
|
|
||
| class GroupFieldTest { | ||
| @Nested | ||
| inner class BackwardCompatibility { | ||
| @Test | ||
| fun `legacy field without type deserializes and casts correctly after type resolution`() { | ||
| // 1. before type resolution — returns raw String (the bug) | ||
| val field = Group.Field(name = "someLongField") | ||
| val rawResult = field.bucketOrGet("1", ceil = false) | ||
| assertIs<String>(rawResult) | ||
|
|
||
| // 2. after type resolution (simulating resolveFieldTypes) | ||
| val resolved = field.copy(type = PrimitiveType.LONG) | ||
| val castedResult = resolved.bucketOrGet("1", ceil = false) | ||
| assertIs<Long>(castedResult) | ||
| assertEquals(1L, castedResult) | ||
| } | ||
| } | ||
|
|
||
| @Nested | ||
| inner class BucketOrGet { | ||
| @Test | ||
| fun `returns raw value when no bucket and no type`() { | ||
| val field = Group.Field(name = "myField") | ||
| val result = field.bucketOrGet("hello", ceil = false) | ||
| assertEquals("hello", result) | ||
| } | ||
|
|
||
| @Test | ||
| fun `casts String to Long when type is LONG`() { | ||
| val field = Group.Field(name = "myField", type = PrimitiveType.LONG) | ||
| val result = field.bucketOrGet("42", ceil = false) | ||
| assertIs<Long>(result) | ||
| assertEquals(42L, result) | ||
| } | ||
|
|
||
| @Test | ||
| fun `passes value to bucket when bucket is present, ignoring type`() { | ||
| val bucket = Bucket.Date("date_id", Bucket.ValueUnit.MILLISECOND, "+09:00", "yyyy-MM-dd") | ||
| val field = Group.Field(name = "ts", bucket = bucket, type = PrimitiveType.LONG) | ||
| val result = field.bucketOrGet(1700000000000L, ceil = false) | ||
| assertIs<String>(result) | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
182 changes: 182 additions & 0 deletions
182
server/src/test/kotlin/com/kakao/actionbase/server/api/graph/v3/EdgeAggQueryE2ETest.kt
This file contains hidden or 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,182 @@ | ||
| package com.kakao.actionbase.server.api.graph.v3 | ||
|
|
||
| import com.kakao.actionbase.server.test.E2ETestBase | ||
|
|
||
| import org.junit.jupiter.api.BeforeAll | ||
| import org.junit.jupiter.api.Nested | ||
| import org.junit.jupiter.api.Test | ||
| import org.junit.jupiter.api.TestInstance | ||
| import org.springframework.http.MediaType | ||
|
|
||
| /** | ||
| * E2E test for AGG query. | ||
| * | ||
| * Verifies that AGG queries correctly return aggregated counts | ||
| * for group fields with various field type and bucket combinations. | ||
| */ | ||
| @TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
| class EdgeAggQueryE2ETest : E2ETestBase() { | ||
| private val db = "agg-test-db" | ||
| private val table = "agg-test-table" | ||
|
|
||
| private val group1 = "count_by_day" | ||
| private val group2 = "count_by_permission_day" | ||
| private val group3 = "count_by_category_day" | ||
|
|
||
| // 1704067200000 = 2024-01-01 00:00:00 UTC | ||
| private val ts = 1704067200000L | ||
|
|
||
| @BeforeAll | ||
| fun setup() { | ||
| client | ||
| .post() | ||
| .uri("/graph/v3/databases") | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .bodyValue("""{"database": "$db", "comment": "test db"}""") | ||
| .exchange() | ||
| .expectStatus() | ||
| .isOk | ||
|
|
||
| val dateBucket = """{"type": "date", "name": "day", "unit": "MILLISECOND", "timezone": "+00:00", "format": "yyyy-MM-dd"}""" | ||
|
|
||
| client | ||
| .post() | ||
| .uri("/graph/v3/databases/$db/tables") | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .bodyValue( | ||
| """ | ||
| { | ||
| "table": "$table", | ||
| "schema": { | ||
| "type": "EDGE", | ||
| "source": {"type": "long", "comment": "source"}, | ||
| "target": {"type": "long", "comment": "target"}, | ||
| "properties": [ | ||
| {"name": "permission", "type": "string", "comment": "perm", "nullable": false}, | ||
| {"name": "categoryId", "type": "long", "comment": "category", "nullable": false}, | ||
| {"name": "createdAt", "type": "long", "comment": "ts", "nullable": false} | ||
| ], | ||
| "direction": "BOTH", | ||
| "indexes": [{"index": "created_at_desc", "fields": [{"field": "createdAt", "order": "DESC"}]}], | ||
| "groups": [ | ||
| {"group": "$group1", "type": "COUNT", "fields": [{"name": "createdAt", "bucket": $dateBucket}]}, | ||
| {"group": "$group2", "type": "COUNT", "fields": [{"name": "permission"}, {"name": "createdAt", "bucket": $dateBucket}]}, | ||
| {"group": "$group3", "type": "COUNT", "fields": [{"name": "categoryId"}, {"name": "createdAt", "bucket": $dateBucket}]} | ||
| ] | ||
| }, | ||
| "storage": "datastore://test_namespace/agg_test_hbase_table", | ||
| "mode": "SYNC", | ||
| "comment": "test table" | ||
| } | ||
| """.trimIndent(), | ||
| ).exchange() | ||
| .expectStatus() | ||
| .isOk | ||
|
|
||
| client | ||
| .post() | ||
| .uri("/graph/v3/databases/$db/tables/$table/edges") | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .bodyValue( | ||
| """ | ||
| { | ||
| "mutations": [ | ||
| {"type": "INSERT", "edge": {"version": 1, "source": 100, "target": 1000, "properties": {"permission": "read", "categoryId": 1, "createdAt": $ts}}}, | ||
| {"type": "INSERT", "edge": {"version": 2, "source": 100, "target": 1001, "properties": {"permission": "read", "categoryId": 1, "createdAt": $ts}}}, | ||
| {"type": "INSERT", "edge": {"version": 3, "source": 100, "target": 1002, "properties": {"permission": "write", "categoryId": 2, "createdAt": $ts}}} | ||
| ] | ||
| } | ||
| """.trimIndent(), | ||
| ).exchange() | ||
| .expectStatus() | ||
| .isOk | ||
| } | ||
|
|
||
| private fun aggQuery( | ||
| group: String, | ||
| ranges: String, | ||
| ) = client | ||
| .get() | ||
| .uri { builder -> | ||
| builder | ||
| .path("/graph/v3/databases/$db/tables/$table/edges/agg/$group") | ||
| .queryParam("start", "100") | ||
| .queryParam("direction", "OUT") | ||
| .queryParam("ranges", ranges) | ||
| .build() | ||
| }.exchange() | ||
| .expectStatus() | ||
| .isOk | ||
| .expectBody() | ||
|
|
||
| /** | ||
| * | rowKey (source, direction, group) | qualifier (day) | value | | ||
| * |-----------------------------------|-----------------|-------| | ||
| * | 100, OUT, count_by_day | "2024-01-01" | 3 | | ||
| */ | ||
| @Nested | ||
| inner class BucketFieldOnly { | ||
| @Test | ||
| fun `returns aggregated count`() { | ||
| aggQuery(group1, "day:eq:2024-01-01") | ||
| .jsonPath("$.count") | ||
| .isEqualTo(1) | ||
| .jsonPath("$.groups[0].value") | ||
| .isEqualTo(3) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * | rowKey (source, direction, group) | qualifier (permission, day) | value | | ||
| * |-----------------------------------|-----------------------------|-------| | ||
| * | 100, OUT, count_by_permission_day | "read", "2024-01-01" | 2 | | ||
| * | 100, OUT, count_by_permission_day | "write", "2024-01-01" | 1 | | ||
| */ | ||
| @Nested | ||
| inner class StringFieldAndBucket { | ||
| @Test | ||
| fun `returns aggregated count for matching value`() { | ||
| aggQuery(group2, "permission:eq:read;day:eq:2024-01-01") | ||
| .jsonPath("$.count") | ||
| .isEqualTo(1) | ||
| .jsonPath("$.groups[0].value") | ||
| .isEqualTo(2) | ||
| } | ||
|
|
||
| @Test | ||
| fun `returns correct count for different value`() { | ||
| aggQuery(group2, "permission:eq:write;day:eq:2024-01-01") | ||
| .jsonPath("$.count") | ||
| .isEqualTo(1) | ||
| .jsonPath("$.groups[0].value") | ||
| .isEqualTo(1) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * | rowKey (source, direction, group) | qualifier (categoryId, day) | value | | ||
| * |-----------------------------------|-----------------------------|-------| | ||
| * | 100, OUT, count_by_category_day | 1L, "2024-01-01" | 2 | | ||
| * | 100, OUT, count_by_category_day | 2L, "2024-01-01" | 1 | | ||
| */ | ||
| @Nested | ||
| inner class LongFieldAndBucket { | ||
| @Test | ||
| fun `returns aggregated count for matching value`() { | ||
| aggQuery(group3, "categoryId:eq:1;day:eq:2024-01-01") | ||
| .jsonPath("$.count") | ||
| .isEqualTo(1) | ||
| .jsonPath("$.groups[0].value") | ||
| .isEqualTo(2) | ||
| } | ||
|
|
||
| @Test | ||
| fun `returns correct count for different value`() { | ||
| aggQuery(group3, "categoryId:eq:2;day:eq:2024-01-01") | ||
| .jsonPath("$.count") | ||
| .isEqualTo(1) | ||
| .jsonPath("$.groups[0].value") | ||
| .isEqualTo(1) | ||
| } | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
@em3s
DECIMALgroup fields are not yet supported — PrimitiveType has no DECIMAL variant. Tracked for a follow-up.