Github user vrozov commented on a diff in the pull request:

    https://github.com/apache/drill/pull/1111#discussion_r166838809
  
    --- Diff: 
contrib/storage-hive/core/src/main/java/org/apache/drill/exec/store/hive/HiveUtilities.java
 ---
    @@ -507,5 +512,49 @@ public static boolean 
hasHeaderOrFooter(HiveTableWithColumnCache table) {
         int skipFooter = retrieveIntProperty(tableProperties, 
serdeConstants.FOOTER_COUNT, -1);
         return skipHeader > 0 || skipFooter > 0;
       }
    +
    +  /**
    +   * This method checks whether the table is transactional and set 
necessary properties in {@link JobConf}.
    +   * If schema evolution properties aren't set in job conf for the input 
format, method sets the column names
    +   * and types from table/partition properties or storage descriptor.
    +   *
    +   * @param job the job to update
    +   * @param properties table or partition properties
    +   * @param sd storage descriptor
    +   */
    +  public static void verifyAndAddTransactionalProperties(JobConf job, 
StorageDescriptor sd) {
    +
    +    if (AcidUtils.isTablePropertyTransactional(job)) {
    +      AcidUtils.setTransactionalTableScan(job, true);
    +
    +      // No work is needed, if schema evolution is used
    +      if (Utilities.isSchemaEvolutionEnabled(job, true) && 
job.get(IOConstants.SCHEMA_EVOLUTION_COLUMNS) != null &&
    +          job.get(IOConstants.SCHEMA_EVOLUTION_COLUMNS_TYPES) != null) {
    +        return;
    +      }
    +
    +      String colNames;
    +      String colTypes;
    +
    +      // Try to get get column names and types from table or partition 
properties. If they are absent there, get columns
    +      // data from storage descriptor of the table
    +      colNames = job.get(serdeConstants.LIST_COLUMNS);
    +      colTypes = job.get(serdeConstants.LIST_COLUMN_TYPES);
    +
    +      if (colNames == null || colTypes == null) {
    +        List<String> colNamesList = Lists.newArrayList();
    +        List<String> colTypesList = Lists.newArrayList();
    +        for (FieldSchema col: sd.getCols()) {
    +          colNamesList.add(col.getName());
    +          colTypesList.add(col.getType());
    +        }
    +        colNames = Joiner.on(",").join(colNamesList);
    --- End diff --
    
    Consider `Joiner.on(",").join(Iterables.transform(sd.getCols(), toName));` 
where `toName` is 
    ```
      private static Function<FieldSchema, String> toName = new 
Function<FieldSchema, String>()
      {
        @Nullable
        @Override
        public String apply(@Nullable FieldSchema input)
        {
          return input.getName();
        }
      };
    ```



---

Reply via email to