[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-14 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=328279=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-328279
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 15/Oct/19 03:04
Start Date: 15/Oct/19 03:04
Worklog Time Spent: 10m 
  Work Description: jcamachor commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791
 
 
   
 

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:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 328279)
Time Spent: 4h 40m  (was: 4.5h)

> Split text files even if header/footer exists
> -
>
> Key: HIVE-21924
> URL: https://issues.apache.org/jira/browse/HIVE-21924
> Project: Hive
>  Issue Type: Improvement
>  Components: File Formats
>Affects Versions: 2.4.0, 4.0.0, 3.2.0
>Reporter: Prasanth Jayachandran
>Assignee: Mustafa Iman
>Priority: Major
>  Labels: pull-request-available
> Fix For: 4.0.0
>
> Attachments: HIVE-21924.2.patch, HIVE-21924.3.patch, 
> HIVE-21924.4.patch, HIVE-21924.5.patch, HIVE-21924.6.patch, HIVE-21924.patch
>
>  Time Spent: 4h 40m
>  Remaining Estimate: 0h
>
> https://github.com/apache/hive/blob/967a1cc98beede8e6568ce750ebeb6e0d048b8ea/ql/src/java/org/apache/hadoop/hive/ql/io/HiveInputFormat.java#L494-L503
>  
> {code}
> int headerCount = 0;
> int footerCount = 0;
> if (table != null) {
>   headerCount = Utilities.getHeaderCount(table);
>   footerCount = Utilities.getFooterCount(table, conf);
>   if (headerCount != 0 || footerCount != 0) {
> // Input file has header or footer, cannot be splitted.
> HiveConf.setLongVar(conf, ConfVars.MAPREDMINSPLITSIZE, 
> Long.MAX_VALUE);
>   }
> }
> {code}
> this piece of code makes the CSV (or any text files with header/footer) files 
> not splittable if header or footer is present. 
> If only header is present, we can find the offset after first line break and 
> use that to split. Similarly for footer, may be read few KB's of data at the 
> end and find the last line break offset. Use that to determine the data range 
> which can be used for splitting. Few reads during split generation are 
> cheaper than not splitting the file at all.  



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


[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-09 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=325827=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-325827
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 09/Oct/19 17:11
Start Date: 09/Oct/19 17:11
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r333131008
 
 

 ##
 File path: 
ql/src/test/queries/clientpositive/file_with_header_footer_aggregation.q
 ##
 @@ -0,0 +1,94 @@
+set hive.mapred.mode=nonstrict;
+
+dfs ${system:test.dfs.mkdir} ${system:test.tmp.dir};
+dfs -copyFromLocal ../../data/files/header_footer_table_4  
${system:test.tmp.dir}/header_footer_table_4;
+
+CREATE TABLE numbrs (numbr int);
+INSERT INTO numbrs VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), 
(11), (12), (NULL);
+CREATE EXTERNAL TABLE header_footer_table_4 (header_int int, header_name 
string, header_choice varchar(10)) ROW FORMAT DELIMITED FIELDS TERMINATED BY 
',' LOCATION '${system:test.tmp.dir}/header_footer_table_4' tblproperties 
("skip.header.line.count"="1", "skip.footer.line.count"="2");
 
 Review comment:
   ok... got it.
 

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:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 325827)
Time Spent: 4.5h  (was: 4h 20m)

> Split text files even if header/footer exists
> -
>
> Key: HIVE-21924
> URL: https://issues.apache.org/jira/browse/HIVE-21924
> Project: Hive
>  Issue Type: Improvement
>  Components: File Formats
>Affects Versions: 2.4.0, 4.0.0, 3.2.0
>Reporter: Prasanth Jayachandran
>Assignee: Mustafa Iman
>Priority: Major
>  Labels: pull-request-available
> Attachments: HIVE-21924.2.patch, HIVE-21924.3.patch, 
> HIVE-21924.4.patch, HIVE-21924.5.patch, HIVE-21924.6.patch, HIVE-21924.patch
>
>  Time Spent: 4.5h
>  Remaining Estimate: 0h
>
> https://github.com/apache/hive/blob/967a1cc98beede8e6568ce750ebeb6e0d048b8ea/ql/src/java/org/apache/hadoop/hive/ql/io/HiveInputFormat.java#L494-L503
>  
> {code}
> int headerCount = 0;
> int footerCount = 0;
> if (table != null) {
>   headerCount = Utilities.getHeaderCount(table);
>   footerCount = Utilities.getFooterCount(table, conf);
>   if (headerCount != 0 || footerCount != 0) {
> // Input file has header or footer, cannot be splitted.
> HiveConf.setLongVar(conf, ConfVars.MAPREDMINSPLITSIZE, 
> Long.MAX_VALUE);
>   }
> }
> {code}
> this piece of code makes the CSV (or any text files with header/footer) files 
> not splittable if header or footer is present. 
> If only header is present, we can find the offset after first line break and 
> use that to split. Similarly for footer, may be read few KB's of data at the 
> end and find the last line break offset. Use that to determine the data range 
> which can be used for splitting. Few reads during split generation are 
> cheaper than not splitting the file at all.  



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


[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-09 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=325808=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-325808
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 09/Oct/19 16:31
Start Date: 09/Oct/19 16:31
Worklog Time Spent: 10m 
  Work Description: mustafaiman commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r333113836
 
 

 ##
 File path: 
ql/src/test/queries/clientpositive/file_with_header_footer_aggregation.q
 ##
 @@ -0,0 +1,94 @@
+set hive.mapred.mode=nonstrict;
+
+dfs ${system:test.dfs.mkdir} ${system:test.tmp.dir};
+dfs -copyFromLocal ../../data/files/header_footer_table_4  
${system:test.tmp.dir}/header_footer_table_4;
+
+CREATE TABLE numbrs (numbr int);
+INSERT INTO numbrs VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), 
(11), (12), (NULL);
+CREATE EXTERNAL TABLE header_footer_table_4 (header_int int, header_name 
string, header_choice varchar(10)) ROW FORMAT DELIMITED FIELDS TERMINATED BY 
',' LOCATION '${system:test.tmp.dir}/header_footer_table_4' tblproperties 
("skip.header.line.count"="1", "skip.footer.line.count"="2");
 
 Review comment:
   see `skiphf_aggr2.q`
 

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:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 325808)
Time Spent: 4h 20m  (was: 4h 10m)

> Split text files even if header/footer exists
> -
>
> Key: HIVE-21924
> URL: https://issues.apache.org/jira/browse/HIVE-21924
> Project: Hive
>  Issue Type: Improvement
>  Components: File Formats
>Affects Versions: 2.4.0, 4.0.0, 3.2.0
>Reporter: Prasanth Jayachandran
>Assignee: Mustafa Iman
>Priority: Major
>  Labels: pull-request-available
> Attachments: HIVE-21924.2.patch, HIVE-21924.3.patch, 
> HIVE-21924.4.patch, HIVE-21924.5.patch, HIVE-21924.6.patch, HIVE-21924.patch
>
>  Time Spent: 4h 20m
>  Remaining Estimate: 0h
>
> https://github.com/apache/hive/blob/967a1cc98beede8e6568ce750ebeb6e0d048b8ea/ql/src/java/org/apache/hadoop/hive/ql/io/HiveInputFormat.java#L494-L503
>  
> {code}
> int headerCount = 0;
> int footerCount = 0;
> if (table != null) {
>   headerCount = Utilities.getHeaderCount(table);
>   footerCount = Utilities.getFooterCount(table, conf);
>   if (headerCount != 0 || footerCount != 0) {
> // Input file has header or footer, cannot be splitted.
> HiveConf.setLongVar(conf, ConfVars.MAPREDMINSPLITSIZE, 
> Long.MAX_VALUE);
>   }
> }
> {code}
> this piece of code makes the CSV (or any text files with header/footer) files 
> not splittable if header or footer is present. 
> If only header is present, we can find the offset after first line break and 
> use that to split. Similarly for footer, may be read few KB's of data at the 
> end and find the last line break offset. Use that to determine the data range 
> which can be used for splitting. Few reads during split generation are 
> cheaper than not splitting the file at all.  



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


[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-09 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=325793=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-325793
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 09/Oct/19 16:07
Start Date: 09/Oct/19 16:07
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r333102646
 
 

 ##
 File path: 
ql/src/test/queries/clientpositive/file_with_header_footer_aggregation.q
 ##
 @@ -0,0 +1,94 @@
+set hive.mapred.mode=nonstrict;
+
+dfs ${system:test.dfs.mkdir} ${system:test.tmp.dir};
+dfs -copyFromLocal ../../data/files/header_footer_table_4  
${system:test.tmp.dir}/header_footer_table_4;
+
+CREATE TABLE numbrs (numbr int);
+INSERT INTO numbrs VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), 
(11), (12), (NULL);
+CREATE EXTERNAL TABLE header_footer_table_4 (header_int int, header_name 
string, header_choice varchar(10)) ROW FORMAT DELIMITED FIELDS TERMINATED BY 
',' LOCATION '${system:test.tmp.dir}/header_footer_table_4' tblproperties 
("skip.header.line.count"="1", "skip.footer.line.count"="2");
+
+SELECT * FROM header_footer_table_4;
+
+SELECT * FROM header_footer_table_4 ORDER BY header_int LIMIT 8;
+
+-- should return nothing as title is correctly skipped
+SELECT * FROM header_footer_table_4 WHERE header_choice = 'header_choice';
 
 Review comment:
   this is covered.
 

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:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 325793)
Time Spent: 4h 10m  (was: 4h)

