@@ -68,8 +68,17 @@ private static final class Part {
6868 private final com .google .spanner .v1 .KeyRecipe .Part .NullOrder nullOrder ; // if kind == VALUE
6969 private final String identifier ; // if kind == VALUE
7070 private final List <Integer > structIdentifiers ; // if kind == VALUE
71+ private final Value constantValue ; // if kind == VALUE and value is set
7172 private final boolean random ; // if kind == VALUE and random: true
7273
74+ private Value constantValue () {
75+ return constantValue ;
76+ }
77+
78+ private boolean hasConstantValue () {
79+ return constantValue != null ;
80+ }
81+
7382 private Part (
7483 Kind kind ,
7584 int tag ,
@@ -78,6 +87,7 @@ private Part(
7887 com .google .spanner .v1 .KeyRecipe .Part .NullOrder nullOrder ,
7988 String identifier ,
8089 List <Integer > structIdentifiers ,
90+ Value constantValue ,
8191 boolean random ) {
8292 this .kind = kind ;
8393 this .tag = tag ;
@@ -86,10 +96,14 @@ private Part(
8696 this .nullOrder = nullOrder ;
8797 this .identifier = identifier ;
8898 this .structIdentifiers = structIdentifiers ;
99+ this .constantValue = constantValue ;
89100 this .random = random ;
90101 }
91102
92103 private ResolvedValue resolveValue (BiFunction <Integer , String , Value > valueFinder , int index ) {
104+ if (hasConstantValue ()) {
105+ return ResolvedValue .ofValue (constantValue ());
106+ }
93107 Value value = valueFinder .apply (index , identifier == null ? "" : identifier );
94108 if (value == null ) {
95109 return ResolvedValue .missing ();
@@ -112,36 +126,38 @@ private ResolvedValue resolveValue(BiFunction<Integer, String, Value> valueFinde
112126 }
113127
114128 private boolean shouldConsumeValueIndex () {
115- return !random ;
129+ return !hasConstantValue () && ! random ;
116130 }
117131
118132 static Part fromProto (com .google .spanner .v1 .KeyRecipe .Part partProto ) {
119133 if (partProto .getTag () != 0 ) {
120134 if (partProto .getTag () < 0 ) {
121- return new Part (Kind .INVALID , 0 , null , null , null , null , null , false );
135+ return new Part (Kind .INVALID , 0 , null , null , null , null , null , null , false );
122136 }
123- return new Part (Kind .TAG , partProto .getTag (), null , null , null , null , null , false );
137+ return new Part (Kind .TAG , partProto .getTag (), null , null , null , null , null , null , false );
124138 }
125139 if (!partProto .hasType ()) {
126- return new Part (Kind .INVALID , 0 , null , null , null , null , null , false );
140+ return new Part (Kind .INVALID , 0 , null , null , null , null , null , null , false );
127141 }
128142 if (partProto .getOrder () != com .google .spanner .v1 .KeyRecipe .Part .Order .ASCENDING
129143 && partProto .getOrder () != com .google .spanner .v1 .KeyRecipe .Part .Order .DESCENDING ) {
130- return new Part (Kind .INVALID , 0 , null , null , null , null , null , false );
144+ return new Part (Kind .INVALID , 0 , null , null , null , null , null , null , false );
131145 }
132146 if (partProto .getNullOrder () != com .google .spanner .v1 .KeyRecipe .Part .NullOrder .NULLS_FIRST
133147 && partProto .getNullOrder () != com .google .spanner .v1 .KeyRecipe .Part .NullOrder .NULLS_LAST
134148 && partProto .getNullOrder () != com .google .spanner .v1 .KeyRecipe .Part .NullOrder .NOT_NULL ) {
135- return new Part (Kind .INVALID , 0 , null , null , null , null , null , false );
149+ return new Part (Kind .INVALID , 0 , null , null , null , null , null , null , false );
136150 }
137151 if (partProto .hasRandom ()
138152 && partProto .getType ().getCode () != com .google .spanner .v1 .TypeCode .INT64 ) {
139- return new Part (Kind .INVALID , 0 , null , null , null , null , null , false );
153+ return new Part (Kind .INVALID , 0 , null , null , null , null , null , null , false );
140154 }
141155
142156 String identifier = partProto .hasIdentifier () ? partProto .getIdentifier () : null ;
143157 List <Integer > structIdentifiers = new ArrayList <>(partProto .getStructIdentifiersList ());
144158
159+ Value constantValue = partProto .hasValue () ? partProto .getValue () : null ;
160+
145161 return new Part (
146162 Kind .VALUE ,
147163 0 ,
@@ -150,6 +166,7 @@ static Part fromProto(com.google.spanner.v1.KeyRecipe.Part partProto) {
150166 partProto .getNullOrder (),
151167 identifier ,
152168 structIdentifiers ,
169+ constantValue ,
153170 partProto .hasRandom ());
154171 }
155172 }
0 commit comments