Repository: oom-ai/oomstore
Pull request #926 (2022-01-07 07:12:33)

Join/fix `ReadJoinedTable`
This PR fixes `ReadJoinedTable`, make sure each row contains all joined values.

codecov[bot]: # [Codecov](https://codecov.io/gh/oom-ai/oomstore/pull/926?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai) Report
> Merging [#926](https://codecov.io/gh/oom-ai/oomstore/pull/926?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai) (4b0f0ef) into [main](https://codecov.io/gh/oom-ai/oomstore/commit/d33bbe6b0740aafe11ce963f0c7641d12bd449bf?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai) (d33bbe6) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/oom-ai/oomstore/pull/926/graphs/tree.svg?width=650&height=150&src=pr&token=C59L7LTRM4&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai)](https://codecov.io/gh/oom-ai/oomstore/pull/926?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai)

```diff
@@           Coverage Diff           @@
##             main     #926   +/-   ##
=======================================
  Coverage   51.00%   51.00%           
=======================================
  Files          86       86           
  Lines        3770     3770           
=======================================
  Hits         1923     1923           
  Misses       1622     1622           
  Partials      225      225           
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/oom-ai/oomstore/pull/926?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/oom-ai/oomstore/pull/926?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai). Last update [d33bbe6...4b0f0ef](https://codecov.io/gh/oom-ai/oomstore/pull/926?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai).


Patch:
diff --git a/internal/database/offline/sqlutil/join.go b/internal/database/offline/sqlutil/join.go
index 8e93a6e2..6848783b 100644
--- a/internal/database/offline/sqlutil/join.go
+++ b/internal/database/offline/sqlutil/join.go
@@ -233,7 +233,7 @@ func ReadJoinedTable(ctx context.Context, dbOpt dbutil.DBOpt, opt ReadJoinedTabl
 	tableNames = append([]string{opt.EntityRowsTableName}, tableNames...)
 	for i := 0; i < len(tableNames)-1; i++ {
 		joinTablePairs = append(joinTablePairs, joinTablePair{
-			LeftTable:  tableNames[i],
+			LeftTable:  tableNames[0],
 			RightTable: tableNames[i+1],
 		})
 	}
@@ -290,7 +290,6 @@ func sqlxQueryResults(ctx context.Context, dbOpt dbutil.DBOpt, query string, hea
 				deserializedValue, err := dbutil.DeserializeByValueType(r, header[i].ValueType, backendType)
 				if err != nil {
 					scanErr = err
-					continue
 				}
 				serializedRecord = append(serializedRecord, deserializedValue)
 			}
diff --git a/internal/database/offline/sqlutil/join_helper.go b/internal/database/offline/sqlutil/join_helper.go
index 38f4c238..1a94e107 100644
--- a/internal/database/offline/sqlutil/join_helper.go
+++ b/internal/database/offline/sqlutil/join_helper.go
@@ -65,7 +65,7 @@ FROM {{ qt .EntityRowsTableName }}
 {{ range $pair := .JoinTables }}
 	{{- $t1 := qt $pair.LeftTable -}}
 	{{- $t2 := qt $pair.RightTable -}}
-lEFT JOIN {{ $t2 }}
+LEFT JOIN {{ $t2 }}
 ON {{ $t1 }}.{{ qt $.UnixMilli }} = {{ $t2 }}.{{ qt $.UnixMilli }} AND {{ $t1 }}.{{ qt $.EntityKey }} = {{ $t2 }}.{{ qt $.EntityKey }}
 {{end}}`
 


Test patch:
diff --git a/internal/database/offline/test_impl/join.go b/internal/database/offline/test_impl/join.go
index fb550314..b121f401 100644
--- a/internal/database/offline/test_impl/join.go
+++ b/internal/database/offline/test_impl/join.go
@@ -186,7 +186,7 @@ func prepareFeatures(oneGroup bool) (types.FeatureList, map[string]types.Feature
 func prepareRevisionRanges(oneGroup bool, stream bool) map[string][]*offline.RevisionRange {
 	basic := []*offline.RevisionRange{
 		{
-			MinRevision:   1,
+			MinRevision:   5,
 			MaxRevision:   15,
 			SnapshotTable: "offline_snapshot_1_1",
 		},
@@ -198,7 +198,7 @@ func prepareRevisionRanges(oneGroup bool, stream bool) map[string][]*offline.Rev
 	}
 	advanced := []*offline.RevisionRange{
 		{
-			MinRevision:   5,
+			MinRevision:   1,
 			MaxRevision:   math.MaxInt64,
 			SnapshotTable: "offline_snapshot_2_1",
 		},
@@ -222,6 +222,11 @@ func prepareRevisionRanges(oneGroup bool, stream bool) map[string][]*offline.Rev
 func prepareEntityRows(isEmpty bool, withValue bool) <-chan types.EntityRow {
 	entityRows := make(chan types.EntityRow)
 	rows := []types.EntityRow{
+		{
+			EntityKey: "1234",
+			UnixMilli: 2,
+			Values:    []string{"1", "2"},
+		},
 		{
 			EntityKey: "1234",
 			UnixMilli: 10,
@@ -299,6 +304,15 @@ func prepareEmptyResult() *types.JoinResult {
 }
 func prepareStreamingResultValues() []map[string]interface{} {
 	return []map[string]interface{}{
+		{
+			"entity_key":                "1234",
+			"unix_milli":                int64(2),
+			"value_1":                   "1",
+			"value_2":                   "2",
+			"device_basic.model":        nil,
+			"device_basic.price":        nil,
+			"device_advanced.is_active": true,
+		},
 		{
 			"entity_key":                "1234",
 			"unix_milli":                int64(10),
@@ -340,6 +354,15 @@ func prepareStreamingResultValues() []map[string]interface{} {
 
 func prepareBatchResultValues() []map[string]interface{} {
 	return []map[string]interface{}{
+		{
+			"entity_key":                "1234",
+			"unix_milli":                int64(2),
+			"value_1":                   "1",
+			"value_2":                   "2",
+			"device_basic.model":        nil,
+			"device_basic.price":        nil,
+			"device_advanced.is_active": true,
+		},
 		{
 			"entity_key":                "1234",
 			"unix_milli":                int64(10),