-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java csv destination #505
java csv destination #505
Changes from all commits
85f3d7e
8787d7c
a100b2c
e8cc2b9
54bf8ef
121d9b4
1300a65
ddf557a
c09b25a
9a3a1db
39bc4c7
6afcb67
020e1f8
dc81794
1aba6bd
4addc80
d35e670
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2020 Airbyte | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.airbyte.integrations.base; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public abstract class FailureTrackingConsumer<T> implements DestinationConsumer<T> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not in love with the name of this class. would love suggestions. |
||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(FailureTrackingConsumer.class); | ||
|
||
private boolean hasFailed = false; | ||
|
||
protected abstract void acceptTracked(T t) throws Exception; | ||
|
||
public void accept(T t) throws Exception { | ||
try { | ||
acceptTracked(t); | ||
} catch (Exception e) { | ||
hasFailed = true; | ||
throw e; | ||
} | ||
} | ||
|
||
protected abstract void close(boolean hasFailed) throws Exception; | ||
|
||
public void close() throws Exception { | ||
LOGGER.info("hasFailed: {}.", hasFailed); | ||
close(hasFailed); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,6 @@ | |
|
||
package io.airbyte.integrations.base; | ||
|
||
import java.nio.file.Path; | ||
|
||
public class JavaBaseConstants { | ||
|
||
public static String ARGS_CONFIG_KEY = "config"; | ||
|
@@ -36,8 +34,4 @@ public class JavaBaseConstants { | |
public static String ARGS_CATALOG_DESC = "input path for the catalog"; | ||
public static String ARGS_PATH_DESC = "path to the json-encoded state file"; | ||
|
||
// todo (cgardens) - this mount path should be passed in by the worker and read as an arg or | ||
// environment variable by the runner. | ||
public static Path LOCAL_MOUNT = Path.of("/local"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed the need for an integration to know about this. |
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2020 Airbyte | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.airbyte.integrations.base; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.doThrow; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class FailureTrackingConsumerTest { | ||
|
||
@Test | ||
void testNoFailure() throws Exception { | ||
final TestConsumer consumer = spy(new TestConsumer()); | ||
consumer.accept(""); | ||
consumer.close(); | ||
|
||
verify(consumer).close(false); | ||
} | ||
|
||
@Test | ||
void testWithFailure() throws Exception { | ||
final TestConsumer consumer = spy(new TestConsumer()); | ||
doThrow(new RuntimeException()).when(consumer).acceptTracked(""); | ||
|
||
// verify the exception still gets thrown. | ||
assertThrows(RuntimeException.class, () -> consumer.accept("")); | ||
consumer.close(); | ||
|
||
verify(consumer).close(true); | ||
} | ||
|
||
static class TestConsumer extends FailureTrackingConsumer<String> { | ||
|
||
@Override | ||
protected void acceptTracked(String s) { | ||
|
||
} | ||
|
||
@Override | ||
protected void close(boolean hasFailed) { | ||
|
||
} | ||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,9 @@ function main() { | |
# todo: state should be optional: --state "$STATE_FILE" | ||
eval "$AIRBYTE_READ_CMD" --config "$CONFIG_FILE" --catalog "$CATALOG_FILE" | ||
;; | ||
write) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should pass in an env var for source/dest so only one of read and write are valid at this level and show an error if the wrong one is called. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed. let's do this in a separate PR. |
||
eval "$AIRBYTE_WRITE_CMD" --config "$CONFIG_FILE" --catalog "$CATALOG_FILE" | ||
;; | ||
*) | ||
error "Unknown command: $CMD" | ||
;; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* | ||
!Dockerfile | ||
!build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM airbyte/base-java:dev | ||
|
||
WORKDIR /airbyte | ||
ENV APPLICATION csv-destination | ||
|
||
COPY build/distributions/${APPLICATION}*.tar ${APPLICATION}.tar | ||
|
||
RUN tar xf ${APPLICATION}.tar --strip-components=1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage | ||
plugins { | ||
id 'com.bmuschko.docker-remote-api' | ||
id 'application' | ||
} | ||
dependencies { | ||
implementation project(':airbyte-config:models') | ||
implementation project(':airbyte-singer') | ||
implementation project(':airbyte-integrations:base-java') | ||
|
||
implementation 'org.apache.commons:commons-csv:1.4' | ||
} | ||
|
||
application { | ||
mainClass = 'io.airbyte.integrations.destination.csv.CsvDestination' | ||
} | ||
|
||
|
||
def image = 'airbyte/airbyte-csv-destination:dev' | ||
|
||
task imageName { | ||
doLast { | ||
println "IMAGE $image" | ||
} | ||
} | ||
|
||
task buildImage(type: DockerBuildImage) { | ||
inputDir = projectDir | ||
images.add(image) | ||
dependsOn ':airbyte-integrations:base-java:buildImage' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the integration runner be responsible for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discussed offline. agreed this was right. also agreed to add a comment explaining what's happening. which i did.