Skip to content

Commit 08859f0

Browse files
author
jmorton
committed
Initial commit
1 parent 0d6836e commit 08859f0

28 files changed

+1266
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea/
2+
target/
3+
dependency-reduced-pom.xml
4+
tableau.iml

bin/extract.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.."
3+
LIB="$DIR/lib"
4+
MAX_MEMORY="2g"
5+
JARFILE="$LIB/tableau-1.0.jar"
6+
SDK_DIR="$LIB/tableausdk-linux64-10300.18.0510.1135"
7+
JAVA_SDK_DIR="$SDK_DIR/lib64/tableausdk/Java/"
8+
9+
export LD_LIBRARY_PATH="$SDK_DIR/lib64/tableausdk"
10+
11+
usage() { echo "Usage: $0 -s <schema> -f <input file> -o <output file> [-t <threads>] [-a, --append]"; }
12+
while getopts ":s:f:o:t:ah" i; do
13+
case "${i}" in
14+
s) schema=${OPTARG};;
15+
f) inputFile=${OPTARG};;
16+
o) outputFile=${OPTARG};;
17+
t) numThreads=${OPTARG};;
18+
a) optionalArguments="--append";;
19+
h) java -jar $JARFILE -help;;
20+
esac
21+
done
22+
shift $((OPTIND-1))
23+
24+
numThreads=${numThreads:-1} # Default to 1
25+
26+
if [[ -z $schema ]] || [[ -z $inputFile ]] || [[ -z $outputFile ]]; then
27+
usage
28+
exit
29+
fi
30+
31+
java -Xmx${MAX_MEMORY} -XX:-UseCompressedOops -XX:+UseConcMarkSweepGC -jar $JARFILE --schema $schema --threads $numThreads --file $inputFile --extract $outputFile $optionalArguments
32+

bin/install_tableau_sdk.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.."
3+
TMP="$DIR/tmp"
4+
LIB_DIR="$DIR/lib"
5+
SDK_DIR="$LIB_DIR/tableausdk-linux64-10300.18.0510.1135"
6+
JAVA_SDK_DIR="$SDK_DIR/lib64/tableausdk/Java/"
7+
TMP_SDK_NAME="$TMP/TableauSDK.tar.gz"
8+
TABLEAU64_SDK_URL="https://downloads.tableau.com/tssoftware/Tableau-SDK-Linux-64Bit-10-3-11.tar.gz"
9+
TABLEAU32_SDK_URL="https://downloads.tableau.com/tssoftware/Tableau-SDK-Linux-32Bit-10-3-11.tar.gz"
10+
11+
function download() {
12+
URL=$1
13+
if type wget &>/dev/null; then
14+
wget -O $TMP_SDK_NAME $URL
15+
elif type curl &>/dev/null; then
16+
curl -o $TMP_SDK_NAME $URL
17+
else
18+
echo "Error: Could not find wget or curl to install Tableau SDK"
19+
exit 1
20+
fi
21+
}
22+
23+
MACHINE_TYPE=`uname -m`
24+
echo "==============================================="
25+
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
26+
echo "Downloading 64-bit TableauSDK based on detected machine type."
27+
download $TABLEAU64_SDK_URL
28+
else
29+
echo "Downloading 32-bit TableauSDK based on detected machine type."
30+
download $TABLEAU32_SDK_URL
31+
fi;
32+
33+
if [[ ! -s $TMP_SDK_NAME ]]; then
34+
echo "Could not download Tableau SDK"
35+
exit 1
36+
fi;
37+
38+
echo "Extracting Tableau SDK to $LIB_DIR"
39+
tar -C $LIB_DIR -xzf $TMP_SDK_NAME
40+
41+
echo "Installing Maven Dependencies"
42+
mvn install:install-file -Dfile=$JAVA_SDK_DIR/jna.jar -DgroupId=com.sun.jna -DartifactId=jna -Dversion=3.5.1 -Dpackaging=jar
43+
mvn install:install-file -Dfile=$JAVA_SDK_DIR/tableaucommon.jar -DgroupId=com.tableausoftware -DartifactId=tableau-common -Dversion=10.3.11 -Dpackaging=jar
44+
mvn install:install-file -Dfile=$JAVA_SDK_DIR/tableauextract.jar -DgroupId=com.tableausoftware -DartifactId=tableau-extract -Dversion=10.3.11 -Dpackaging=jar
45+
mvn install:install-file -Dfile=$JAVA_SDK_DIR/tableauserver.jar -DgroupId=com.tableausoftware -DartifactId=tableau-server -Dversion=10.3.11 -Dpackaging=jar