> Split text files even if header/footer exists
> -
>
> Key: HIVE-21924
> URL: https://issues.apache.org/jira/browse/HIVE-21924
> Project: Hive
>  Issue Type: Improvement
>  Components: File Formats
>Affects Versions: 2.4.0, 4.0.0, 3.2.0
>Reporter: Prasanth Jayachandran
>Assignee: Mustafa Iman
>Priority: Major
>  Labels: pull-request-available
> Attachments: HIVE-21924.2.patch, HIVE-21924.3.patch, 
> HIVE-21924.4.patch, HIVE-21924.5.patch, HIVE-21924.6.patch, HIVE-21924.patch
>
>  Time Spent: 4h 10m
>  Remaining Estimate: 0h
>
> https://github.com/apache/hive/blob/967a1cc98beede8e6568ce750ebeb6e0d048b8ea/ql/src/java/org/apache/hadoop/hive/ql/io/HiveInputFormat.java#L494-L503
>  
> {code}
> int headerCount = 0;
> int footerCount = 0;
> if (table != null) {
>   headerCount = Utilities.getHeaderCount(table);
>   footerCount = Utilities.getFooterCount(table, conf);
>   if (headerCount != 0 || footerCount != 0) {
> // Input file has header or footer, cannot be splitted.
> HiveConf.setLongVar(conf, ConfVars.MAPREDMINSPLITSIZE, 
> Long.MAX_VALUE);
>   }
> }
> {code}
> this piece of code makes the CSV (or any text files with header/footer) files 
> not splittable if header or footer is present. 
> If only header is present, we can find the offset after first line break and 
> use that to split. Similarly for footer, may be read few KB's of data at the 
> end and find the last line break offset. Use that to determine the data range 
> which can be used for splitting. Few reads during split generation are 
> cheaper than not splitting the file at all.  



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


