@@ -4958,37 +4958,43 @@ func TestIntegration_DataMaterializedView(t *testing.T) {
49584958 // in case the client fails
49594959 defer deleteTable (ctx , t , adminClient , tblConf .TableID )
49604960
4961+ client , err := testEnv .NewClient ()
4962+ if err != nil {
4963+ t .Fatalf ("NewClient: %v" , err )
4964+ }
4965+ defer client .Close ()
4966+
4967+ // Populate table
4968+ tbl := client .OpenTable (tblConf .TableID )
4969+ mut := NewMutation ()
4970+ mut .Set ("fam1" , "col1" , 1000 , []byte ("1" ))
4971+ if err := tbl .Apply (ctx , "r1" , mut ); err != nil {
4972+ t .Fatalf ("Mutating row: %v" , err )
4973+ }
49614974 // Create materialized view
49624975 materializedViewUUID := uid .NewSpace ("materializedView-" , & uid.Options {})
49634976 materializedView := materializedViewUUID .New ()
49644977 defer instanceAdminClient .DeleteMaterializedView (ctx , testEnv .Config ().Instance , materializedView )
49654978
49664979 materializedViewInfo := MaterializedViewInfo {
49674980 MaterializedViewID : materializedView ,
4968- Query : fmt .Sprintf ("SELECT _key, fam1[col1] as col, count(* ) as count FROM %s " , tblConf .TableID ),
4981+ Query : fmt .Sprintf ("SELECT _key, count( fam1[col1]) as `result. count` FROM `%s` GROUP BY _key " , tblConf .TableID ),
49694982 DeletionProtection : Unprotected ,
49704983 }
49714984 if err = instanceAdminClient .CreateMaterializedView (ctx , testEnv .Config ().Instance , & materializedViewInfo ); err != nil {
49724985 t .Fatalf ("Creating materialized view: %v" , err )
49734986 }
49744987
4975- client , err := testEnv .NewClient ()
4976- if err != nil {
4977- t .Fatalf ("NewClient: %v" , err )
4978- }
4979- defer client .Close ()
49804988 mv := client .OpenMaterializedView (materializedView )
4981- tbl := client .OpenTable (tblConf .TableID )
49824989
49834990 // Test ReadRow
49844991 gotRow , err := mv .ReadRow (ctx , "r1" )
49854992 if err != nil {
49864993 t .Fatalf ("Reading row from a materialized view: %v" , err )
49874994 }
49884995 wantRow := Row {
4989- "fam1" : []ReadItem {
4990- {Row : "r1" , Column : "fam1:col1" , Timestamp : 1000 , Value : []byte ("1" )},
4991- {Row : "r1" , Column : "fam1:col2" , Timestamp : 1000 , Value : []byte ("1" )},
4996+ "result" : []ReadItem {
4997+ {Row : "r1" , Column : "result:count" , Timestamp : 1000 , Value : []byte ("1" )},
49924998 },
49934999 }
49945000 if ! testutil .Equal (gotRow , wantRow ) {
@@ -5015,18 +5021,10 @@ func TestIntegration_DataMaterializedView(t *testing.T) {
50155021 if err = mv .ReadRows (ctx , RowRange {}, f ); err != nil {
50165022 t .Fatalf ("Reading rows from an materialized view: %v" , err )
50175023 }
5018- want := "r1-col1-1,r1-col2-1 "
5024+ want := "r1-col1-1"
50195025 if got := strings .Join (elt , "," ); got != want {
50205026 t .Fatalf ("Error bulk reading from materialized view.\n Got %v\n Want %v" , got , want )
50215027 }
5022- elt = nil
5023- if err = tbl .ReadRows (ctx , RowRange {}, f ); err != nil {
5024- t .Fatalf ("Reading rows from a table: %v" , err )
5025- }
5026- want = "r1-col1-1,r1-col2-1,r2-col1-1"
5027- if got := strings .Join (elt , "," ); got != want {
5028- t .Fatalf ("Error bulk reading from table.\n Got %v\n Want %v" , got , want )
5029- }
50305028
50315029 // Test SampleRowKeys
50325030 if _ , err := mv .SampleRowKeys (ctx ); err != nil {
@@ -5194,7 +5192,7 @@ func TestIntegration_AdminMaterializedView(t *testing.T) {
51945192
51955193 materializedViewInfo := MaterializedViewInfo {
51965194 MaterializedViewID : materializedView ,
5197- Query : fmt .Sprintf ("SELECT _key, fam1[col1] as col FROM %s" , tblConf .TableID ),
5195+ Query : fmt .Sprintf ("SELECT _key, count( fam1[col1]) as count FROM %s GROUP BY _key " , tblConf .TableID ),
51985196 DeletionProtection : Protected ,
51995197 }
52005198 if err = instanceAdminClient .CreateMaterializedView (ctx , testEnv .Config ().Instance , & materializedViewInfo ); err != nil {
0 commit comments