bin/publish.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
BASE_PATH="$DIR/..";
4+
LIB="$BASE_PATH/lib"
5+
JARFILE="$LIB/tableau-1.0.jar"
6+
SDK_DIR="$LIB/tableausdk-linux64-10300.18.0510.1135"
7+
JAVA_SDK_DIR="$SDK_DIR/lib64/tableausdk/Java/"
8+
9+
export LD_LIBRARY_PATH="$SDK_DIR/lib64/tableausdk"
10+
11+
#export http_proxy="http://$PROXY_HOST:$PROXY_PORT"
12+
#export https_proxy="http://$PROXY_HOST:$PROXY_PORT"
13+
14+
usage() { echo "Usage: $0 -e <extract path> -s <site name> -d <datasource name>"; }
15+
while getopts "e:s:d:p:" i; do
16+
case "${i}" in
17+
u) url=${OPTARG};;
18+
n) username=${OPTARG};;
19+
x) password=${OPTARG};;
20+
e) extract=${OPTARG};;
21+
s) site=${OPTARG};;
22+
d) datasource_name=${OPTARG};;
23+
p) project_name=${OPTARG};;
24+
h) java -jar $JARFILE -help;;
25+
esac
26+
done
27+
shift $((OPTIND-1))
28+
29+
if [[ -z $extract ]] || [[ -z $site ]] || [[ -z $datasource_name ]] || [[ -z $project_name ]]; then
30+
usage
31+
exit
32+
fi
33+
34+
java -jar $JARFILE -p -extract $extract -site $site -project $project_name -name $datasource_name

pom.xml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>net.jlmorton</groupId>
6+
<artifactId>tableau</artifactId>
7+
<version>1.0</version>
8+
<properties>
9+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10+
<java.language.version>1.8</java.language.version>
11+
</properties>
12+
13+
<repositories>
14+
<repository>
15+
<id>central</id>
16+
<name>Maven Central</name>
17+
<url>https://repo.maven.apache.org/maven2</url>
18+
<releases>
19+
<enabled>true</enabled>
20+
</releases>
21+
<snapshots>
22+
<enabled>true</enabled>
23+
</snapshots>
24+
</repository>
25+
</repositories>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>com.tableausoftware</groupId>
30+
<artifactId>tableau-server</artifactId>
31+
<version>10.3.11</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>com.tableausoftware</groupId>
35+
<artifactId>tableau-common</artifactId>
36+
<version>10.3.11</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>com.tableausoftware</groupId>
40+
<artifactId>tableau-extract</artifactId>
41+
<version>10.3.11</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>com.sun.jna</groupId>
45+
<artifactId>jna</artifactId>
46+
<version>3.5.1</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>com.univocity</groupId>
50+
<artifactId>univocity-parsers</artifactId>
51+
<version>2.4.1</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>com.fasterxml.jackson.core</groupId>
55+
<artifactId>jackson-databind</artifactId>
56+
<version>2.8.8</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.apache.commons</groupId>
60+
<artifactId>commons-lang3</artifactId>
61+
<version>3.7</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>commons-cli</groupId>
65+
<artifactId>commons-cli</artifactId>
66+
<version>1.4</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.apache.logging.log4j</groupId>
70+
<artifactId>log4j-api</artifactId>
71+
<version>2.11.0</version>
72+
</dependency>
73+
<dependency>
74+
<groupId>org.apache.logging.log4j</groupId>
75+
<artifactId>log4j-core</artifactId>
76+
<version>2.11.0</version>
77+
<scope>compile</scope>
78+
</dependency>
79+
<dependency>
80+
<groupId>commons-configuration</groupId>
81+
<artifactId>commons-configuration</artifactId>
82+
<version>1.10</version>
83+
</dependency>
84+
85+
86+
<!-- Test Dependencies -->
87+
<dependency>
88+
<groupId>junit</groupId>
89+
<artifactId>junit</artifactId>
90+
<version>4.4</version>
91+
<scope>test</scope>
92+
</dependency>
93+
</dependencies>
94+
95+
<build>
96+
<plugins>
97+
<plugin>
98+
<groupId>org.apache.maven.plugins</groupId>
99+
<artifactId>maven-compiler-plugin</artifactId>
100+
<version>2.3.2</version>
101+
<configuration>
102+
<encoding>${project.build.sourceEncoding}</encoding>
103+
<source>${java.language.version}</source>
104+
<target>${java.language.version}</target>
105+
</configuration>
106+
</plugin>
107+
<plugin>
108+
<groupId>org.apache.maven.plugins</groupId>
109+
<artifactId>maven-shade-plugin</artifactId>
110+
<version>3.0.0</version>
111+
<executions>
112+
<execution>
113+
<phase>package</phase>
114+
<goals>
115+
<goal>shade</goal>
116+
</goals>
117+
<configuration>
118+
<transformers>
119+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
120+
<mainClass>net.jlmorton.tableau.Main</mainClass>
121+
</transformer>
122+
</transformers>
123+
</configuration>
124+
</execution>
125+
</executions>
126+
</plugin>
127+
</plugins>
128+
</build>
129+
</project>

