From c0a45e9241d241a292f5164eacfaf056b6baf7b3 Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Thu, 19 Sep 2024 10:52:56 -0700 Subject: [PATCH] Clean up tests. --- ...st.go => table_data_merge_columns_test.go} | 65 ++++++++----------- lib/typing/ext/time.go | 2 + 2 files changed, 30 insertions(+), 37 deletions(-) rename lib/optimization/{event_update_test.go => table_data_merge_columns_test.go} (83%) diff --git a/lib/optimization/event_update_test.go b/lib/optimization/table_data_merge_columns_test.go similarity index 83% rename from lib/optimization/event_update_test.go rename to lib/optimization/table_data_merge_columns_test.go index 1298afd4d..ffaff9321 100644 --- a/lib/optimization/event_update_test.go +++ b/lib/optimization/table_data_merge_columns_test.go @@ -14,49 +14,48 @@ const strCol = "string" func TestTableData_UpdateInMemoryColumnsFromDestination(t *testing.T) { { + // Trying to merge an invalid destination column tableDataCols := &columns.Columns{} - tableData := &TableData{ - inMemoryColumns: tableDataCols, - } - + tableData := &TableData{inMemoryColumns: tableDataCols} tableData.AddInMemoryCol(columns.NewColumn("foo", typing.String)) invalidCol := columns.NewColumn("foo", typing.Invalid) assert.ErrorContains(t, tableData.MergeColumnsFromDestination(invalidCol), `column "foo" is invalid`) } { - // If the in-memory column is a string and the destination column is Date - // We should mark the in-memory column as date and try to parse it accordingly. + // In-memory column is a string and the destination column is a Date tableDataCols := &columns.Columns{} - tableData := &TableData{ - inMemoryColumns: tableDataCols, - } - + tableData := &TableData{inMemoryColumns: tableDataCols} tableData.AddInMemoryCol(columns.NewColumn("foo", typing.String)) extTime := typing.ETime - extTime.ExtendedTimeDetails = &ext.NestedKind{ - Type: ext.DateKindType, - } - + extTime.ExtendedTimeDetails = &ext.Date tsCol := columns.NewColumn("foo", extTime) assert.NoError(t, tableData.MergeColumnsFromDestination(tsCol)) - col, isOk := tableData.inMemoryColumns.GetColumn("foo") + updatedColumn, isOk := tableData.inMemoryColumns.GetColumn("foo") assert.True(t, isOk) - assert.Equal(t, typing.ETime.Kind, col.KindDetails.Kind) - assert.Equal(t, ext.DateKindType, col.KindDetails.ExtendedTimeDetails.Type) - assert.Equal(t, extTime.ExtendedTimeDetails, col.KindDetails.ExtendedTimeDetails) + assert.Equal(t, typing.ETime.Kind, updatedColumn.KindDetails.Kind) + assert.Equal(t, ext.DateKindType, updatedColumn.KindDetails.ExtendedTimeDetails.Type) + // Format is not copied over. + assert.Equal(t, "", updatedColumn.KindDetails.ExtendedTimeDetails.Format) } { tableDataCols := &columns.Columns{} - tableData := &TableData{ - inMemoryColumns: tableDataCols, + tableData := &TableData{inMemoryColumns: tableDataCols} + + { + // In-memory column is NUMERIC and destination column is an INTEGER + tableDataCols.AddColumn(columns.NewColumn("numeric_test", typing.EDecimal)) + assert.NoError(t, tableData.MergeColumnsFromDestination(columns.NewColumn("numeric_test", typing.Integer))) + + numericCol, isOk := tableData.inMemoryColumns.GetColumn("numeric_test") + assert.True(t, isOk) + assert.Equal(t, typing.Integer.Kind, numericCol.KindDetails.Kind) } tableDataCols.AddColumn(columns.NewColumn("name", typing.String)) tableDataCols.AddColumn(columns.NewColumn("bool_backfill", typing.Boolean)) tableDataCols.AddColumn(columns.NewColumn("prev_invalid", typing.Invalid)) - tableDataCols.AddColumn(columns.NewColumn("numeric_test", typing.EDecimal)) // Casting these as STRING so tableColumn via this f(x) will set it correctly. tableDataCols.AddColumn(columns.NewColumn("ext_date", typing.String)) @@ -82,12 +81,6 @@ func TestTableData_UpdateInMemoryColumnsFromDestination(t *testing.T) { assert.False(t, isOk, nonExistentTableCol) } - // Making sure it's still numeric - assert.NoError(t, tableData.MergeColumnsFromDestination(columns.NewColumn("numeric_test", typing.Integer))) - numericCol, isOk := tableData.inMemoryColumns.GetColumn("numeric_test") - assert.True(t, isOk) - assert.Equal(t, typing.EDecimal.Kind, numericCol.KindDetails.Kind, "numeric_test") - // Testing to make sure we're copying the kindDetails over. assert.NoError(t, tableData.MergeColumnsFromDestination(columns.NewColumn("prev_invalid", typing.String))) prevInvalidCol, isOk := tableData.inMemoryColumns.GetColumn("prev_invalid") @@ -169,20 +162,18 @@ func TestTableData_UpdateInMemoryColumnsFromDestination(t *testing.T) { assert.Equal(t, int32(2), extDecColFilled.KindDetails.ExtendedDecimalDetails.Scale()) } { + // String (precision being copied over) tableDataCols := &columns.Columns{} - tableData := &TableData{ - inMemoryColumns: tableDataCols, - } + tableData := &TableData{inMemoryColumns: tableDataCols} tableDataCols.AddColumn(columns.NewColumn(strCol, typing.String)) + assert.NoError(t, tableData.MergeColumnsFromDestination(columns.NewColumn(strCol, + typing.KindDetails{ + Kind: typing.String.Kind, + OptionalStringPrecision: typing.ToPtr(int32(123)), + }), + )) - // Testing string precision - stringKindWithPrecision := typing.KindDetails{ - Kind: typing.String.Kind, - OptionalStringPrecision: typing.ToPtr(int32(123)), - } - - assert.NoError(t, tableData.MergeColumnsFromDestination(columns.NewColumn(strCol, stringKindWithPrecision))) foundStrCol, isOk := tableData.inMemoryColumns.GetColumn(strCol) assert.True(t, isOk) assert.Equal(t, typing.String.Kind, foundStrCol.KindDetails.Kind) diff --git a/lib/typing/ext/time.go b/lib/typing/ext/time.go index 333e67fb5..5971a8715 100644 --- a/lib/typing/ext/time.go +++ b/lib/typing/ext/time.go @@ -5,6 +5,8 @@ import ( "time" ) +// TODO: This package should have a concept of default formats for each type. + type ExtendedTimeKindType string const (