Skip to content

Commit 8e0ac1a

Browse files
authored
Merge pull request #276 from marklogic/feature/15791-refactor
MLE-15791 Refactored aggregate XML classes into a package
2 parents 24704c8 + 270bcdb commit 8e0ac1a

File tree

6 files changed

+21
-13
lines changed

6 files changed

+21
-13
lines changed

src/main/java/com/marklogic/spark/reader/file/FileContext.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
import java.util.Map;
1717
import java.util.zip.GZIPInputStream;
1818

19-
class FileContext extends ContextSupport implements Serializable {
19+
public class FileContext extends ContextSupport implements Serializable {
2020

2121
private SerializableConfiguration hadoopConfiguration;
2222
private final String encoding;
2323

24-
FileContext(Map<String, String> properties, SerializableConfiguration hadoopConfiguration) {
24+
public FileContext(Map<String, String> properties, SerializableConfiguration hadoopConfiguration) {
2525
super(properties);
2626
this.hadoopConfiguration = hadoopConfiguration;
2727
this.encoding = getStringOption(Options.READ_FILES_ENCODING);
@@ -42,7 +42,7 @@ boolean isGzip() {
4242
return "gzip".equalsIgnoreCase(getStringOption(Options.READ_FILES_COMPRESSION));
4343
}
4444

45-
InputStream openFile(String filePath) {
45+
public InputStream openFile(String filePath) {
4646
try {
4747
Path hadoopPath = new Path(filePath);
4848
FileSystem fileSystem = hadoopPath.getFileSystem(hadoopConfiguration.value());
@@ -54,7 +54,7 @@ InputStream openFile(String filePath) {
5454
}
5555
}
5656

57-
boolean isReadAbortOnFailure() {
57+
public boolean isReadAbortOnFailure() {
5858
if (hasOption(Options.READ_FILES_ABORT_ON_FAILURE)) {
5959
return Boolean.parseBoolean(getStringOption(Options.READ_FILES_ABORT_ON_FAILURE));
6060
}

src/main/java/com/marklogic/spark/reader/file/FilePartition.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import java.util.List;
66

7-
class FilePartition implements InputPartition {
7+
public class FilePartition implements InputPartition {
88

99
static final long serialVersionUID = 1;
1010

@@ -14,7 +14,7 @@ public FilePartition(List<String> paths) {
1414
this.paths = paths;
1515
}
1616

17-
List<String> getPaths() {
17+
public List<String> getPaths() {
1818
return paths;
1919
}
2020

src/main/java/com/marklogic/spark/reader/file/FilePartitionReaderFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.marklogic.spark.reader.file;
22

33
import com.marklogic.spark.Options;
4+
import com.marklogic.spark.reader.file.xml.AggregateXmlFileReader;
5+
import com.marklogic.spark.reader.file.xml.ZipAggregateXmlFileReader;
46
import org.apache.spark.sql.catalyst.InternalRow;
57
import org.apache.spark.sql.connector.read.InputPartition;
68
import org.apache.spark.sql.connector.read.PartitionReader;

src/main/java/com/marklogic/spark/reader/file/AggregateXmlFileReader.java renamed to src/main/java/com/marklogic/spark/reader/file/xml/AggregateXmlFileReader.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
package com.marklogic.spark.reader.file;
1+
package com.marklogic.spark.reader.file.xml;
22

33
import com.marklogic.spark.ConnectorException;
44
import com.marklogic.spark.Util;
5+
import com.marklogic.spark.reader.file.FileContext;
6+
import com.marklogic.spark.reader.file.FilePartition;
57
import org.apache.commons.io.IOUtils;
68
import org.apache.spark.sql.catalyst.InternalRow;
79
import org.apache.spark.sql.connector.read.PartitionReader;
810

911
import java.io.InputStream;
1012

11-
class AggregateXmlFileReader implements PartitionReader<InternalRow> {
13+
public class AggregateXmlFileReader implements PartitionReader<InternalRow> {
1214

1315
private final FilePartition filePartition;
1416
private final FileContext fileContext;
@@ -18,7 +20,7 @@ class AggregateXmlFileReader implements PartitionReader<InternalRow> {
1820
private InternalRow nextRowToReturn;
1921
private int filePathIndex = 0;
2022

21-
AggregateXmlFileReader(FilePartition filePartition, FileContext fileContext) {
23+
public AggregateXmlFileReader(FilePartition filePartition, FileContext fileContext) {
2224
this.filePartition = filePartition;
2325
this.fileContext = fileContext;
2426
}

src/main/java/com/marklogic/spark/reader/file/AggregateXmlSplitter.java renamed to src/main/java/com/marklogic/spark/reader/file/xml/AggregateXmlSplitter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
package com.marklogic.spark.reader.file;
1+
package com.marklogic.spark.reader.file.xml;
22

33
import com.marklogic.client.datamovement.XMLSplitter;
44
import com.marklogic.client.io.StringHandle;
55
import com.marklogic.spark.ConnectorException;
66
import com.marklogic.spark.Options;
7+
import com.marklogic.spark.reader.file.FileContext;
78
import org.apache.spark.sql.catalyst.InternalRow;
89
import org.apache.spark.sql.catalyst.expressions.GenericInternalRow;
910
import org.apache.spark.unsafe.types.ByteArray;

src/main/java/com/marklogic/spark/reader/file/ZipAggregateXmlFileReader.java renamed to src/main/java/com/marklogic/spark/reader/file/xml/ZipAggregateXmlFileReader.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
package com.marklogic.spark.reader.file;
1+
package com.marklogic.spark.reader.file.xml;
22

33
import com.marklogic.spark.ConnectorException;
44
import com.marklogic.spark.Util;
5+
import com.marklogic.spark.reader.file.FileContext;
6+
import com.marklogic.spark.reader.file.FilePartition;
7+
import com.marklogic.spark.reader.file.FileUtil;
58
import org.apache.commons.io.IOUtils;
69
import org.apache.spark.sql.catalyst.InternalRow;
710
import org.apache.spark.sql.connector.read.PartitionReader;
@@ -12,7 +15,7 @@
1215
import java.util.zip.ZipEntry;
1316
import java.util.zip.ZipInputStream;
1417

15-
class ZipAggregateXmlFileReader implements PartitionReader<InternalRow> {
18+
public class ZipAggregateXmlFileReader implements PartitionReader<InternalRow> {
1619

1720
private static final Logger logger = LoggerFactory.getLogger(ZipAggregateXmlFileReader.class);
1821

@@ -29,7 +32,7 @@ class ZipAggregateXmlFileReader implements PartitionReader<InternalRow> {
2932
private String currentFilePath;
3033
private ZipInputStream currentZipInputStream;
3134

32-
ZipAggregateXmlFileReader(FilePartition filePartition, FileContext fileContext) {
35+
public ZipAggregateXmlFileReader(FilePartition filePartition, FileContext fileContext) {
3336
this.fileContext = fileContext;
3437
this.filePartition = filePartition;
3538
this.openNextFile();

0 commit comments

Comments
 (0)