samples/test.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
foo,bar,baz,bax,test,test_time
2+
"Hello, World!", 100, true, 10.15, 2017-01-01, 2017-02-01 13:35:01.555555-08
3+
"こんにちは世界!", 200, false, 20.51, 2017-02-01, 2017-02-01 23:59:59.999999-00

samples/test.schema

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"schemaName": "Sample",
3+
"schema": {
4+
"foo": "CHAR_STRING",
5+
"bar": "INTEGER",
6+
"baz": "BOOLEAN",
7+
"bax": "DOUBLE",
8+
"test": "DATE",
9+
"test_time": "DATETIME"
10+
}
11+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package net.jlmorton.tableau;
2+
3+
import org.apache.commons.cli.*;
4+
5+
import java.io.File;
6+
7+
class CommandLinePropertySource {
8+
private final String[] args;
9+
10+
CommandLinePropertySource(String... args) {
11+
this.args = args;
12+
}
13+
14+
Properties getProperties() {
15+
CommandLine commandLine = parseCommandLineOptions();
16+
17+
return new Properties() {
18+
@Override
19+
public String getSchemaPath() {
20+
return commandLine.getOptionValue("schema");
21+
}
22+
23+
@Override
24+
public File getCsvFile() {
25+
return new File(commandLine.getOptionValue("file"));
26+
}
27+
28+
@Override
29+
public String getExtractFilePath() {
30+
return commandLine.getOptionValue("extract");
31+
}
32+
33+
@Override
34+
public String getTableauSiteName() {
35+
return commandLine.getOptionValue("site");
36+
}
37+
38+
@Override
39+
public String getTableauProjectName() {
40+
return commandLine.getOptionValue("project");
41+
}
42+
43+
@Override
44+
public String getTableauDatasourceName() {
45+
return commandLine.getOptionValue("datasource");
46+
}
47+
48+
@Override
49+
public String getTableauServerUrl() {
50+
return commandLine.getOptionValue("url");
51+
}
52+
53+
@Override
54+
public String getTableauServerUsername() {
55+
return commandLine.getOptionValue("username");
56+
}
57+
58+
@Override
59+
public String getTableauServerPassword() {
60+
return commandLine.getOptionValue("password");
61+
}
62+
63+
@Override
64+
public int getNumberOfThreads() {
65+
if (commandLine.hasOption("threads")) {
66+
return Integer.valueOf(commandLine.getOptionValue("threads"));
67+
}
68+
69+
return 1;
70+
}
71+
72+
@Override
73+
public boolean isPublish() {
74+
return commandLine.hasOption("publish");
75+
}
76+
77+
@Override
78+
public boolean isExtract() {
79+
return commandLine.hasOption("extract");
80+
}
81+
82+
@Override
83+
public boolean isAppend() {
84+
return commandLine.hasOption("append");
85+
}
86+
};
87+
}
88+
89+
private CommandLine parseCommandLineOptions() {
90+
CommandLineParser parser = new DefaultParser();
91+
92+
try {
93+
CommandLine commandLine = parser.parse(getOptions(), args);
94+
if (commandLine.hasOption("help")) {
95+
printHelp();
96+
}
97+
98+
return commandLine;
99+
} catch (ParseException e) {
100+
throw new RuntimeException("Could not parse command line options", e);
101+
}
102+
}
103+
104+
private static Options getOptions() {
105+
Options options = new Options();
106+
options.addOption("s", "schema", true, "Schema file for extract");
107+
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");
110+
options.addOption("t", "threads", true, "Number of threads (default: 1)");
111+
options.addOption("p", "publish", false, "Publish an extract to Tableau (requires --extract, --site, --project, --datasource, --username --password, and --url,");
112+
options.addOption("s", "site", true, "Tableau site name to publish");
113+
options.addOption("c", "project", true, "Project name to publish to");
114+
options.addOption("e", "extract", true, "Filename of extract to publish");
115+
options.addOption("d", "datasource", true, "Name of datasource to publish");
116+
options.addOption("u", "url", true, "Tableau Server URL for publishing");
117+
options.addOption("n", "username", true, "Tableau Server username for publishing");
118+
options.addOption("x", "password", true, "Tableau Server password for publishing");
119+
options.addOption("h", "help", false, "");
120+
121+
return options;
122+
}
123+
124+
static void printHelp() {
125+
HelpFormatter helpFormatter = new HelpFormatter();
126+
helpFormatter.printHelp("java -jar tableau.jar", getOptions());
127+
System.exit(1);
128+
}
129+
}

0 commit comments

Comments
 (0)