@@ -2198,13 +2198,51 @@ private Status executeGenerateDbPartitionsRead(
21982198 }
21992199
22002200 /** Execute action that generates database partitions for the given query. */
2201+
2202+ private Options .ReadQueryUpdateTransactionOption buildSecureContextOption (
2203+ Map <String , com .google .spanner .executor .v1 .Value > secureContextMap ) {
2204+ if (secureContextMap != null && !secureContextMap .isEmpty ()) {
2205+ com .google .spanner .v1 .RequestOptions .ClientContext .Builder clientContextBuilder =
2206+ com .google .spanner .v1 .RequestOptions .ClientContext .newBuilder ();
2207+ for (Map .Entry <String , com .google .spanner .executor .v1 .Value > entry :
2208+ secureContextMap .entrySet ()) {
2209+ com .google .protobuf .Value .Builder valueBuilder = com .google .protobuf .Value .newBuilder ();
2210+ if (entry .getValue ().getValueTypeCase () == com .google .spanner .executor .v1 .Value .ValueTypeCase .IS_NULL
2211+ && entry .getValue ().getIsNull ()) {
2212+ valueBuilder .setNullValue (com .google .protobuf .NullValue .NULL_VALUE );
2213+ } else if (entry .getValue ().getValueTypeCase () == com .google .spanner .executor .v1 .Value .ValueTypeCase .STRING_VALUE ) {
2214+ valueBuilder .setStringValue (entry .getValue ().getStringValue ());
2215+ } else {
2216+ throw new IllegalArgumentException ("Unsupported secure parameter value type in executor proxy" );
2217+ }
2218+ clientContextBuilder .putSecureContext (entry .getKey (), valueBuilder .build ());
2219+ }
2220+ return Options .clientContext (clientContextBuilder .build ());
2221+ }
2222+ return null ;
2223+ }
2224+
2225+ @ SuppressWarnings ("unchecked" )
2226+ private <T > void addSecureContextOption (
2227+ Map <String , com .google .spanner .executor .v1 .Value > secureContextMap ,
2228+ List <T > optionsList ,
2229+ Class <?> optionClass ) {
2230+ Options .ReadQueryUpdateTransactionOption secureContextOption =
2231+ buildSecureContextOption (secureContextMap );
2232+ if (secureContextOption != null && optionClass .isInstance (secureContextOption )) {
2233+ optionsList .add ((T ) secureContextOption );
2234+ }
2235+ }
2236+
22012237 private Status executeGenerateDbPartitionsQuery (
22022238 GenerateDbPartitionsForQueryAction action ,
22032239 OutcomeSender sender ,
22042240 ExecutionFlowContext executionContext ) {
22052241 try {
22062242 BatchReadOnlyTransaction batchTxn = executionContext .getBatchTxn ();
22072243 Statement .Builder stmt = Statement .newBuilder (action .getQuery ().getSql ());
2244+ List <Options .QueryOption > queryOptions = new ArrayList <>();
2245+ addSecureContextOption (action .getQuery ().getSecureContextMap (), queryOptions , Options .QueryOption .class );
22082246 for (int i = 0 ; i < action .getQuery ().getParamsCount (); ++i ) {
22092247 stmt .bind (action .getQuery ().getParams (i ).getName ())
22102248 .to (
@@ -2216,7 +2254,7 @@ private Status executeGenerateDbPartitionsQuery(
22162254 PartitionOptions .newBuilder ()
22172255 .setPartitionSizeBytes (action .getDesiredBytesPerPartition ())
22182256 .build ();
2219- List <Partition > parts = batchTxn .partitionQuery (partitionOptions , stmt .build ());
2257+ List <Partition > parts = batchTxn .partitionQuery (partitionOptions , stmt .build (), queryOptions . toArray ( new Options . QueryOption [ 0 ]) );
22202258 List <BatchPartition > batchPartitions = new ArrayList <>();
22212259 for (Partition part : parts ) {
22222260 batchPartitions .add (
@@ -2282,11 +2320,14 @@ private Status executePartitionedUpdate(
22822320 PartitionedUpdateAction action , DatabaseClient dbClient , OutcomeSender sender ) {
22832321 try {
22842322 ExecutePartitionedUpdateOptions options = action .getOptions ();
2323+ List <Options .UpdateOption > optionsList = new ArrayList <>();
2324+ optionsList .add (Options .tag (options .getTag ()));
2325+ optionsList .add (Options .priority (RpcPriority .fromProto (options .getRpcPriority ())));
2326+ addSecureContextOption (action .getUpdate ().getSecureContextMap (), optionsList , Options .UpdateOption .class );
22852327 Long count =
22862328 dbClient .executePartitionedUpdate (
22872329 Statement .of (action .getUpdate ().getSql ()),
2288- Options .tag (options .getTag ()),
2289- Options .priority (RpcPriority .fromProto (options .getRpcPriority ())));
2330+ optionsList .toArray (new Options .UpdateOption [0 ]));
22902331 SpannerActionOutcome outcome =
22912332 SpannerActionOutcome .newBuilder ()
22922333 .setStatus (toProto (Status .OK ))
@@ -2739,7 +2780,10 @@ private Status executeQuery(
27392780 String .format (
27402781 "Finish query building, ready to execute %s\n " ,
27412782 executionContext .getTransactionSeed ()));
2742- ResultSet result = txn .executeQuery (stmt .build (), Options .tag ("query-tag" ));
2783+ List <Options .QueryOption > queryOptions = new ArrayList <>();
2784+ queryOptions .add (Options .tag ("query-tag" ));
2785+ addSecureContextOption (action .getSecureContextMap (), queryOptions , Options .QueryOption .class );
2786+ ResultSet result = txn .executeQuery (stmt .build (), queryOptions .toArray (new Options .QueryOption [0 ]));
27432787 LOGGER .log (
27442788 Level .INFO ,
27452789 String .format ("Parsing query result %s\n " , executionContext .getTransactionSeed ()));
0 commit comments