[ 
https://issues.apache.org/jira/browse/BEAM-7590?focusedWorklogId=269382&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-269382
 ]

ASF GitHub Bot logged work on BEAM-7590:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 28/Jun/19 16:49
            Start Date: 28/Jun/19 16:49
    Worklog Time Spent: 10m 
      Work Description: riazela commented on pull request #8928: [DO NOT MERGE] 
[BEAM-7590] Converting JDBC Pipeline Options Map to PipelineOptions.
URL: https://github.com/apache/beam/pull/8928#discussion_r298671093
 
 

 ##########
 File path: 
sdks/java/core/src/main/java/org/apache/beam/sdk/options/PipelineOptionsReflectionSetter.java
 ##########
 @@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.options;
+
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import org.apache.beam.sdk.util.StringUtils;
+import 
org.apache.beam.vendor.guava.v20_0.com.google.common.collect.ImmutableListMultimap;
+import org.apache.beam.vendor.guava.v20_0.com.google.common.collect.Iterables;
+import 
org.apache.beam.vendor.guava.v20_0.com.google.common.collect.ListMultimap;
+import org.apache.beam.vendor.guava.v20_0.com.google.common.collect.Sets;
+
+/** This is a utility class to set and remove options individually. */
+public class PipelineOptionsReflectionSetter {
+  private static final boolean STRICT_PARSING = true;
+
+  @SuppressWarnings("unchecked")
+  public static Class<? extends PipelineOptions> getPipelineOptionsInterface(
+      PipelineOptions options) {
+    if (options.getClass().getInterfaces().length != 1) {
 
 Review comment:
   If I call options.getClass() it will not return DataflowPipelineOptions, it 
will return a proxy class. For instance BigQueryOptions also extends multiple 
interfaces (Similar to DataflowPipelineOptions); however, if I run the 
following code:
   
       BigQueryOptions options = 
PipelineOptionsFactory.as(BigQueryOptions.class);
       System.out.println(options.getClass());
       System.out.println(options.getClass().isInterface());
       
System.out.println(PipelineOptionsReflectionSetter.getPipelineOptionsInterface(options));
   
   There will be no exception and the output will be:
       class com.sun.proxy.$Proxy25
       false
       interface org.apache.beam.sdk.io.gcp.bigquery.BigQueryOptions
   
   The reason that I need this method is when the user tries to use reset 
command, I should set it to its default value. In order to do that, first I try 
to see what type of pipelineOptions this object is implementing and then using 
PipelineOptionsFactory I construct an instance of that options and get its 
default value. 
   
   Currently with our use cases and the expected behavior of 
PipelineOptionsFactory, this should not fail in any use case. Because the 
method .as() in PipelineOptions and PipelineOptionsFactory returns a proxy 
object that implements one interface. I think currently, if the user needs its 
own piplineOptions they need to declare an interface extending PipelineOptions 
and then use PipelineOptionsFactory to create an instance of it. 
   
   Hope this makes sense.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 269382)
    Time Spent: 3h 50m  (was: 3h 40m)

> Convert PipelineOptionsMap to PipelineOption
> --------------------------------------------
>
>                 Key: BEAM-7590
>                 URL: https://issues.apache.org/jira/browse/BEAM-7590
>             Project: Beam
>          Issue Type: Improvement
>          Components: dsl-sql
>            Reporter: Alireza Samadianzakaria
>            Assignee: Alireza Samadianzakaria
>            Priority: Minor
>          Time Spent: 3h 50m
>  Remaining Estimate: 0h
>
> Currently, BeamCalciteTable keeps a map version of PipelineOptions and that 
> map version is used in JDBCConnection and RelNodes as well. This map is empty 
> when the pipeline is constructed from SQLTransform and it will have the 
> parameters passed from JDBC Client when the pipeline is started by JDBC path. 
> Since for Row-Count estimation we need to use PipelineOptions (or its 
> sub-classes) and we cannot convert a map that is created from a 
> pipelineOptions Subclasses back to PipelineOptions, it is better to keep 
> PipelineOptions object itself.
> Another thing that will be changed as a result is set command. Currently, if 
> in JDBC we use Set Command for a pipeline option, it will only change that 
> option in the map. This means even if the option is incorrect, it does not 
> throw exception until it creates the actual Pipeline Options. However, if we 
> are keeping the PipelineOptions class itself, then wee need to actually set 
> the passed parameters (using reflection) which will throw exception at the 
> time of setting them. 
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to