Skip to content

Commit 95c253e

Browse files
author
jmorton
committed
Split apart Extract creation into an ExtractAdapter, to support Hyper extracts in the future. Add Makefile for managing releases
1 parent b92aaf8 commit 95c253e

File tree

15 files changed

+312
-172
lines changed

15 files changed

+312
-172
lines changed

Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
MKDIR_P = mkdir -p
2+
NAME = tableau-sdk-wrapper
3+
VERSION = 1.1
4+
BUILD_DIR = ${NAME}-${VERSION}
5+
ARTIFACT = tableau-${VERSION}.jar
6+
ARCHIVE = ${NAME}-${VERSION}.zip
7+
TARGET = target
8+
SAMPLES = samples
9+
BIN_DIR = bin
10+
11+
all: mkdir copy_files archive
12+
13+
mkdir:
14+
${MKDIR_P} ${BUILD_DIR}/bin
15+
${MKDIR_P} ${BUILD_DIR}/lib
16+
${MKDIR_P} ${BUILD_DIR}/samples
17+
${MKDIR_P} ${BUILD_DIR}/tmp
18+
${MKDIR_P} ${BUILD_DIR}/logs
19+
20+
copy_files:
21+
cp ${TARGET}/${ARTIFACT} ${BUILD_DIR}/lib
22+
cp -a ${SAMPLES}/* ${BUILD_DIR}/samples/
23+
cp -a ${BIN_DIR}/* ${BUILD_DIR}/bin/
24+
25+
archive:
26+
zip -r ${ARCHIVE} ${BUILD_DIR}
27+
28+
clean:
29+
rm -rf ${BUILD_DIR}
30+
rm -f ${ARCHIVE}

bin/extract.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.."
33
LIB="$DIR/lib"
44
MAX_MEMORY="2g"
5-
JARFILE="$LIB/tableau-1.0.jar"
5+
JARFILE="$LIB/tableau-1.1.jar"
66
SDK_DIR="$LIB/tableausdk-linux64-10300.18.0510.1135"
77
JAVA_SDK_DIR="$SDK_DIR/lib64/tableausdk/Java/"
88

bin/publish.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
33
BASE_PATH="$DIR/..";
44
LIB="$BASE_PATH/lib"
5-
JARFILE="$LIB/tableau-1.0.jar"
5+
JARFILE="$LIB/tableau-1.1.jar"
66
SDK_DIR="$LIB/tableausdk-linux64-10300.18.0510.1135"
77
JAVA_SDK_DIR="$SDK_DIR/lib64/tableausdk/Java/"
88

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>net.jlmorton</groupId>
66
<artifactId>tableau</artifactId>
7-
<version>1.0</version>
7+
<version>1.1</version>
88
<properties>
99
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1010
<java.language.version>1.8</java.language.version>

src/main/java/net/jlmorton/tableau/CommandLinePropertySource.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package net.jlmorton.tableau;
22

33
import org.apache.commons.cli.*;
4+
import org.apache.logging.log4j.LogManager;
5+
import org.apache.logging.log4j.Logger;
46

57
import java.io.File;
8+
import java.io.IOException;
69

710
class CommandLinePropertySource {
11+
private static final Logger LOGGER = LogManager.getLogger(CommandLinePropertySource.class);
12+
813
private final String[] args;
914

1015
CommandLinePropertySource(String... args) {
@@ -16,8 +21,9 @@ Properties getProperties() {
1621

1722
return new Properties() {
1823
@Override
19-
public String getSchemaPath() {
20-
return commandLine.getOptionValue("schema");
24+
public Schema getSchema() {
25+
String schemaPath = commandLine.getOptionValue("schema");
26+
return createSchemaFromJson(schemaPath);
2127
}
2228

2329
@Override
@@ -79,13 +85,18 @@ public boolean isExtract() {
7985
return commandLine.hasOption("extract");
8086
}
8187

82-
@Override
83-
public boolean isAppend() {
84-
return commandLine.hasOption("append");
85-
}
8688
};
8789
}
8890

91+
private Schema createSchemaFromJson(String schemaPath) {
92+
try {
93+
return Schema.fromJson(schemaPath);
94+
} catch (IOException e) {
95+
LOGGER.error("Error creating schema with path {}", schemaPath, e);
96+
throw new RuntimeException(e);
97+
}
98+
}
99+
89100
private CommandLine parseCommandLineOptions() {
90101
CommandLineParser parser = new DefaultParser();
91102

@@ -97,6 +108,7 @@ private CommandLine parseCommandLineOptions() {
97108

98109
return commandLine;
99110
} catch (ParseException e) {
111+
LOGGER.error("Could not parse command line options", e);
100112
throw new RuntimeException("Could not parse command line options", e);
101113
}
102114
}
@@ -105,13 +117,11 @@ private static Options getOptions() {
105117
Options options = new Options();
106118
options.addOption("s", "schema", true, "Schema file for extract");
107119
options.addOption("f", "file", true, "CSV file to import");
108-
options.addOption("a", "append", false, "Append to existing extract");
109-
options.addOption("o", "output", true, "Output file name, or name of existing extract in append mode");
110120
options.addOption("t", "threads", true, "Number of threads (default: 1)");
111121
options.addOption("p", "publish", false, "Publish an extract to Tableau (requires --extract, --site, --project, --datasource, --username --password, and --url,");
112122
options.addOption("s", "site", true, "Tableau site name to publish");
113123
options.addOption("c", "project", true, "Project name to publish to");
114-
options.addOption("e", "extract", true, "Filename of extract to publish");
124+
options.addOption("e", "extract", true, "Filename of extract");
115125
options.addOption("d", "datasource", true, "Name of datasource to publish");
116126
options.addOption("u", "url", true, "Tableau Server URL for publishing");
117127
options.addOption("n", "username", true, "Tableau Server username for publishing");
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package net.jlmorton.tableau;
2+
3+
import com.tableausoftware.TableauException;
4+
import com.tableausoftware.extract.Row;
5+
import com.tableausoftware.extract.TableDefinition;
6+
7+
public interface ExtractAdapter {
8+
void openExtract() throws TableauException;
9+
10+
void closeExtract();
11+
12+
void insertRow(Row row) throws TableauException;
13+
14+
TableDefinition getTableDefinition();
15+
16+
default String getTableName() {
17+
return "Extract";
18+
}
19+
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package net.jlmorton.tableau;
22

3-
import com.tableausoftware.extract.Extract;
3+
import com.tableausoftware.TableauException;
44

55
public interface ExtractWriter {
6-
Extract createExtract();
6+
void writeExtract() throws TableauException;
7+
8+
void closeExtract();
79
}

src/main/java/net/jlmorton/tableau/ExtractWriterImpl.java

Lines changed: 0 additions & 130 deletions
This file was deleted.

src/main/java/net/jlmorton/tableau/Main.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package net.jlmorton.tableau;
22

33
import com.tableausoftware.TableauException;
4-
import com.tableausoftware.extract.Extract;
54
import org.apache.commons.lang3.StringUtils;
65
import org.apache.logging.log4j.LogManager;
76
import org.apache.logging.log4j.Logger;
87

98
import java.io.File;
10-
import java.io.IOException;
119
import java.util.Objects;
1210

1311
public class Main {
@@ -44,21 +42,20 @@ private static void publish(Properties properties) throws TableauException {
4442
Publisher.publish(properties);
4543
}
4644

47-
private static void createExtract(Properties properties) throws IOException {
45+
private static void createExtract(Properties properties) throws TableauException {
4846
validatePropertiesForExtract(properties);
4947

50-
Schema schema = Schema.fromJson(properties.getSchemaPath());
51-
52-
LOGGER.info("Creating Extract {}", schema.getName());
48+
LOGGER.info("Creating Extract {}", properties.getSchema().getName());
5349
LOGGER.info("CSV File Path: {}", properties.getCsvFile());
5450
LOGGER.info("Extract Path: {}", properties.getExtractFilePath());
5551
LOGGER.info("Number of Threads: {}", properties.getNumberOfThreads());
5652

5753
RowInputSource rowInputSource = new CsvInputSource(properties.getCsvFile());
54+
ExtractAdapter extractAdapter = new TdeExtractAdapter(properties);
5855

59-
ExtractWriter extractWriter = new ExtractWriterImpl(schema, rowInputSource, properties);
60-
Extract extract = extractWriter.createExtract();
61-
extract.close();
56+
ExtractWriter extractWriter = new MultiThreadedExtractWriter(properties, rowInputSource, extractAdapter);
57+
extractWriter.writeExtract();
58+
extractWriter.closeExtract();
6259
}
6360

6461
private static void validatePropertiesForPublishing(Properties properties) {
@@ -84,7 +81,7 @@ private static void validatePropertiesForPublishing(Properties properties) {
8481
private static void validatePropertiesForExtract(Properties properties) {
8582
boolean hasExtractPath = !Objects.isNull(properties.getExtractFilePath());
8683
boolean hasCsvFilePath = !Objects.isNull(properties.getCsvFile());
87-
boolean hasSchemaPath = StringUtils.isNotBlank(properties.getSchemaPath());
84+
boolean hasSchemaPath = !Objects.isNull(properties.getSchema());
8885

8986
if (!(hasExtractPath && hasCsvFilePath && hasSchemaPath)) {
9087
LOGGER.error("Must provide extract path, CSV file path, and Schema path when creating an extract");

0 commit comments

Comments
 (0)