|
17 | 17 | package com.google.cloud.spanner.spi.v1; |
18 | 18 |
|
19 | 19 | import static org.junit.Assert.assertEquals; |
| 20 | +import static org.junit.Assert.assertFalse; |
20 | 21 | import static org.junit.Assert.assertTrue; |
21 | 22 |
|
22 | 23 | import com.google.protobuf.ByteString; |
@@ -76,6 +77,59 @@ public void queryParamsUsesConstantValue() throws Exception { |
76 | 77 | assertTrue(target.limit.isEmpty()); |
77 | 78 | } |
78 | 79 |
|
| 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 | + |
79 | 133 | private static com.google.spanner.v1.KeyRecipe createRecipe(String text) |
80 | 134 | throws TextFormat.ParseException { |
81 | 135 | com.google.spanner.v1.KeyRecipe.Builder builder = com.google.spanner.v1.KeyRecipe.newBuilder(); |
|
0 commit comments