Skip to content

Commit 73319c9

Browse files
authored
Merge branch 'develop' into feature/add_ci_test
2 parents 9b38603 + 317fc7e commit 73319c9

File tree

5 files changed

+85
-31
lines changed

5 files changed

+85
-31
lines changed

.github/workflows/main.yml

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,22 @@ on:
1616
types: [labeled]
1717

1818
jobs:
19-
main:
19+
test:
20+
name: test
2021
runs-on: ubuntu-latest
2122
if: >
2223
${{
2324
github.event_name == 'pull_request' ||
2425
(github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'safe to test')) ||
2526
startsWith(github.ref, 'refs/tags/')
2627
}}
27-
permissions:
28-
packages: write
29-
contents: read
30-
3128
steps:
32-
- uses: actions/checkout@v1
29+
- uses: actions/checkout@v2
3330
- name: Set up JDK 1.8
3431
uses: actions/setup-java@v1
3532
with:
3633
java-version: 1.8
3734
- name: lint
38-
# Run ./gradlew spotlessApply when failing on this step.
3935
run: ./gradlew spotlessCheck
4036
- name: Write test secret to file
4137
run: envsubst < ci/config_template.yml > test-config.yml
@@ -50,22 +46,23 @@ jobs:
5046
- run: ./gradlew test
5147
env:
5248
EMBULK_OUTPUT_DATABRICKS_TEST_CONFIG: "./test-config.yml"
53-
- name: Show Current Version
54-
run: ./gradlew printVersion
55-
- name: Build Gem & Put it into './build/gems/' Directory
56-
run: ./gradlew gem
57-
- name: Set up JRuby
49+
build:
50+
name: Build + Publish
51+
runs-on: ubuntu-latest
52+
permissions:
53+
packages: write
54+
contents: read
55+
needs: [ test ]
56+
if: ${{ github.event_name == 'workflow_dispatch' || contains(github.ref, 'refs/tags/') }}
57+
steps:
58+
- uses: actions/checkout@v2
59+
- name: Set up Ruby 2.7
5860
uses: ruby/setup-ruby@v1
5961
with:
60-
ruby-version: jruby
61-
- name: Publish to GPR
62-
if: startsWith( github.ref, 'refs/tags/' )
63-
run: |
64-
mkdir -p $HOME/.gem
65-
touch $HOME/.gem/credentials
66-
chmod 0600 $HOME/.gem/credentials
67-
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
68-
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} ./build/gems/*.gem
69-
env:
70-
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
71-
OWNER: ${{ github.repository_owner }}
62+
ruby-version: 2.7
63+
- name: push gem
64+
uses: trocco-io/push-gem-to-gpr-action@v1
65+
with:
66+
language: java
67+
gem-path: "./pkg/*.gem"
68+
github-token: "${{ secrets.GITHUB_TOKEN }}"

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ Databricks output plugin for Embulk loads records to Databricks Delta Table.
5959
* Transactional: Yes.
6060
* Resumable: No.
6161

62+
## Note
63+
64+
This plugin does not support TIMESTAMP_NTZ、INTERVAL types, if target tables contain these types, embulk will raise a runtime error.
65+
(Because [The official Databricks JDBC driver does not support TIMESTAMP_NTZ、INTERVAL types](https://docs.databricks.com/en/sql/language-manual/data-types/timestamp-ntz-type.html#notes).)
66+
67+
This plugin converts empty string input to null output. If you want to empty string output, you can use continuous double quote string ("").
68+
6269
## Build
6370

6471
```
@@ -67,4 +74,4 @@ $ ./gradlew gem # -t to watch change of files and rebuild continuously
6774

6875
## TEST
6976

70-
$ EMBULK_OUTPUT_DATABRICKS_TEST_CONFIG="example/test.yml" ./gradlew test # Create exxample/test.yml based on example/test.yml.example
77+
$ EMBULK_OUTPUT_DATABRICKS_TEST_CONFIG="example/test.yml" ./gradlew test # Create example/test.yml based on example/test.yml.example

example/test.yml.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# The catalog_name and schema_name must be created in advance.
2+
13
server_hostname:
24
http_path:
35
personal_access_token:

src/test/java/org/embulk/output/databricks/TestDatabricksOutputPluginByMode.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,23 +127,35 @@ public void testMergeToExistTableWithMergeRules2() throws Exception {
127127
assertQueryResults("test0,0,a", "test1,1test89,bTESTB", "test2,12,C");
128128
}
129129

130+
@Test
131+
public void testMergeNoKeyToExistTable() throws Exception {
132+
setPluginConfigSource(AbstractJdbcOutputPlugin.Mode.MERGE);
133+
String[] sqlTypes = sqlStringTypes(2);
134+
ConnectionUtil.run(
135+
String.format("CREATE TABLE %s (_c0 STRING PRIMARY KEY, _c1 STRING)", quotedDstTableName));
136+
ConnectionUtil.run(insertSQL(quotedDstTableName, sqlTypes, "test0,0", "test1,1"));
137+
embulk.runOutput(configSource, createInputFile("test1,11", "test2,12").toPath());
138+
assertQueryResults("test0,0", "test1,11", "test2,12");
139+
}
140+
130141
private void setMergeRule(String... mergeRules) {
131142
configSource.set("merge_rule", Arrays.asList(mergeRules));
132143
}
133144

134145
private void setPluginConfigSource(AbstractJdbcOutputPlugin.Mode mode, String... mergeKeys) {
135-
configSource = createPluginConfigSource(mode, Arrays.asList(mergeKeys));
146+
configSource =
147+
createPluginConfigSource(mode, mergeKeys.length > 0 ? Arrays.asList(mergeKeys) : null);
136148
quotedDstTableName = quotedDstTableName(configSource);
137149
}
138150

139151
private void createTable(String... rows) {
140-
String[] sqlTypes = sqlTypes(rows[0]);
152+
String[] sqlTypes = sqlStringTypes(rows[0]);
141153
ConnectionUtil.run(createTableSQL(quotedDstTableName, sqlTypes));
142154
ConnectionUtil.run(insertSQL(quotedDstTableName, sqlTypes, rows));
143155
}
144156

145157
private File createInputFile(String... rows) throws IOException {
146-
return IOUtil.createInputFile(testFolder, csvHeader(sqlTypes(rows[0])), rows);
158+
return IOUtil.createInputFile(testFolder, csvHeader(sqlStringTypes(rows[0])), rows);
147159
}
148160

149161
private void assertQueryResults(String... rows) {
@@ -161,8 +173,12 @@ private void assertQueryResults(String... rows) {
161173
assertTableResults(results, numberOfColumns, data.toArray());
162174
}
163175

164-
private String[] sqlTypes(String sampleRow) {
176+
private String[] sqlStringTypes(String sampleRow) {
165177
int numberOfColumns = sampleRow.split(",").length;
178+
return sqlStringTypes(numberOfColumns);
179+
}
180+
181+
private String[] sqlStringTypes(int numberOfColumns) {
166182
return IntStream.range(0, numberOfColumns).mapToObj(x -> "string").toArray(String[]::new);
167183
}
168184
}

src/test/java/org/embulk/output/databricks/TestDatabricksOutputPluginByTimestamp.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.embulk.output.databricks;
22

33
import java.io.IOException;
4+
import java.sql.Timestamp;
45
import java.time.ZoneId;
56
import org.junit.Test;
67

@@ -9,13 +10,30 @@ public class TestDatabricksOutputPluginByTimestamp extends AbstractTestDatabrick
910
public void testTimestamp() throws IOException {
1011
testOutputValues(
1112
new TestTimestampSet(
12-
"2000-01-02 03:04:05.00 UTC", "%Y/%m/%d %H-%M-%S", null, "2000/01/02 03-04-05"),
13+
"2000-01-02 03:04:05.00 UTC",
14+
"%Y-%m-%d",
15+
null,
16+
Timestamp.valueOf("2000-01-02 00:00:00.0")),
17+
new TestTimestampSet(
18+
"2000-01-02 03:04:05.00 UTC", "%Y", null, Timestamp.valueOf("2000-01-01 00:00:00.0")),
1319
new TestTimestampSet(
20+
"2000-01-02 20:04:05.00 UTC",
21+
"%Y-%m-%d",
22+
ZoneId.of("Asia/Tokyo"),
23+
Timestamp.valueOf("2000-01-03 00:00:00.0")));
24+
}
25+
26+
@Test
27+
public void testTimestampToString() throws IOException {
28+
testOutputValues(
29+
new TestTimestampToStringSet(
30+
"2000-01-02 03:04:05.00 UTC", "%Y/%m/%d %H-%M-%S", null, "2000/01/02 03-04-05"),
31+
new TestTimestampToStringSet(
1432
"2000-01-02 03:04:05.00 UTC",
1533
null,
1634
ZoneId.of("Asia/Tokyo"),
1735
"2000-01-02 12:04:05.000000"),
18-
new TestTimestampSet(
36+
new TestTimestampToStringSet(
1937
"2000-01-02 03:04:05.00 UTC",
2038
"%Y/%m/%d %H-%M-%S",
2139
ZoneId.of("Asia/Tokyo"),
@@ -25,6 +43,20 @@ public void testTimestamp() throws IOException {
2543
protected class TestTimestampSet extends TestSet {
2644
TestTimestampSet(
2745
String value, String outputTimestampFormat, ZoneId outputTimezone, Object expected) {
46+
super(
47+
value,
48+
"timestamp",
49+
"timestamp",
50+
"string",
51+
outputTimestampFormat,
52+
outputTimezone,
53+
expected);
54+
}
55+
}
56+
57+
protected class TestTimestampToStringSet extends TestSet {
58+
TestTimestampToStringSet(
59+
String value, String outputTimestampFormat, ZoneId outputTimezone, Object expected) {
2860
super(value, "timestamp", "string", null, outputTimestampFormat, outputTimezone, expected);
2961
}
3062
}

0 commit comments

Comments
 (0)