1717package com .google .cloud .spanner .spi .v1 ;
1818
1919import static org .junit .Assert .assertEquals ;
20+ import static org .junit .Assert .assertFalse ;
2021import static org .junit .Assert .assertTrue ;
2122
2223import com .google .protobuf .ByteString ;
@@ -76,6 +77,59 @@ public void queryParamsUsesConstantValue() throws Exception {
7677 assertTrue (target .limit .isEmpty ());
7778 }
7879
80+ @ Test
81+ public void queryParamsCaseInsensitiveFallback () throws Exception {
82+ com .google .spanner .v1 .KeyRecipe recipeProto =
83+ createRecipe (
84+ "part { tag: 1 }\n "
85+ + "part {\n "
86+ + " order: ASCENDING\n "
87+ + " null_order: NULLS_FIRST\n "
88+ + " type { code: STRING }\n "
89+ + " identifier: \" id\" \n "
90+ + "}\n " );
91+
92+ Struct params =
93+ parseStruct (
94+ "fields {\n " + " key: \" Id\" \n " + " value { string_value: \" foo\" }\n " + "}\n " );
95+
96+ KeyRecipe recipe = KeyRecipe .create (recipeProto );
97+ TargetRange target = recipe .queryParamsToTargetRange (params );
98+ assertEquals (expectedKey ("foo" ), target .start );
99+ assertTrue (target .limit .isEmpty ());
100+ }
101+
102+ @ Test
103+ public void queryParamsCaseInsensitiveDuplicateUsesLastValue () throws Exception {
104+ com .google .spanner .v1 .KeyRecipe recipeProto =
105+ createRecipe (
106+ "part { tag: 1 }\n "
107+ + "part {\n "
108+ + " order: ASCENDING\n "
109+ + " null_order: NULLS_FIRST\n "
110+ + " type { code: STRING }\n "
111+ + " identifier: \" ID\" \n "
112+ + "}\n " );
113+
114+ // Both "Id" and "id" normalize to "id"; the last one ("id"→"bar") wins.
115+ Struct params =
116+ parseStruct (
117+ "fields {\n "
118+ + " key: \" Id\" \n "
119+ + " value { string_value: \" foo\" }\n "
120+ + "}\n "
121+ + "fields {\n "
122+ + " key: \" id\" \n "
123+ + " value { string_value: \" bar\" }\n "
124+ + "}\n " );
125+
126+ KeyRecipe recipe = KeyRecipe .create (recipeProto );
127+ TargetRange target = recipe .queryParamsToTargetRange (params );
128+ assertEquals (expectedKey ("bar" ), target .start );
129+ assertFalse (target .approximate );
130+ assertTrue (target .limit .isEmpty ());
131+ }
132+
79133 private static com .google .spanner .v1 .KeyRecipe createRecipe (String text )
80134 throws TextFormat .ParseException {
81135 com .google .spanner .v1 .KeyRecipe .Builder builder = com .google .spanner .v1 .KeyRecipe .newBuilder ();
@@ -96,4 +150,10 @@ private static ByteString expectedKey(String value) {
96150 SsFormat .appendStringIncreasing (out , value );
97151 return ByteString .copyFrom (out .toByteArray ());
98152 }
153+
154+ private static ByteString expectedTagOnlyKey () {
155+ UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream ();
156+ SsFormat .appendCompositeTag (out , 1 );
157+ return ByteString .copyFrom (out .toByteArray ());
158+ }
99159}
0 commit comments