[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-09 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=325791=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-325791
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 09/Oct/19 16:06
Start Date: 09/Oct/19 16:06
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r333102183
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,212 @@
+/*
+ * 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.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+return makeSplitInternal(file, start, length, hosts, null);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+return makeSplitInternal(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private FileSplit makeSplitInternal(Path file, long start, long length, 
String[] hosts, String[] inMemoryHosts) {
+long cachedStart;
+long cachedEnd;
+try {
+  cachedStart = getCachedStartIndex(file);
+  cachedEnd = getCachedEndIndex(file);
+} catch (IOException e) {
+  LOG.warn("Could not detect header/footer", e);
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+if (inMemoryHosts == null) {
+  return super.makeSplit(file, start, length, hosts);
+} else {
+  return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+}
+  }
+
+  private long getCachedStartIndex(Path path) throws IOException {
+if (headerCount == 0) {
+  return 0;
+}
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  FileSystem fileSystem;
+  FSDataInputStream fis = null;
+  fileSystem = path.getFileSystem(conf);
+  try {
+fis = fileSystem.open(path);
+for (int j = 0; j < headerCount; j++) {
+  if (fis.readLine() == null) {
+startIndexMap.put(path, Long.MAX_VALUE);
+return Long.MAX_VALUE;
+  }
+}
+// back 1 byte because readers skip the entire first row if split 
start is not 0
+startIndexForFile = fis.getPos() - 1;
 
 Review comment:
   ok. make sense.
 

This is an automated message from the Apache Git Service.
To respond to the 

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-09 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=325790=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-325790
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 09/Oct/19 16:05
Start Date: 09/Oct/19 16:05
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r333101701
 
 

 ##
 File path: 
ql/src/test/queries/clientpositive/file_with_header_footer_aggregation.q
 ##
 @@ -0,0 +1,94 @@
+set hive.mapred.mode=nonstrict;
+
+dfs ${system:test.dfs.mkdir} ${system:test.tmp.dir};
+dfs -copyFromLocal ../../data/files/header_footer_table_4  
${system:test.tmp.dir}/header_footer_table_4;
+
+CREATE TABLE numbrs (numbr int);
+INSERT INTO numbrs VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), 
(11), (12), (NULL);
+CREATE EXTERNAL TABLE header_footer_table_4 (header_int int, header_name 
string, header_choice varchar(10)) ROW FORMAT DELIMITED FIELDS TERMINATED BY 
',' LOCATION '${system:test.tmp.dir}/header_footer_table_4' tblproperties 
("skip.header.line.count"="1", "skip.footer.line.count"="2");
 
 Review comment:
   how about this?
 

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:
us...@infra.apache.org


Issue Time Tracking
---

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

> Split text files even if header/footer exists
> -
>
> Key: HIVE-21924
> URL: https://issues.apache.org/jira/browse/HIVE-21924
> Project: Hive
>  Issue Type: Improvement
>  Components: File Formats
>Affects Versions: 2.4.0, 4.0.0, 3.2.0
>Reporter: Prasanth Jayachandran
>Assignee: Mustafa Iman
>Priority: Major
>  Labels: pull-request-available
> Attachments: HIVE-21924.2.patch, HIVE-21924.3.patch, 
> HIVE-21924.4.patch, HIVE-21924.5.patch, HIVE-21924.6.patch, HIVE-21924.patch
>
>  Time Spent: 3h 50m
>  Remaining Estimate: 0h
>
> https://github.com/apache/hive/blob/967a1cc98beede8e6568ce750ebeb6e0d048b8ea/ql/src/java/org/apache/hadoop/hive/ql/io/HiveInputFormat.java#L494-L503
>  
> {code}
> int headerCount = 0;
> int footerCount = 0;
> if (table != null) {
>   headerCount = Utilities.getHeaderCount(table);
>   footerCount = Utilities.getFooterCount(table, conf);
>   if (headerCount != 0 || footerCount != 0) {
> // Input file has header or footer, cannot be splitted.
> HiveConf.setLongVar(conf, ConfVars.MAPREDMINSPLITSIZE, 
> Long.MAX_VALUE);
>   }
> }
> {code}
> this piece of code makes the CSV (or any text files with header/footer) files 
> not splittable if header or footer is present. 
> If only header is present, we can find the offset after first line break and 
> use that to split. Similarly for footer, may be read few KB's of data at the 
> end and find the last line break offset. Use that to determine the data range 
> which can be used for splitting. Few reads during split generation are 
> cheaper than not splitting the file at all.  



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


[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-09 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=325788=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-325788
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 09/Oct/19 16:04
Start Date: 09/Oct/19 16:04
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r333100958
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,212 @@
+/*
+ * 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.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+return makeSplitInternal(file, start, length, hosts, null);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+return makeSplitInternal(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private FileSplit makeSplitInternal(Path file, long start, long length, 
String[] hosts, String[] inMemoryHosts) {
+long cachedStart;
+long cachedEnd;
+try {
+  cachedStart = getCachedStartIndex(file);
+  cachedEnd = getCachedEndIndex(file);
+} catch (IOException e) {
+  LOG.warn("Could not detect header/footer", e);
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+if (inMemoryHosts == null) {
+  return super.makeSplit(file, start, length, hosts);
+} else {
+  return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+}
+  }
+
+  private long getCachedStartIndex(Path path) throws IOException {
+if (headerCount == 0) {
+  return 0;
+}
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  FileSystem fileSystem;
+  FSDataInputStream fis = null;
+  fileSystem = path.getFileSystem(conf);
+  try {
+fis = fileSystem.open(path);
+for (int j = 0; j < headerCount; j++) {
+  if (fis.readLine() == null) {
+startIndexMap.put(path, Long.MAX_VALUE);
+return Long.MAX_VALUE;
+  }
+}
+// back 1 byte because readers skip the entire first row if split 
start is not 0
+startIndexForFile = fis.getPos() - 1;
+  } finally {
+if (fis != null) {
+  fis.close();
+}
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;
+  }

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-09 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=325787=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-325787
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 09/Oct/19 16:03
Start Date: 09/Oct/19 16:03
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r333100647
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,212 @@
+/*
+ * 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.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+return makeSplitInternal(file, start, length, hosts, null);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+return makeSplitInternal(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private FileSplit makeSplitInternal(Path file, long start, long length, 
String[] hosts, String[] inMemoryHosts) {
+long cachedStart;
+long cachedEnd;
+try {
+  cachedStart = getCachedStartIndex(file);
+  cachedEnd = getCachedEndIndex(file);
+} catch (IOException e) {
+  LOG.warn("Could not detect header/footer", e);
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+if (inMemoryHosts == null) {
+  return super.makeSplit(file, start, length, hosts);
+} else {
+  return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+}
+  }
+
+  private long getCachedStartIndex(Path path) throws IOException {
+if (headerCount == 0) {
+  return 0;
+}
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  FileSystem fileSystem;
+  FSDataInputStream fis = null;
+  fileSystem = path.getFileSystem(conf);
+  try {
+fis = fileSystem.open(path);
+for (int j = 0; j < headerCount; j++) {
+  if (fis.readLine() == null) {
+startIndexMap.put(path, Long.MAX_VALUE);
+return Long.MAX_VALUE;
+  }
+}
+// back 1 byte because readers skip the entire first row if split 
start is not 0
+startIndexForFile = fis.getPos() - 1;
+  } finally {
+if (fis != null) {
+  fis.close();
+}
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;
+  }

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-09 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=325786=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-325786
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 09/Oct/19 16:02
Start Date: 09/Oct/19 16:02
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r333100168
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,212 @@
+/*
+ * 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.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+return makeSplitInternal(file, start, length, hosts, null);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+return makeSplitInternal(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private FileSplit makeSplitInternal(Path file, long start, long length, 
String[] hosts, String[] inMemoryHosts) {
+long cachedStart;
+long cachedEnd;
+try {
+  cachedStart = getCachedStartIndex(file);
+  cachedEnd = getCachedEndIndex(file);
+} catch (IOException e) {
+  LOG.warn("Could not detect header/footer", e);
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+if (inMemoryHosts == null) {
+  return super.makeSplit(file, start, length, hosts);
+} else {
+  return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+}
+  }
+
+  private long getCachedStartIndex(Path path) throws IOException {
+if (headerCount == 0) {
+  return 0;
+}
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  FileSystem fileSystem;
+  FSDataInputStream fis = null;
+  fileSystem = path.getFileSystem(conf);
+  try {
+fis = fileSystem.open(path);
+for (int j = 0; j < headerCount; j++) {
+  if (fis.readLine() == null) {
+startIndexMap.put(path, Long.MAX_VALUE);
+return Long.MAX_VALUE;
+  }
+}
+// back 1 byte because readers skip the entire first row if split 
start is not 0
+startIndexForFile = fis.getPos() - 1;
+  } finally {
+if (fis != null) {
+  fis.close();
+}
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;
+  }

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-04 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=323656=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-323656
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 04/Oct/19 18:46
Start Date: 04/Oct/19 18:46
Worklog Time Spent: 10m 
  Work Description: mustafaiman commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r331638453
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,212 @@
+/*
+ * 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.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+return makeSplitInternal(file, start, length, hosts, null);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+return makeSplitInternal(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private FileSplit makeSplitInternal(Path file, long start, long length, 
String[] hosts, String[] inMemoryHosts) {
+long cachedStart;
+long cachedEnd;
+try {
+  cachedStart = getCachedStartIndex(file);
+  cachedEnd = getCachedEndIndex(file);
+} catch (IOException e) {
+  LOG.warn("Could not detect header/footer", e);
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+if (inMemoryHosts == null) {
+  return super.makeSplit(file, start, length, hosts);
+} else {
+  return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+}
+  }
+
+  private long getCachedStartIndex(Path path) throws IOException {
+if (headerCount == 0) {
+  return 0;
+}
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  FileSystem fileSystem;
+  FSDataInputStream fis = null;
+  fileSystem = path.getFileSystem(conf);
+  try {
+fis = fileSystem.open(path);
+for (int j = 0; j < headerCount; j++) {
+  if (fis.readLine() == null) {
+startIndexMap.put(path, Long.MAX_VALUE);
+return Long.MAX_VALUE;
+  }
+}
+// back 1 byte because readers skip the entire first row if split 
start is not 0
+startIndexForFile = fis.getPos() - 1;
+  } finally {
+if (fis != null) {
+  fis.close();
+}
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-04 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=323657=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-323657
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 04/Oct/19 18:46
Start Date: 04/Oct/19 18:46
Worklog Time Spent: 10m 
  Work Description: mustafaiman commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r331632718
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,212 @@
+/*
+ * 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.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+return makeSplitInternal(file, start, length, hosts, null);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+return makeSplitInternal(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private FileSplit makeSplitInternal(Path file, long start, long length, 
String[] hosts, String[] inMemoryHosts) {
+long cachedStart;
+long cachedEnd;
+try {
+  cachedStart = getCachedStartIndex(file);
+  cachedEnd = getCachedEndIndex(file);
+} catch (IOException e) {
+  LOG.warn("Could not detect header/footer", e);
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+if (inMemoryHosts == null) {
+  return super.makeSplit(file, start, length, hosts);
+} else {
+  return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+}
+  }
+
+  private long getCachedStartIndex(Path path) throws IOException {
+if (headerCount == 0) {
+  return 0;
+}
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  FileSystem fileSystem;
+  FSDataInputStream fis = null;
+  fileSystem = path.getFileSystem(conf);
+  try {
+fis = fileSystem.open(path);
+for (int j = 0; j < headerCount; j++) {
+  if (fis.readLine() == null) {
+startIndexMap.put(path, Long.MAX_VALUE);
+return Long.MAX_VALUE;
+  }
+}
+// back 1 byte because readers skip the entire first row if split 
start is not 0
+startIndexForFile = fis.getPos() - 1;
+  } finally {
+if (fis != null) {
+  fis.close();
+}
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-04 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=323650=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-323650
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 04/Oct/19 18:31
Start Date: 04/Oct/19 18:31
Worklog Time Spent: 10m 
  Work Description: mustafaiman commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r331632718
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,212 @@
+/*
+ * 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.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+return makeSplitInternal(file, start, length, hosts, null);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+return makeSplitInternal(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private FileSplit makeSplitInternal(Path file, long start, long length, 
String[] hosts, String[] inMemoryHosts) {
+long cachedStart;
+long cachedEnd;
+try {
+  cachedStart = getCachedStartIndex(file);
+  cachedEnd = getCachedEndIndex(file);
+} catch (IOException e) {
+  LOG.warn("Could not detect header/footer", e);
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+if (inMemoryHosts == null) {
+  return super.makeSplit(file, start, length, hosts);
+} else {
+  return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+}
+  }
+
+  private long getCachedStartIndex(Path path) throws IOException {
+if (headerCount == 0) {
+  return 0;
+}
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  FileSystem fileSystem;
+  FSDataInputStream fis = null;
+  fileSystem = path.getFileSystem(conf);
+  try {
+fis = fileSystem.open(path);
+for (int j = 0; j < headerCount; j++) {
+  if (fis.readLine() == null) {
+startIndexMap.put(path, Long.MAX_VALUE);
+return Long.MAX_VALUE;
+  }
+}
+// back 1 byte because readers skip the entire first row if split 
start is not 0
+startIndexForFile = fis.getPos() - 1;
+  } finally {
+if (fis != null) {
+  fis.close();
+}
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-04 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=323646=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-323646
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 04/Oct/19 18:21
Start Date: 04/Oct/19 18:21
Worklog Time Spent: 10m 
  Work Description: mustafaiman commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r331628387
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,212 @@
+/*
+ * 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.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+return makeSplitInternal(file, start, length, hosts, null);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+return makeSplitInternal(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private FileSplit makeSplitInternal(Path file, long start, long length, 
String[] hosts, String[] inMemoryHosts) {
+long cachedStart;
+long cachedEnd;
+try {
+  cachedStart = getCachedStartIndex(file);
+  cachedEnd = getCachedEndIndex(file);
+} catch (IOException e) {
+  LOG.warn("Could not detect header/footer", e);
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+if (inMemoryHosts == null) {
+  return super.makeSplit(file, start, length, hosts);
+} else {
+  return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+}
+  }
+
+  private long getCachedStartIndex(Path path) throws IOException {
+if (headerCount == 0) {
+  return 0;
+}
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  FileSystem fileSystem;
+  FSDataInputStream fis = null;
+  fileSystem = path.getFileSystem(conf);
+  try {
+fis = fileSystem.open(path);
+for (int j = 0; j < headerCount; j++) {
+  if (fis.readLine() == null) {
+startIndexMap.put(path, Long.MAX_VALUE);
+return Long.MAX_VALUE;
+  }
+}
+// back 1 byte because readers skip the entire first row if split 
start is not 0
+startIndexForFile = fis.getPos() - 1;
+  } finally {
+if (fis != null) {
+  fis.close();
+}
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-04 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=323645=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-323645
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 04/Oct/19 18:19
Start Date: 04/Oct/19 18:19
Worklog Time Spent: 10m 
  Work Description: mustafaiman commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r331627809
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,212 @@
+/*
+ * 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.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+return makeSplitInternal(file, start, length, hosts, null);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+return makeSplitInternal(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private FileSplit makeSplitInternal(Path file, long start, long length, 
String[] hosts, String[] inMemoryHosts) {
+long cachedStart;
+long cachedEnd;
+try {
+  cachedStart = getCachedStartIndex(file);
+  cachedEnd = getCachedEndIndex(file);
+} catch (IOException e) {
+  LOG.warn("Could not detect header/footer", e);
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+if (inMemoryHosts == null) {
+  return super.makeSplit(file, start, length, hosts);
+} else {
+  return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+}
+  }
+
+  private long getCachedStartIndex(Path path) throws IOException {
+if (headerCount == 0) {
+  return 0;
+}
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  FileSystem fileSystem;
+  FSDataInputStream fis = null;
+  fileSystem = path.getFileSystem(conf);
+  try {
+fis = fileSystem.open(path);
+for (int j = 0; j < headerCount; j++) {
+  if (fis.readLine() == null) {
+startIndexMap.put(path, Long.MAX_VALUE);
+return Long.MAX_VALUE;
+  }
+}
+// back 1 byte because readers skip the entire first row if split 
start is not 0
+startIndexForFile = fis.getPos() - 1;
+  } finally {
+if (fis != null) {
+  fis.close();
+}
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-04 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=323641=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-323641
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 04/Oct/19 18:15
Start Date: 04/Oct/19 18:15
Worklog Time Spent: 10m 
  Work Description: mustafaiman commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r331626102
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,212 @@
+/*
+ * 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.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+return makeSplitInternal(file, start, length, hosts, null);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+return makeSplitInternal(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private FileSplit makeSplitInternal(Path file, long start, long length, 
String[] hosts, String[] inMemoryHosts) {
+long cachedStart;
+long cachedEnd;
+try {
+  cachedStart = getCachedStartIndex(file);
+  cachedEnd = getCachedEndIndex(file);
+} catch (IOException e) {
+  LOG.warn("Could not detect header/footer", e);
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+if (inMemoryHosts == null) {
+  return super.makeSplit(file, start, length, hosts);
+} else {
+  return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+}
+  }
+
+  private long getCachedStartIndex(Path path) throws IOException {
+if (headerCount == 0) {
+  return 0;
+}
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  FileSystem fileSystem;
+  FSDataInputStream fis = null;
+  fileSystem = path.getFileSystem(conf);
+  try {
+fis = fileSystem.open(path);
+for (int j = 0; j < headerCount; j++) {
+  if (fis.readLine() == null) {
+startIndexMap.put(path, Long.MAX_VALUE);
+return Long.MAX_VALUE;
+  }
+}
+// back 1 byte because readers skip the entire first row if split 
start is not 0
+startIndexForFile = fis.getPos() - 1;
 
 Review comment:
   I tried to explain this in the comment above. LineRecordReader from hadoop 
always skips the first line if the start index of the split is not 0. Here, we 

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-03 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=323197=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-323197
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 04/Oct/19 05:35
Start Date: 04/Oct/19 05:35
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r330946090
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,212 @@
+/*
+ * 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.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+return makeSplitInternal(file, start, length, hosts, null);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+return makeSplitInternal(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private FileSplit makeSplitInternal(Path file, long start, long length, 
String[] hosts, String[] inMemoryHosts) {
+long cachedStart;
+long cachedEnd;
+try {
+  cachedStart = getCachedStartIndex(file);
+  cachedEnd = getCachedEndIndex(file);
+} catch (IOException e) {
+  LOG.warn("Could not detect header/footer", e);
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+if (inMemoryHosts == null) {
+  return super.makeSplit(file, start, length, hosts);
+} else {
+  return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+}
+  }
+
+  private long getCachedStartIndex(Path path) throws IOException {
+if (headerCount == 0) {
+  return 0;
+}
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  FileSystem fileSystem;
+  FSDataInputStream fis = null;
+  fileSystem = path.getFileSystem(conf);
+  try {
+fis = fileSystem.open(path);
+for (int j = 0; j < headerCount; j++) {
+  if (fis.readLine() == null) {
+startIndexMap.put(path, Long.MAX_VALUE);
+return Long.MAX_VALUE;
+  }
+}
+// back 1 byte because readers skip the entire first row if split 
start is not 0
+startIndexForFile = fis.getPos() - 1;
 
 Review comment:
   I'm not sure about this. My understanding is that getPos() returns position 
of first character in the line. Do we need the -1?
 

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-03 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=323194=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-323194
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 04/Oct/19 05:33
Start Date: 04/Oct/19 05:33
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r331338984
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,212 @@
+/*
+ * 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.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+return makeSplitInternal(file, start, length, hosts, null);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+return makeSplitInternal(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private FileSplit makeSplitInternal(Path file, long start, long length, 
String[] hosts, String[] inMemoryHosts) {
+long cachedStart;
+long cachedEnd;
+try {
+  cachedStart = getCachedStartIndex(file);
+  cachedEnd = getCachedEndIndex(file);
+} catch (IOException e) {
+  LOG.warn("Could not detect header/footer", e);
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+if (inMemoryHosts == null) {
+  return super.makeSplit(file, start, length, hosts);
+} else {
+  return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+}
+  }
+
+  private long getCachedStartIndex(Path path) throws IOException {
+if (headerCount == 0) {
+  return 0;
+}
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  FileSystem fileSystem;
+  FSDataInputStream fis = null;
+  fileSystem = path.getFileSystem(conf);
+  try {
+fis = fileSystem.open(path);
+for (int j = 0; j < headerCount; j++) {
+  if (fis.readLine() == null) {
+startIndexMap.put(path, Long.MAX_VALUE);
+return Long.MAX_VALUE;
+  }
+}
+// back 1 byte because readers skip the entire first row if split 
start is not 0
+startIndexForFile = fis.getPos() - 1;
+  } finally {
+if (fis != null) {
+  fis.close();
+}
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;
+  }

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-03 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=323195=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-323195
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 04/Oct/19 05:33
Start Date: 04/Oct/19 05:33
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r331345123
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,212 @@
+/*
+ * 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.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+return makeSplitInternal(file, start, length, hosts, null);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+return makeSplitInternal(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private FileSplit makeSplitInternal(Path file, long start, long length, 
String[] hosts, String[] inMemoryHosts) {
+long cachedStart;
+long cachedEnd;
+try {
+  cachedStart = getCachedStartIndex(file);
+  cachedEnd = getCachedEndIndex(file);
+} catch (IOException e) {
+  LOG.warn("Could not detect header/footer", e);
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+if (inMemoryHosts == null) {
+  return super.makeSplit(file, start, length, hosts);
+} else {
+  return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+}
+  }
+
+  private long getCachedStartIndex(Path path) throws IOException {
+if (headerCount == 0) {
+  return 0;
+}
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  FileSystem fileSystem;
+  FSDataInputStream fis = null;
+  fileSystem = path.getFileSystem(conf);
+  try {
+fis = fileSystem.open(path);
+for (int j = 0; j < headerCount; j++) {
+  if (fis.readLine() == null) {
+startIndexMap.put(path, Long.MAX_VALUE);
+return Long.MAX_VALUE;
+  }
+}
+// back 1 byte because readers skip the entire first row if split 
start is not 0
+startIndexForFile = fis.getPos() - 1;
+  } finally {
+if (fis != null) {
+  fis.close();
+}
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;
+  }

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-03 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=323191=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-323191
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 04/Oct/19 05:33
Start Date: 04/Oct/19 05:33
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r330946090
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,212 @@
+/*
+ * 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.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+return makeSplitInternal(file, start, length, hosts, null);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+return makeSplitInternal(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private FileSplit makeSplitInternal(Path file, long start, long length, 
String[] hosts, String[] inMemoryHosts) {
+long cachedStart;
+long cachedEnd;
+try {
+  cachedStart = getCachedStartIndex(file);
+  cachedEnd = getCachedEndIndex(file);
+} catch (IOException e) {
+  LOG.warn("Could not detect header/footer", e);
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+if (inMemoryHosts == null) {
+  return super.makeSplit(file, start, length, hosts);
+} else {
+  return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+}
+  }
+
+  private long getCachedStartIndex(Path path) throws IOException {
+if (headerCount == 0) {
+  return 0;
+}
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  FileSystem fileSystem;
+  FSDataInputStream fis = null;
+  fileSystem = path.getFileSystem(conf);
+  try {
+fis = fileSystem.open(path);
+for (int j = 0; j < headerCount; j++) {
+  if (fis.readLine() == null) {
+startIndexMap.put(path, Long.MAX_VALUE);
+return Long.MAX_VALUE;
+  }
+}
+// back 1 byte because readers skip the entire first row if split 
start is not 0
+startIndexForFile = fis.getPos() - 1;
 
 Review comment:
   I'm not sure about this. My understanding is that getPos() returns position 
of first character in the row. Do we need the -1?
 

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-03 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=323192=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-323192
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 04/Oct/19 05:33
Start Date: 04/Oct/19 05:33
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r331344762
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,212 @@
+/*
+ * 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.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+return makeSplitInternal(file, start, length, hosts, null);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+return makeSplitInternal(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private FileSplit makeSplitInternal(Path file, long start, long length, 
String[] hosts, String[] inMemoryHosts) {
+long cachedStart;
+long cachedEnd;
+try {
+  cachedStart = getCachedStartIndex(file);
+  cachedEnd = getCachedEndIndex(file);
+} catch (IOException e) {
+  LOG.warn("Could not detect header/footer", e);
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+if (inMemoryHosts == null) {
+  return super.makeSplit(file, start, length, hosts);
+} else {
+  return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+}
+  }
+
+  private long getCachedStartIndex(Path path) throws IOException {
+if (headerCount == 0) {
+  return 0;
+}
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  FileSystem fileSystem;
+  FSDataInputStream fis = null;
+  fileSystem = path.getFileSystem(conf);
+  try {
+fis = fileSystem.open(path);
+for (int j = 0; j < headerCount; j++) {
+  if (fis.readLine() == null) {
+startIndexMap.put(path, Long.MAX_VALUE);
+return Long.MAX_VALUE;
+  }
+}
+// back 1 byte because readers skip the entire first row if split 
start is not 0
+startIndexForFile = fis.getPos() - 1;
+  } finally {
+if (fis != null) {
+  fis.close();
+}
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;
+  }

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-03 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=323196=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-323196
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 04/Oct/19 05:33
Start Date: 04/Oct/19 05:33
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r331344245
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,212 @@
+/*
+ * 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.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+return makeSplitInternal(file, start, length, hosts, null);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+return makeSplitInternal(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private FileSplit makeSplitInternal(Path file, long start, long length, 
String[] hosts, String[] inMemoryHosts) {
+long cachedStart;
+long cachedEnd;
+try {
+  cachedStart = getCachedStartIndex(file);
+  cachedEnd = getCachedEndIndex(file);
+} catch (IOException e) {
+  LOG.warn("Could not detect header/footer", e);
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+if (inMemoryHosts == null) {
+  return super.makeSplit(file, start, length, hosts);
+} else {
+  return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+}
+  }
+
+  private long getCachedStartIndex(Path path) throws IOException {
+if (headerCount == 0) {
+  return 0;
+}
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  FileSystem fileSystem;
+  FSDataInputStream fis = null;
+  fileSystem = path.getFileSystem(conf);
+  try {
+fis = fileSystem.open(path);
+for (int j = 0; j < headerCount; j++) {
+  if (fis.readLine() == null) {
+startIndexMap.put(path, Long.MAX_VALUE);
+return Long.MAX_VALUE;
+  }
+}
+// back 1 byte because readers skip the entire first row if split 
start is not 0
+startIndexForFile = fis.getPos() - 1;
+  } finally {
+if (fis != null) {
+  fis.close();
+}
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;
+  }

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-03 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=323193=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-323193
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 04/Oct/19 05:33
Start Date: 04/Oct/19 05:33
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r331344703
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,212 @@
+/*
+ * 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.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+return makeSplitInternal(file, start, length, hosts, null);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+return makeSplitInternal(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private FileSplit makeSplitInternal(Path file, long start, long length, 
String[] hosts, String[] inMemoryHosts) {
+long cachedStart;
+long cachedEnd;
+try {
+  cachedStart = getCachedStartIndex(file);
+  cachedEnd = getCachedEndIndex(file);
+} catch (IOException e) {
+  LOG.warn("Could not detect header/footer", e);
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+if (inMemoryHosts == null) {
+  return super.makeSplit(file, start, length, hosts);
+} else {
+  return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+}
+  }
+
+  private long getCachedStartIndex(Path path) throws IOException {
+if (headerCount == 0) {
+  return 0;
+}
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  FileSystem fileSystem;
+  FSDataInputStream fis = null;
+  fileSystem = path.getFileSystem(conf);
+  try {
+fis = fileSystem.open(path);
+for (int j = 0; j < headerCount; j++) {
+  if (fis.readLine() == null) {
+startIndexMap.put(path, Long.MAX_VALUE);
+return Long.MAX_VALUE;
+  }
+}
+// back 1 byte because readers skip the entire first row if split 
start is not 0
+startIndexForFile = fis.getPos() - 1;
+  } finally {
+if (fis != null) {
+  fis.close();
+}
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;
+  }

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-03 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=323143=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-323143
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 04/Oct/19 02:08
Start Date: 04/Oct/19 02:08
Worklog Time Spent: 10m 
  Work Description: jdere commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r331316286
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,212 @@
+/*
+ * 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.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+return makeSplitInternal(file, start, length, hosts, null);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+return makeSplitInternal(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private FileSplit makeSplitInternal(Path file, long start, long length, 
String[] hosts, String[] inMemoryHosts) {
+long cachedStart;
+long cachedEnd;
+try {
+  cachedStart = getCachedStartIndex(file);
+  cachedEnd = getCachedEndIndex(file);
+} catch (IOException e) {
+  LOG.warn("Could not detect header/footer", e);
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+}
+if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+if (inMemoryHosts == null) {
+  return super.makeSplit(file, start, length, hosts);
+} else {
+  return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+}
+  }
+
+  private long getCachedStartIndex(Path path) throws IOException {
+if (headerCount == 0) {
+  return 0;
+}
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  FileSystem fileSystem;
+  FSDataInputStream fis = null;
+  fileSystem = path.getFileSystem(conf);
+  try {
+fis = fileSystem.open(path);
+for (int j = 0; j < headerCount; j++) {
+  if (fis.readLine() == null) {
+startIndexMap.put(path, Long.MAX_VALUE);
+return Long.MAX_VALUE;
+  }
+}
+// back 1 byte because readers skip the entire first row if split 
start is not 0
+startIndexForFile = fis.getPos() - 1;
+  } finally {
+if (fis != null) {
+  fis.close();
+}
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;
+  }
+

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-10-01 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=321636=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-321636
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 02/Oct/19 00:23
Start Date: 02/Oct/19 00:23
Worklog Time Spent: 10m 
  Work Description: mustafaiman commented on issue #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#issuecomment-537284007
 
 
   @sankarh Can you review this again?
 

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:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 321636)
Time Spent: 1.5h  (was: 1h 20m)

> Split text files even if header/footer exists
> -
>
> Key: HIVE-21924
> URL: https://issues.apache.org/jira/browse/HIVE-21924
> Project: Hive
>  Issue Type: Improvement
>  Components: File Formats
>Affects Versions: 2.4.0, 4.0.0, 3.2.0
>Reporter: Prasanth Jayachandran
>Assignee: Mustafa Iman
>Priority: Major
>  Labels: pull-request-available
> Attachments: HIVE-21924.2.patch, HIVE-21924.3.patch, 
> HIVE-21924.4.patch, HIVE-21924.patch
>
>  Time Spent: 1.5h
>  Remaining Estimate: 0h
>
> https://github.com/apache/hive/blob/967a1cc98beede8e6568ce750ebeb6e0d048b8ea/ql/src/java/org/apache/hadoop/hive/ql/io/HiveInputFormat.java#L494-L503
>  
> {code}
> int headerCount = 0;
> int footerCount = 0;
> if (table != null) {
>   headerCount = Utilities.getHeaderCount(table);
>   footerCount = Utilities.getFooterCount(table, conf);
>   if (headerCount != 0 || footerCount != 0) {
> // Input file has header or footer, cannot be splitted.
> HiveConf.setLongVar(conf, ConfVars.MAPREDMINSPLITSIZE, 
> Long.MAX_VALUE);
>   }
> }
> {code}
> this piece of code makes the CSV (or any text files with header/footer) files 
> not splittable if header or footer is present. 
> If only header is present, we can find the offset after first line break and 
> use that to split. Similarly for footer, may be read few KB's of data at the 
> end and find the last line break offset. Use that to determine the data range 
> which can be used for splitting. Few reads during split generation are 
> cheaper than not splitting the file at all.  



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


[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-09-27 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=319437=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-319437
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 27/Sep/19 09:17
Start Date: 27/Sep/19 09:17
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r328983572
 
 

 ##
 File path: 
ql/src/test/queries/clientpositive/file_with_header_footer_aggregation.q
 ##
 @@ -0,0 +1,94 @@
+set hive.mapred.mode=nonstrict;
+
+dfs ${system:test.dfs.mkdir} ${system:test.tmp.dir};
+dfs -copyFromLocal ../../data/files/header_footer_table_4  
${system:test.tmp.dir}/header_footer_table_4;
+
+CREATE TABLE numbrs (numbr int);
+INSERT INTO numbrs VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), 
(11), (12), (NULL);
+CREATE EXTERNAL TABLE header_footer_table_4 (header_int int, header_name 
string, header_choice varchar(10)) ROW FORMAT DELIMITED FIELDS TERMINATED BY 
',' LOCATION '${system:test.tmp.dir}/header_footer_table_4' tblproperties 
("skip.header.line.count"="1", "skip.footer.line.count"="2");
+
+SELECT * FROM header_footer_table_4;
+
+SELECT * FROM header_footer_table_4 ORDER BY header_int LIMIT 8;
+
+-- should return nothing as title is correctly skipped
+SELECT * FROM header_footer_table_4 WHERE header_choice = 'header_choice';
 
 Review comment:
   Add a select query with filters that return valid rows. 
 

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:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 319437)
Time Spent: 50m  (was: 40m)

> Split text files even if header/footer exists
> -
>
> Key: HIVE-21924
> URL: https://issues.apache.org/jira/browse/HIVE-21924
> Project: Hive
>  Issue Type: Improvement
>  Components: File Formats
>Affects Versions: 2.4.0, 4.0.0, 3.2.0
>Reporter: Prasanth Jayachandran
>Assignee: Mustafa Iman
>Priority: Major
>  Labels: pull-request-available
> Attachments: HIVE-21924.patch
>
>  Time Spent: 50m
>  Remaining Estimate: 0h
>
> https://github.com/apache/hive/blob/967a1cc98beede8e6568ce750ebeb6e0d048b8ea/ql/src/java/org/apache/hadoop/hive/ql/io/HiveInputFormat.java#L494-L503
>  
> {code}
> int headerCount = 0;
> int footerCount = 0;
> if (table != null) {
>   headerCount = Utilities.getHeaderCount(table);
>   footerCount = Utilities.getFooterCount(table, conf);
>   if (headerCount != 0 || footerCount != 0) {
> // Input file has header or footer, cannot be splitted.
> HiveConf.setLongVar(conf, ConfVars.MAPREDMINSPLITSIZE, 
> Long.MAX_VALUE);
>   }
> }
> {code}
> this piece of code makes the CSV (or any text files with header/footer) files 
> not splittable if header or footer is present. 
> If only header is present, we can find the offset after first line break and 
> use that to split. Similarly for footer, may be read few KB's of data at the 
> end and find the last line break offset. Use that to determine the data range 
> which can be used for splitting. Few reads during split generation are 
> cheaper than not splitting the file at all.  



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


[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-09-27 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=319436=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-319436
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 27/Sep/19 09:17
Start Date: 27/Sep/19 09:17
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r328918560
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,136 @@
+package org.apache.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > -1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > - 1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private long getCachedStartIndex(Path path) {
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  try {
+FSDataInputStream fis = path.getFileSystem(conf).open(path);
+for (int j = 0; j < headerCount; j++) {
+  fis.readLine();
+  // back 1 byte because readers skip the entire first row if split 
start is not 0
+  startIndexForFile = fis.getPos() - 1;
+}
+  } catch (IOException e) {
+startIndexForFile = 0L;
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;
+  }
+
+  private long getCachedEndIndex(Path path) {
+Long endIndexForFile = endIndexMap.get(path);
+if (endIndexForFile == null) {
+  try {
+final long bufferSectionSize = 1024;
+long bufferSectionEnd = 
path.getFileSystem(conf).getFileStatus(path).getLen();
+long bufferSectionStart = Math.max(0, bufferSectionEnd - 
bufferSectionSize);
+Queue lineEndBuffer = new ArrayDeque(headerCount + 1);
+FSDataInputStream fis = path.getFileSystem(conf).open(path);
+fis.seek(bufferSectionStart);
 
 Review comment:
   Redundant statement. It is again done within the loop.
 

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:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 319436)
Time Spent: 40m  (was: 0.5h)

> Split text files even if header/footer exists
> 

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-09-27 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=319430=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-319430
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 27/Sep/19 09:17
Start Date: 27/Sep/19 09:17
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r328918215
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,136 @@
+package org.apache.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > -1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > - 1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private long getCachedStartIndex(Path path) {
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  try {
+FSDataInputStream fis = path.getFileSystem(conf).open(path);
 
 Review comment:
   fis.close() needed in finally block.
 

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:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 319430)
Time Spent: 20m  (was: 10m)

> Split text files even if header/footer exists
> -
>
> Key: HIVE-21924
> URL: https://issues.apache.org/jira/browse/HIVE-21924
> Project: Hive
>  Issue Type: Improvement
>  Components: File Formats
>Affects Versions: 2.4.0, 4.0.0, 3.2.0
>Reporter: Prasanth Jayachandran
>Assignee: Mustafa Iman
>Priority: Major
>  Labels: pull-request-available
> Attachments: HIVE-21924.patch
>
>  Time Spent: 20m
>  Remaining Estimate: 0h
>
> https://github.com/apache/hive/blob/967a1cc98beede8e6568ce750ebeb6e0d048b8ea/ql/src/java/org/apache/hadoop/hive/ql/io/HiveInputFormat.java#L494-L503
>  
> {code}
> int headerCount = 0;
> int footerCount = 0;
> if (table != null) {
>   headerCount = Utilities.getHeaderCount(table);
>   footerCount = Utilities.getFooterCount(table, conf);
>   if (headerCount != 0 || footerCount != 0) {
> // Input file has 

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-09-27 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=319439=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-319439
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 27/Sep/19 09:17
Start Date: 27/Sep/19 09:17
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r328983296
 
 

 ##
 File path: 
ql/src/test/queries/clientpositive/file_with_header_footer_aggregation.q
 ##
 @@ -0,0 +1,94 @@
+set hive.mapred.mode=nonstrict;
+
+dfs ${system:test.dfs.mkdir} ${system:test.tmp.dir};
+dfs -copyFromLocal ../../data/files/header_footer_table_4  
${system:test.tmp.dir}/header_footer_table_4;
+
+CREATE TABLE numbrs (numbr int);
+INSERT INTO numbrs VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), 
(11), (12), (NULL);
+CREATE EXTERNAL TABLE header_footer_table_4 (header_int int, header_name 
string, header_choice varchar(10)) ROW FORMAT DELIMITED FIELDS TERMINATED BY 
',' LOCATION '${system:test.tmp.dir}/header_footer_table_4' tblproperties 
("skip.header.line.count"="1", "skip.footer.line.count"="2");
 
 Review comment:
   Also, add tests with only header, only footer, file having only 
header+footer but no data rows. 
 

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:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 319439)
Time Spent: 50m  (was: 40m)

> Split text files even if header/footer exists
> -
>
> Key: HIVE-21924
> URL: https://issues.apache.org/jira/browse/HIVE-21924
> Project: Hive
>  Issue Type: Improvement
>  Components: File Formats
>Affects Versions: 2.4.0, 4.0.0, 3.2.0
>Reporter: Prasanth Jayachandran
>Assignee: Mustafa Iman
>Priority: Major
>  Labels: pull-request-available
> Attachments: HIVE-21924.patch
>
>  Time Spent: 50m
>  Remaining Estimate: 0h
>
> https://github.com/apache/hive/blob/967a1cc98beede8e6568ce750ebeb6e0d048b8ea/ql/src/java/org/apache/hadoop/hive/ql/io/HiveInputFormat.java#L494-L503
>  
> {code}
> int headerCount = 0;
> int footerCount = 0;
> if (table != null) {
>   headerCount = Utilities.getHeaderCount(table);
>   footerCount = Utilities.getFooterCount(table, conf);
>   if (headerCount != 0 || footerCount != 0) {
> // Input file has header or footer, cannot be splitted.
> HiveConf.setLongVar(conf, ConfVars.MAPREDMINSPLITSIZE, 
> Long.MAX_VALUE);
>   }
> }
> {code}
> this piece of code makes the CSV (or any text files with header/footer) files 
> not splittable if header or footer is present. 
> If only header is present, we can find the offset after first line break and 
> use that to split. Similarly for footer, may be read few KB's of data at the 
> end and find the last line break offset. Use that to determine the data range 
> which can be used for splitting. Few reads during split generation are 
> cheaper than not splitting the file at all.  



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


[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-09-27 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=319432=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-319432
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 27/Sep/19 09:17
Start Date: 27/Sep/19 09:17
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r328913511
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,136 @@
+package org.apache.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > -1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+long cachedStart = getCachedStartIndex(file);
 
 Review comment:
   The logic to obtain start and length are duplicated in 2 methods. Can we 
have a private methods for it?
 

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:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 319432)
Time Spent: 0.5h  (was: 20m)

> Split text files even if header/footer exists
> -
>
> Key: HIVE-21924
> URL: https://issues.apache.org/jira/browse/HIVE-21924
> Project: Hive
>  Issue Type: Improvement
>  Components: File Formats
>Affects Versions: 2.4.0, 4.0.0, 3.2.0
>Reporter: Prasanth Jayachandran
>Assignee: Mustafa Iman
>Priority: Major
>  Labels: pull-request-available
> Attachments: HIVE-21924.patch
>
>  Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> https://github.com/apache/hive/blob/967a1cc98beede8e6568ce750ebeb6e0d048b8ea/ql/src/java/org/apache/hadoop/hive/ql/io/HiveInputFormat.java#L494-L503
>  
> {code}
> int headerCount = 0;
> int footerCount = 0;
> if (table != null) {
>   headerCount = Utilities.getHeaderCount(table);
>   footerCount = Utilities.getFooterCount(table, conf);
>   if (headerCount != 0 || footerCount != 0) {
> // Input file has header or footer, cannot be splitted.
> HiveConf.setLongVar(conf, ConfVars.MAPREDMINSPLITSIZE, 
> Long.MAX_VALUE);
>   }
> }
> {code}
> this piece of code makes the CSV (or any text files with header/footer) files 
> not splittable if header or footer is present. 
> If only header is present, we can find the offset after first line break and 
> use that to split. Similarly for footer, may be read few KB's of data at the 
> end and find the last line break offset. Use that to determine the data range 
> which can be used for splitting. Few reads during split generation are 
> cheaper than not splitting the file at all.  



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


[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-09-27 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=319443=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-319443
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 27/Sep/19 09:17
Start Date: 27/Sep/19 09:17
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r328978995
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,136 @@
+package org.apache.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > -1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > - 1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private long getCachedStartIndex(Path path) {
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  try {
+FSDataInputStream fis = path.getFileSystem(conf).open(path);
+for (int j = 0; j < headerCount; j++) {
+  fis.readLine();
+  // back 1 byte because readers skip the entire first row if split 
start is not 0
+  startIndexForFile = fis.getPos() - 1;
+}
+  } catch (IOException e) {
+startIndexForFile = 0L;
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;
+  }
+
+  private long getCachedEndIndex(Path path) {
+Long endIndexForFile = endIndexMap.get(path);
+if (endIndexForFile == null) {
+  try {
+final long bufferSectionSize = 1024;
+long bufferSectionEnd = 
path.getFileSystem(conf).getFileStatus(path).getLen();
+long bufferSectionStart = Math.max(0, bufferSectionEnd - 
bufferSectionSize);
+Queue lineEndBuffer = new ArrayDeque(headerCount + 1);
+FSDataInputStream fis = path.getFileSystem(conf).open(path);
+fis.seek(bufferSectionStart);
+while (bufferSectionEnd > bufferSectionStart) {
+  fis.seek(bufferSectionStart);
+  long pos = fis.getPos();
+  while (pos < bufferSectionEnd) {
+fis.readLine();
+pos = fis.getPos();
+if (pos <= bufferSectionEnd) {
+  if (lineEndBuffer.size() > footerCount) {
+lineEndBuffer.poll();
 
 Review comment:
   I think, there is a problem in this logic. The queue is expected to have 
positions added in descending order. But, let's say, if first batch doesn't 
make the queue full, then 2nd batch 

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-09-27 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=319433=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-319433
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 27/Sep/19 09:17
Start Date: 27/Sep/19 09:17
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r328916465
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,136 @@
+package org.apache.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > -1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > - 1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private long getCachedStartIndex(Path path) {
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  try {
+FSDataInputStream fis = path.getFileSystem(conf).open(path);
+for (int j = 0; j < headerCount; j++) {
+  fis.readLine();
+  // back 1 byte because readers skip the entire first row if split 
start is not 0
+  startIndexForFile = fis.getPos() - 1;
+}
+  } catch (IOException e) {
+startIndexForFile = 0L;
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;
+  }
+
+  private long getCachedEndIndex(Path path) {
+Long endIndexForFile = endIndexMap.get(path);
+if (endIndexForFile == null) {
+  try {
+final long bufferSectionSize = 1024;
+long bufferSectionEnd = 
path.getFileSystem(conf).getFileStatus(path).getLen();
+long bufferSectionStart = Math.max(0, bufferSectionEnd - 
bufferSectionSize);
+Queue lineEndBuffer = new ArrayDeque(headerCount + 1);
 
 Review comment:
   It should be footerCount + 1.
 

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:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 319433)
Time Spent: 0.5h  (was: 20m)

> Split text files even if header/footer exists
> -
>
> Key: HIVE-21924
> URL: https://issues.apache.org/jira/browse/HIVE-21924
>

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-09-27 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=319431=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-319431
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 27/Sep/19 09:17
Start Date: 27/Sep/19 09:17
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r328915560
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,136 @@
+package org.apache.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > -1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > - 1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private long getCachedStartIndex(Path path) {
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  try {
+FSDataInputStream fis = path.getFileSystem(conf).open(path);
+for (int j = 0; j < headerCount; j++) {
+  fis.readLine();
+  // back 1 byte because readers skip the entire first row if split 
start is not 0
+  startIndexForFile = fis.getPos() - 1;
+}
+  } catch (IOException e) {
+startIndexForFile = 0L;
 
 Review comment:
   This IOException handling doesn't seem right. If file read fails then better 
to throw exception and if doesn't have enough header rows, then we should set 
start index as EOF so that we return dummy split always.
 

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:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 319431)
Time Spent: 0.5h  (was: 20m)

> Split text files even if header/footer exists
> -
>
> Key: HIVE-21924
> URL: https://issues.apache.org/jira/browse/HIVE-21924
> Project: Hive
>  Issue Type: Improvement
>  Components: File Formats
>Affects Versions: 2.4.0, 4.0.0, 3.2.0
>Reporter: Prasanth Jayachandran
>Assignee: Mustafa Iman
>Priority: Major
>  Labels: pull-request-available
> Attachments: HIVE-21924.patch
>
>  Time Spent: 

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-09-27 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=319440=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-319440
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 27/Sep/19 09:17
Start Date: 27/Sep/19 09:17
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r328964763
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,136 @@
+package org.apache.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > -1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > - 1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private long getCachedStartIndex(Path path) {
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  try {
+FSDataInputStream fis = path.getFileSystem(conf).open(path);
+for (int j = 0; j < headerCount; j++) {
+  fis.readLine();
+  // back 1 byte because readers skip the entire first row if split 
start is not 0
+  startIndexForFile = fis.getPos() - 1;
+}
+  } catch (IOException e) {
+startIndexForFile = 0L;
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;
+  }
+
+  private long getCachedEndIndex(Path path) {
+Long endIndexForFile = endIndexMap.get(path);
+if (endIndexForFile == null) {
+  try {
+final long bufferSectionSize = 1024;
+long bufferSectionEnd = 
path.getFileSystem(conf).getFileStatus(path).getLen();
+long bufferSectionStart = Math.max(0, bufferSectionEnd - 
bufferSectionSize);
+Queue lineEndBuffer = new ArrayDeque(headerCount + 1);
+FSDataInputStream fis = path.getFileSystem(conf).open(path);
+fis.seek(bufferSectionStart);
+while (bufferSectionEnd > bufferSectionStart) {
+  fis.seek(bufferSectionStart);
+  long pos = fis.getPos();
+  while (pos < bufferSectionEnd) {
+fis.readLine();
+pos = fis.getPos();
+if (pos <= bufferSectionEnd) {
+  if (lineEndBuffer.size() > footerCount) {
+lineEndBuffer.poll();
+  }
+  lineEndBuffer.add(pos);
+}
+  }
+  if (lineEndBuffer.size() > footerCount) {
+break;
+  } else {
+bufferSectionEnd = 

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-09-27 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=319444=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-319444
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 27/Sep/19 09:17
Start Date: 27/Sep/19 09:17
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r328983856
 
 

 ##
 File path: 
ql/src/test/queries/clientpositive/file_with_header_footer_aggregation.q
 ##
 @@ -0,0 +1,94 @@
+set hive.mapred.mode=nonstrict;
+
+dfs ${system:test.dfs.mkdir} ${system:test.tmp.dir};
+dfs -copyFromLocal ../../data/files/header_footer_table_4  
${system:test.tmp.dir}/header_footer_table_4;
+
+CREATE TABLE numbrs (numbr int);
+INSERT INTO numbrs VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), 
(11), (12), (NULL);
+CREATE EXTERNAL TABLE header_footer_table_4 (header_int int, header_name 
string, header_choice varchar(10)) ROW FORMAT DELIMITED FIELDS TERMINATED BY 
',' LOCATION '${system:test.tmp.dir}/header_footer_table_4' tblproperties 
("skip.header.line.count"="1", "skip.footer.line.count"="2");
+
+SELECT * FROM header_footer_table_4;
+
+SELECT * FROM header_footer_table_4 ORDER BY header_int LIMIT 8;
+
+-- should return nothing as title is correctly skipped
+SELECT * FROM header_footer_table_4 WHERE header_choice = 'header_choice';
 
 Review comment:
   Also, test count(*) as well.
 

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:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 319444)
Time Spent: 1h 20m  (was: 1h 10m)

> Split text files even if header/footer exists
> -
>
> Key: HIVE-21924
> URL: https://issues.apache.org/jira/browse/HIVE-21924
> Project: Hive
>  Issue Type: Improvement
>  Components: File Formats
>Affects Versions: 2.4.0, 4.0.0, 3.2.0
>Reporter: Prasanth Jayachandran
>Assignee: Mustafa Iman
>Priority: Major
>  Labels: pull-request-available
> Attachments: HIVE-21924.patch
>
>  Time Spent: 1h 20m
>  Remaining Estimate: 0h
>
> https://github.com/apache/hive/blob/967a1cc98beede8e6568ce750ebeb6e0d048b8ea/ql/src/java/org/apache/hadoop/hive/ql/io/HiveInputFormat.java#L494-L503
>  
> {code}
> int headerCount = 0;
> int footerCount = 0;
> if (table != null) {
>   headerCount = Utilities.getHeaderCount(table);
>   footerCount = Utilities.getFooterCount(table, conf);
>   if (headerCount != 0 || footerCount != 0) {
> // Input file has header or footer, cannot be splitted.
> HiveConf.setLongVar(conf, ConfVars.MAPREDMINSPLITSIZE, 
> Long.MAX_VALUE);
>   }
> }
> {code}
> this piece of code makes the CSV (or any text files with header/footer) files 
> not splittable if header or footer is present. 
> If only header is present, we can find the offset after first line break and 
> use that to split. Similarly for footer, may be read few KB's of data at the 
> end and find the last line break offset. Use that to determine the data range 
> which can be used for splitting. Few reads during split generation are 
> cheaper than not splitting the file at all.  



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


[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-09-27 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=319438=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-319438
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 27/Sep/19 09:17
Start Date: 27/Sep/19 09:17
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r328967734
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,136 @@
+package org.apache.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > -1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > - 1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private long getCachedStartIndex(Path path) {
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  try {
+FSDataInputStream fis = path.getFileSystem(conf).open(path);
+for (int j = 0; j < headerCount; j++) {
+  fis.readLine();
+  // back 1 byte because readers skip the entire first row if split 
start is not 0
+  startIndexForFile = fis.getPos() - 1;
+}
+  } catch (IOException e) {
+startIndexForFile = 0L;
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;
+  }
+
+  private long getCachedEndIndex(Path path) {
+Long endIndexForFile = endIndexMap.get(path);
+if (endIndexForFile == null) {
+  try {
+final long bufferSectionSize = 1024;
+long bufferSectionEnd = 
path.getFileSystem(conf).getFileStatus(path).getLen();
 
 Review comment:
   We can have a special handling for footerCount = 0. We can return the actual 
length of file.
 

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:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 319438)
Time Spent: 50m  (was: 40m)

> Split text files even if header/footer exists
> -
>
> Key: HIVE-21924
> URL: https://issues.apache.org/jira/browse/HIVE-21924
> Project: Hive
>  Issue Type: Improvement
>  Components: File Formats
> 

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-09-27 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=319441=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-319441
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 27/Sep/19 09:17
Start Date: 27/Sep/19 09:17
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r328919993
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,136 @@
+package org.apache.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > -1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > - 1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private long getCachedStartIndex(Path path) {
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  try {
+FSDataInputStream fis = path.getFileSystem(conf).open(path);
+for (int j = 0; j < headerCount; j++) {
+  fis.readLine();
+  // back 1 byte because readers skip the entire first row if split 
start is not 0
+  startIndexForFile = fis.getPos() - 1;
+}
+  } catch (IOException e) {
+startIndexForFile = 0L;
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;
+  }
+
+  private long getCachedEndIndex(Path path) {
+Long endIndexForFile = endIndexMap.get(path);
+if (endIndexForFile == null) {
+  try {
+final long bufferSectionSize = 1024;
+long bufferSectionEnd = 
path.getFileSystem(conf).getFileStatus(path).getLen();
+long bufferSectionStart = Math.max(0, bufferSectionEnd - 
bufferSectionSize);
+Queue lineEndBuffer = new ArrayDeque(headerCount + 1);
+FSDataInputStream fis = path.getFileSystem(conf).open(path);
+fis.seek(bufferSectionStart);
+while (bufferSectionEnd > bufferSectionStart) {
+  fis.seek(bufferSectionStart);
+  long pos = fis.getPos();
+  while (pos < bufferSectionEnd) {
+fis.readLine();
+pos = fis.getPos();
+if (pos <= bufferSectionEnd) {
+  if (lineEndBuffer.size() > footerCount) {
+lineEndBuffer.poll();
+  }
+  lineEndBuffer.add(pos);
+}
+  }
+  if (lineEndBuffer.size() > footerCount) {
+break;
+  } else {
+bufferSectionEnd = 

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-09-27 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=319435=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-319435
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 27/Sep/19 09:17
Start Date: 27/Sep/19 09:17
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r328914761
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,136 @@
+package org.apache.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > -1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > - 1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private long getCachedStartIndex(Path path) {
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  try {
+FSDataInputStream fis = path.getFileSystem(conf).open(path);
+for (int j = 0; j < headerCount; j++) {
+  fis.readLine();
+  // back 1 byte because readers skip the entire first row if split 
start is not 0
+  startIndexForFile = fis.getPos() - 1;
 
 Review comment:
   Can we move this outside the loop?
   Also, as per current logic, if data have only footer rows and headerCount=0, 
then startIndexForFile will be null. Having this statement outside the loop 
would handle it.
 

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:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 319435)
Time Spent: 40m  (was: 0.5h)

> Split text files even if header/footer exists
> -
>
> Key: HIVE-21924
> URL: https://issues.apache.org/jira/browse/HIVE-21924
> Project: Hive
>  Issue Type: Improvement
>  Components: File Formats
>Affects Versions: 2.4.0, 4.0.0, 3.2.0
>Reporter: Prasanth Jayachandran
>Assignee: Mustafa Iman
>Priority: Major
>  Labels: pull-request-available
> Attachments: HIVE-21924.patch
>
>  Time Spent: 40m
>  Remaining Estimate: 0h
>
> 

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-09-27 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=319434=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-319434
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 27/Sep/19 09:17
Start Date: 27/Sep/19 09:17
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r328918236
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,136 @@
+package org.apache.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > -1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > - 1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private long getCachedStartIndex(Path path) {
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  try {
+FSDataInputStream fis = path.getFileSystem(conf).open(path);
+for (int j = 0; j < headerCount; j++) {
+  fis.readLine();
+  // back 1 byte because readers skip the entire first row if split 
start is not 0
+  startIndexForFile = fis.getPos() - 1;
+}
+  } catch (IOException e) {
+startIndexForFile = 0L;
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;
+  }
+
+  private long getCachedEndIndex(Path path) {
+Long endIndexForFile = endIndexMap.get(path);
+if (endIndexForFile == null) {
+  try {
+final long bufferSectionSize = 1024;
+long bufferSectionEnd = 
path.getFileSystem(conf).getFileStatus(path).getLen();
+long bufferSectionStart = Math.max(0, bufferSectionEnd - 
bufferSectionSize);
+Queue lineEndBuffer = new ArrayDeque(headerCount + 1);
+FSDataInputStream fis = path.getFileSystem(conf).open(path);
 
 Review comment:
   fis.close() needed in finally block.
 

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:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 319434)

> Split text files even if header/footer exists
> -
>
> Key: HIVE-21924
> URL: 

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-09-27 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=319442=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-319442
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 27/Sep/19 09:17
Start Date: 27/Sep/19 09:17
Worklog Time Spent: 10m 
  Work Description: sankarh commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791#discussion_r328981037
 
 

 ##
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/io/SkippingTextInputFormat.java
 ##
 @@ -0,0 +1,136 @@
+package org.apache.hadoop.hive.ql.io;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * SkippingInputFormat is a header/footer aware input format. It truncates
+ * splits identified by TextInputFormat. Header and footers are removed
+ * from the splits.
+ */
+public class SkippingTextInputFormat extends TextInputFormat {
+
+  private final Map startIndexMap = new ConcurrentHashMap();
+  private final Map endIndexMap = new ConcurrentHashMap();
+  private JobConf conf;
+  private int headerCount;
+  private int footerCount;
+
+  @Override
+  public void configure(JobConf conf) {
+this.conf = conf;
+super.configure(conf);
+  }
+
+  public void configure(JobConf conf, int headerCount, int footerCount) {
+configure(conf);
+this.headerCount = headerCount;
+this.footerCount = footerCount;
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > -1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts);
+  }
+
+  @Override
+  protected FileSplit makeSplit(Path file, long start, long length, String[] 
hosts, String[] inMemoryHosts) {
+long cachedStart = getCachedStartIndex(file);
+long cachedEnd = getCachedEndIndex(file);
+if (cachedStart > start + length) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedStart > start) {
+  length = length - (cachedStart - start);
+  start = cachedStart;
+}
+if (cachedEnd > - 1 && cachedEnd < start) {
+  return new NullRowsInputFormat.DummyInputSplit(file);
+} else if (cachedEnd < start + length) {
+  length = cachedEnd - start;
+}
+return super.makeSplit(file, start, length, hosts, inMemoryHosts);
+  }
+
+  private long getCachedStartIndex(Path path) {
+Long startIndexForFile = startIndexMap.get(path);
+if (startIndexForFile == null) {
+  try {
+FSDataInputStream fis = path.getFileSystem(conf).open(path);
+for (int j = 0; j < headerCount; j++) {
+  fis.readLine();
+  // back 1 byte because readers skip the entire first row if split 
start is not 0
+  startIndexForFile = fis.getPos() - 1;
+}
+  } catch (IOException e) {
+startIndexForFile = 0L;
+  }
+  startIndexMap.put(path, startIndexForFile);
+}
+return startIndexForFile;
+  }
+
+  private long getCachedEndIndex(Path path) {
+Long endIndexForFile = endIndexMap.get(path);
+if (endIndexForFile == null) {
+  try {
+final long bufferSectionSize = 1024;
+long bufferSectionEnd = 
path.getFileSystem(conf).getFileStatus(path).getLen();
+long bufferSectionStart = Math.max(0, bufferSectionEnd - 
bufferSectionSize);
+Queue lineEndBuffer = new ArrayDeque(headerCount + 1);
+FSDataInputStream fis = path.getFileSystem(conf).open(path);
+fis.seek(bufferSectionStart);
+while (bufferSectionEnd > bufferSectionStart) {
+  fis.seek(bufferSectionStart);
+  long pos = fis.getPos();
+  while (pos < bufferSectionEnd) {
+fis.readLine();
+pos = fis.getPos();
+if (pos <= bufferSectionEnd) {
+  if (lineEndBuffer.size() > footerCount) {
+lineEndBuffer.poll();
+  }
+  lineEndBuffer.add(pos);
+}
+  }
+  if (lineEndBuffer.size() > footerCount) {
+break;
+  } else {
+bufferSectionEnd = 

[jira] [Work logged] (HIVE-21924) Split text files even if header/footer exists

2019-09-26 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/HIVE-21924?focusedWorklogId=319283=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-319283
 ]

ASF GitHub Bot logged work on HIVE-21924:
-

Author: ASF GitHub Bot
Created on: 26/Sep/19 23:52
Start Date: 26/Sep/19 23:52
Worklog Time Spent: 10m 
  Work Description: mustafaiman commented on pull request #791: HIVE-21924
URL: https://github.com/apache/hive/pull/791
 
 
   
 

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:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 319283)
Remaining Estimate: 0h
Time Spent: 10m

> Split text files even if header/footer exists
> -
>
> Key: HIVE-21924
> URL: https://issues.apache.org/jira/browse/HIVE-21924
> Project: Hive
>  Issue Type: Improvement
>  Components: File Formats
>Affects Versions: 2.4.0, 4.0.0, 3.2.0
>Reporter: Prasanth Jayachandran
>Assignee: Mustafa Iman
>Priority: Major
>  Labels: pull-request-available
> Attachments: HIVE-21924.patch
>
>  Time Spent: 10m
>  Remaining Estimate: 0h
>
> https://github.com/apache/hive/blob/967a1cc98beede8e6568ce750ebeb6e0d048b8ea/ql/src/java/org/apache/hadoop/hive/ql/io/HiveInputFormat.java#L494-L503
>  
> {code}
> int headerCount = 0;
> int footerCount = 0;
> if (table != null) {
>   headerCount = Utilities.getHeaderCount(table);
>   footerCount = Utilities.getFooterCount(table, conf);
>   if (headerCount != 0 || footerCount != 0) {
> // Input file has header or footer, cannot be splitted.
> HiveConf.setLongVar(conf, ConfVars.MAPREDMINSPLITSIZE, 
> Long.MAX_VALUE);
>   }
> }
> {code}
> this piece of code makes the CSV (or any text files with header/footer) files 
> not splittable if header or footer is present. 
> If only header is present, we can find the offset after first line break and 
> use that to split. Similarly for footer, may be read few KB's of data at the 
> end and find the last line break offset. Use that to determine the data range 
> which can be used for splitting. Few reads during split generation are 
> cheaper than not splitting the file at all.  



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