You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "zhoukui (Jira)" <ji...@apache.org> on 2021/01/12 06:57:00 UTC

[jira] [Updated] (FLINK-20936) Improvements in custom partition extractor

     [ https://issues.apache.org/jira/browse/FLINK-20936?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

zhoukui updated FLINK-20936:
----------------------------
    Description: 
In flink1.12.0, I saw PartitionTimeExtractor is a constructor without parameters, why not take the parameter “extractorPattern". See the source code below:

@Experimental
 public interface PartitionTimeExtractor extends Serializable {

String DEFAULT = "default";
 String CUSTOM = "custom";

/**
 * Extract time from partition keys and values.
 */
 LocalDateTime extract(List<String> partitionKeys, List<String> partitionValues);

static PartitionTimeExtractor create(
 ClassLoader userClassLoader,
 String extractorKind,
 String extractorClass,
 String extractorPattern) {
 switch (extractorKind) {
 case DEFAULT:
 return new DefaultPartTimeExtractor(extractorPattern);
 case CUSTOM:
 try

{ Class<?> aClass = userClassLoader.loadClass(extractorClass); return (PartitionTimeExtractor) aClass.newInstance(); }

catch (ClassNotFoundException | IllegalAccessException | InstantiationException e)

{ throw new RuntimeException( "Can not new instance for custom class from " + extractorClass, e); }

default:
 throw new UnsupportedOperationException(
 "Unsupported extractor kind: " + extractorKind);
 }
 }
 }

 

Would it be more reasonable to bring a construction method? as follows:

try {
 Class<?> aClass = userClassLoader.loadClass(extractorClass);
 Constructor<?> declaredConstructor = aClass.getDeclaredConstructor(String.class);
 return (PartitionTimeExtractor) declaredConstructor.newInstance(extractorPattern);
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
 throw new RuntimeException(
 "Can not new instance for custom class from " + extractorClass, e);
}

 

  was:
In flink1.12.0, I saw PartitionTimeExtractor is a constructor without parameters, why not take the parameter “extractorPattern". See the source code below:

@Experimental
public interface PartitionTimeExtractor extends Serializable {

 String DEFAULT = "default";
 String CUSTOM = "custom";

 /**
 * Extract time from partition keys and values.
 */
 LocalDateTime extract(List<String> partitionKeys, List<String> partitionValues);

 static PartitionTimeExtractor create(
 ClassLoader userClassLoader,
 String extractorKind,
 String extractorClass,
 String extractorPattern) {
 switch (extractorKind) {
 case DEFAULT:
 return new DefaultPartTimeExtractor(extractorPattern);
 case CUSTOM:
 try {
 Class<?> aClass = userClassLoader.loadClass(extractorClass);
 return (PartitionTimeExtractor) aClass.newInstance();
 } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
 throw new RuntimeException(
 "Can not new instance for custom class from " + extractorClass, e);
 }
 default:
 throw new UnsupportedOperationException(
 "Unsupported extractor kind: " + extractorKind);
 }
 }
}

 

Would it be more reasonable to bring a construction method? as follows:

Constructor<?> declaredConstructor = aClass.getDeclaredConstructor(String.class);
return (PartitionTimeExtractor) declaredConstructor.newInstance(extractorPattern);

 


>  Improvements in custom partition extractor
> -------------------------------------------
>
>                 Key: FLINK-20936
>                 URL: https://issues.apache.org/jira/browse/FLINK-20936
>             Project: Flink
>          Issue Type: Improvement
>          Components: Connectors / Hive
>    Affects Versions: 1.12.0
>         Environment: flink 1.12.0
> jdk 1.8
>            Reporter: zhoukui
>            Priority: Minor
>
> In flink1.12.0, I saw PartitionTimeExtractor is a constructor without parameters, why not take the parameter “extractorPattern". See the source code below:
> @Experimental
>  public interface PartitionTimeExtractor extends Serializable {
> String DEFAULT = "default";
>  String CUSTOM = "custom";
> /**
>  * Extract time from partition keys and values.
>  */
>  LocalDateTime extract(List<String> partitionKeys, List<String> partitionValues);
> static PartitionTimeExtractor create(
>  ClassLoader userClassLoader,
>  String extractorKind,
>  String extractorClass,
>  String extractorPattern) {
>  switch (extractorKind) {
>  case DEFAULT:
>  return new DefaultPartTimeExtractor(extractorPattern);
>  case CUSTOM:
>  try
> { Class<?> aClass = userClassLoader.loadClass(extractorClass); return (PartitionTimeExtractor) aClass.newInstance(); }
> catch (ClassNotFoundException | IllegalAccessException | InstantiationException e)
> { throw new RuntimeException( "Can not new instance for custom class from " + extractorClass, e); }
> default:
>  throw new UnsupportedOperationException(
>  "Unsupported extractor kind: " + extractorKind);
>  }
>  }
>  }
>  
> Would it be more reasonable to bring a construction method? as follows:
> try {
>  Class<?> aClass = userClassLoader.loadClass(extractorClass);
>  Constructor<?> declaredConstructor = aClass.getDeclaredConstructor(String.class);
>  return (PartitionTimeExtractor) declaredConstructor.newInstance(extractorPattern);
> } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
>  throw new RuntimeException(
>  "Can not new instance for custom class from " + extractorClass, e);
> }
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)