You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/10/12 01:29:32 UTC
[GitHub] [pulsar] david-streamlio opened a new pull request, #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink
david-streamlio opened a new pull request, #16179:
URL: https://github.com/apache/pulsar/pull/16179
### Motivation
The current implementation of the Cassandra Sink connector only supported a single schema type (key, string). This is not useful for production. So I modified the code to be able to support any schema type in Cassandra.
### Modifications
Added classes that interrogate the database to determine the schema type at runtime. I also added a framework that will extract the values from the supported incoming schema types (GenericRecord, and String) using the table metadata.
### Verifying this change
- [ x] Make sure that the change passes the CI checks.
*(Please pick either of the following options)*
This change added tests and can be verified as follows:
*Added integration tests for testing against a Cassandra database*
### Does this pull request potentially affect one of the following parts:
*If `yes` was chosen, please highlight the changes*
- Dependencies (does it add or upgrade a dependency): (yes)
- The public API: (no)
- The schema: (yes)
- The default values of configurations: (no)
- The wire protocol: (no)
- The rest endpoints: (no)
- The admin cli options: ( no)
- Anything that affects deployment: (no)
### Documentation
Check the box below or label this PR directly.
Need to update docs?
- [ x] `doc-required`
(Your PR needs to update docs and you will update later)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codecov-commenter commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink
Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1277892077
# [Codecov](https://codecov.io/gh/apache/pulsar/pull/16179?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> :exclamation: No coverage uploaded for pull request base (`master@bff3400`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#section-missing-base-commit).
> The diff coverage is `n/a`.
[](https://codecov.io/gh/apache/pulsar/pull/16179?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
```diff
@@ Coverage Diff @@
## master #16179 +/- ##
=========================================
Coverage ? 70.88%
Complexity ? 438
=========================================
Files ? 26
Lines ? 2246
Branches ? 245
=========================================
Hits ? 1592
Misses ? 481
Partials ? 173
```
| Flag | Coverage Δ | |
|---|---|---|
| unittests | `70.88% <0.00%> (?)` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] github-actions[bot] commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1221451899
The pr had no activity for 30 days, mark with Stale label.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink [pulsar]
Posted by "david-streamlio (via GitHub)" <gi...@apache.org>.
david-streamlio closed pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink
URL: https://github.com/apache/pulsar/pull/16179
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui closed pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink
Posted by GitBox <gi...@apache.org>.
codelipenghui closed pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink
URL: https://github.com/apache/pulsar/pull/16179
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink [pulsar]
Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on code in PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#discussion_r2774592647
##########
pulsar-io/cassandra/src/main/java/org/apache/pulsar/io/cassandra/CassandraStringSink.java:
##########
@@ -19,23 +19,13 @@
package org.apache.pulsar.io.cassandra;
import org.apache.pulsar.functions.api.Record;
-import org.apache.pulsar.io.core.KeyValue;
-import org.apache.pulsar.io.core.annotations.Connector;
-import org.apache.pulsar.io.core.annotations.IOType;
+import org.apache.pulsar.io.cassandra.util.RecordWrapper;
+import org.apache.pulsar.io.cassandra.util.StringRecordWrapper;
+
+public class CassandraStringSink extends CassandraSink<String> {
-/**
- * Cassandra sink that treats incoming messages on the input topic as Strings
- * and write identical key/value pairs.
- */
-@Connector(
- name = "cassandra",
- type = IOType.SINK,
- help = "The CassandraStringSink is used for moving messages from Pulsar to Cassandra.",
- configClass = CassandraSinkConfig.class)
-public class CassandraStringSink extends CassandraAbstractSink<String, String> {
@Override
- public KeyValue<String, String> extractKeyValue(Record<byte[]> record) {
- String key = record.getKey().orElseGet(() -> new String(record.getValue()));
- return new KeyValue<>(key, new String(record.getValue()));
+ RecordWrapper<String> wrapRecord(Record<String> record) {
+ return new StringRecordWrapper(record.getValue());
}
-}
Review Comment:
The behavior of the existing CassandraStringSink shouldn't be modified since it breaks backwards compatibility.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] david-streamlio commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink
Posted by GitBox <gi...@apache.org>.
david-streamlio commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1278098298
/pulsarbot run-failure-checks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] david-streamlio commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink
Posted by GitBox <gi...@apache.org>.
david-streamlio commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1274947370
/pulsarbot ready-to-test
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] david-streamlio commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink
Posted by GitBox <gi...@apache.org>.
david-streamlio commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1382178440
@tisonkun @eolivelli I would appreciate another review when you have the time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] david-streamlio commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink
Posted by GitBox <gi...@apache.org>.
david-streamlio commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1297368527
@eolivelli , Can you please take a look at this when you get the chance? Thanks again!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] david-streamlio commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink
Posted by GitBox <gi...@apache.org>.
david-streamlio commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1355313812
/pulsarbot run-failure-checks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink [pulsar]
Posted by "david-streamlio (via GitHub)" <gi...@apache.org>.
david-streamlio commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-5320907238
Closing this in favour of two PRs against `apache/pulsar-connectors`, where the connector now lives:
- **apache/pulsar-connectors#136** — authenticated clusters (`userName` / `password`)
- **apache/pulsar-connectors#137** — the `cassandra-generic-record` and `cassandra-json` sinks
**Why it moved rather than being updated here.** PIP-465 removed the IO connectors from this
repository (#25408, merged 2026-03-27), a day after `apache/pulsar-connectors` was initialised with
the Cassandra connector as it then stood. The connector migrated cleanly; this PR, still open on top
of it, did not. Every file here targets `pulsar-io/cassandra/**`, which no longer exists on `master`,
plus a `pom.xml`, and none of those survive the Gradle migration either. Rebasing produces
delete/modify conflicts on all 23 files with nowhere to resolve them to, so the change had to be
ported rather than rebased. Apologies for leaving it sitting this long in the first place.
**Why two PRs.** Re-reading this one, it was doing two independent things under a title that mentions
only one. The Cassandra sink cannot connect to a cluster requiring authentication at all — there are
no credential fields and `CassandraAbstractSink` builds its `Cluster` with contact points only — and
that fix has nothing to do with schema mapping. It is four files and reviewable on its own, so it
should not wait behind a design discussion about field-to-column mapping. That is #136. The
schema-mapping work is #137, stacked on it.
**@lhotari — your change request is addressed, and I took it further than asked.** You wrote:
> The behavior of the existing CassandraStringSink shouldn't be modified since it breaks backwards
> compatibility. Breaking existing behavior will be surprising for existing users. That's why it's
> better to add the new behavior only when specific configuration is used.
You were right, and re-reading the diff the damage was wider than the line you flagged. This PR also
dropped the `@Connector` annotation that registers the `cassandra` sink, changed the input from
`Record<byte[]>` to `Record<String>`, and removed the key-falls-back-to-value behaviour — on top of
reinterpreting the message as JSON. Four breaking changes to a shipped connector, for a feature that
did not need to touch it.
Rather than gate the new behaviour behind a configuration flag, #137 makes it a separate connector.
`CassandraStringSink`, `CassandraAbstractSink` and the `cassandra` entry in `pulsar-io.yaml` are
unchanged, and the new behaviour arrives as `cassandra-generic-record` (schema-carrying records) and
`cassandra-json` (raw JSON strings). An operator selects one by name or does not get it, so there is
no configuration path by which the existing sink can start behaving differently. Its diff is
additive — 934 insertions, zero deletions — and the pre-existing `CassandraStringSinkTest` passes
unmodified, which is the check that backs the compatibility claim.
One thing in #136 does touch the existing path and is worth your eye: config loading moves from
`CassandraSinkConfig.load` to `IOConfigUtils.loadWithSecrets`, so a `sensitive` password can come
from a Pulsar secret instead of plaintext config. It is the helper kinesis, redis, canal and
azure-data-explorer already use, and `CassandraStringSinkTest` passing unchanged is the evidence that
it is a drop-in for configs with no secrets — but it is a real change to that path and I would rather
point at it than have it found.
Your other note — that there were no integration tests and they could come later — is partly
answered. Between the two PRs there are Testcontainers tests for authentication, the connection, the
generated `INSERT` against real table metadata, and table-definition resolution. There is still no
end-to-end test driving either new sink through a running sink instance; that is called out in #137
as worth doing rather than left implied.
Thanks for the review. It was the right call and the design is better for it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] david-streamlio commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink
Posted by GitBox <gi...@apache.org>.
david-streamlio commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1289238251
@eolivelli I have made the requested changes, can you PTAL when you get a chance? Thank!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] david-streamlio commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink
Posted by GitBox <gi...@apache.org>.
david-streamlio commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1191734946
@tspannhw can you review and upvote?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] david-streamlio commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink
Posted by GitBox <gi...@apache.org>.
david-streamlio commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1312147210
@eolivelli Can I please get some feedback on these changes I made in response to your initial feedback? Thanks again for the review, I really appreciated it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] david-streamlio commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink
Posted by GitBox <gi...@apache.org>.
david-streamlio commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1273812855
/pulsarbot run-failure-checks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] eolivelli commented on a diff in pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink
Posted by GitBox <gi...@apache.org>.
eolivelli commented on code in PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#discussion_r993261206
##########
pulsar-io/cassandra/src/main/java/org/apache/pulsar/io/cassandra/util/CassandraConnector.java:
##########
@@ -0,0 +1,135 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.pulsar.io.cassandra.util;
+
+import com.datastax.driver.core.*;
+import com.datastax.driver.core.Session;
+import org.apache.pulsar.io.cassandra.CassandraSinkConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CassandraConnector {
+
+ private Cluster cluster;
+ private Session session;
Review Comment:
we have to handle concurrent access properly to these fields
##########
pulsar-io/cassandra/pom.xml:
##########
@@ -51,6 +51,39 @@
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
+ <version>${cassandra.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>io.dropwizard.metrics</groupId>
+ <artifactId>metrics-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ <version>1.9.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.pulsar</groupId>
+ <artifactId>pulsar-functions-local-runner-original</artifactId>
+ <version>2.11.0-SNAPSHOT</version>
Review Comment:
please use project.version
##########
pulsar-io/cassandra/src/main/java/org/apache/pulsar/io/cassandra/util/TableMetadataProvider.java:
##########
@@ -0,0 +1,102 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.pulsar.io.cassandra.util;
+
+import com.datastax.driver.core.*;
Review Comment:
please do not use star imports
##########
pulsar-io/cassandra/src/main/java/org/apache/pulsar/io/cassandra/util/StringRecordWrapper.java:
##########
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.pulsar.io.cassandra.util;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class StringRecordWrapper extends RecordWrapper<String> {
+
+ private Map<String, Object> valuesMap;
+
+ public StringRecordWrapper(String jsonString) {
+ super(jsonString);
+ valuesMap = new Gson().fromJson(jsonString,
Review Comment:
I think that we can cache this "new Gson()" instance in a static field
##########
pulsar-io/cassandra/src/test/java/org/apache/pulsar/io/cassandra/producers/InputTopicProducerThread.java:
##########
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.pulsar.io.cassandra.producers;
+
+import org.apache.pulsar.client.api.Producer;
+import org.apache.pulsar.client.api.PulsarClient;
+import org.apache.pulsar.client.api.PulsarClientException;
+import org.apache.pulsar.client.api.Schema;
+
+import java.util.Random;
+
+public abstract class InputTopicProducerThread<T> implements Runnable {
+
+ private Random rnd = new Random();
+
+ final String inputTopic;
+ final String brokerUrl;
+ PulsarClient client;
+ Producer<T> producer;
+
+ public InputTopicProducerThread(String brokerUrl, String inputTopic) {
+ this.brokerUrl = brokerUrl;
+ this.inputTopic = inputTopic;
+ }
+
+ @Override
+ public void run() {
+ for (int idx = 0; idx < 100; idx++) {
+ try {
+ getProducer().newMessage().key(getKey()).value(getValue()).send();
+ } catch (PulsarClientException e) {
+ e.printStackTrace();
Review Comment:
please use logger
##########
pulsar-io/cassandra/src/test/java/org/apache/pulsar/io/cassandra/CassandraSinkExec.java:
##########
@@ -0,0 +1,98 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.pulsar.io.cassandra;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.pulsar.common.io.SinkConfig;
+import org.apache.pulsar.functions.LocalRunner;
+import org.apache.pulsar.io.cassandra.producers.InputTopicProducerThread;
+import org.apache.pulsar.io.cassandra.producers.InputTopicStringProducer;
+import org.apache.pulsar.io.cassandra.producers.ReadingSchemaRecordProducer;
+import org.yaml.snakeyaml.Yaml;
+
+/**
+ * Useful for testing within IDE.
+ *
+ */
+public class CassandraSinkExec {
+
+ public static final String BROKER_URL = "pulsar://localhost:6650";
+ public static final String INPUT_TOPIC = "persistent://public/default/air-quality-reading-generic";
+ // public static final String INPUT_TOPIC = "persistent://public/default/air-quality-reading-string";
+ public static final String CONFIG_FILE = "cassandra-sink-config.yaml";
+
+ public static void main(String[] args) throws Exception {
+
+ SinkConfig config = getSinkConfig();
+
+ final LocalRunner localRunner =
+ LocalRunner.builder()
+ .brokerServiceUrl(BROKER_URL)
+ .sinkConfig(config)
+ .build();
+
+ localRunner.start(false);
+
+ sendData();
+ TimeUnit.MINUTES.sleep(10);
+
+ localRunner.stop();
+
+ System.exit(0);
+ }
+
+ private static SinkConfig getSinkConfig() throws FileNotFoundException {
+ SinkConfig sinkConfig = SinkConfig.builder()
+ .autoAck(true)
+ .cleanupSubscription(Boolean.TRUE)
+ .configs(getConfigs())
+ .className(CassandraGenericRecordSink.class.getName())
+ .inputs(Collections.singletonList(INPUT_TOPIC))
+ .name("CassandraSink")
+ .build();
+
+ return sinkConfig;
+ }
+
+ private static Map<String, Object> getConfigs() throws FileNotFoundException {
+ Map<String, Object> configs = new HashMap<String, Object>();
+
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ File file = new File(classLoader.getResource(CONFIG_FILE).getFile());
+
+ Yaml yaml = new Yaml();
+ configs = yaml.load(new FileInputStream(file));
+
+ return configs;
+ }
+
+ private static final void sendData() throws InterruptedException {
+ TimeUnit.SECONDS.sleep(10);
Review Comment:
do we need to sleep a fixed amount of time ?
##########
pulsar-io/cassandra/src/test/java/org/apache/pulsar/io/cassandra/CassandraSinkExec.java:
##########
@@ -0,0 +1,98 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.pulsar.io.cassandra;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.pulsar.common.io.SinkConfig;
+import org.apache.pulsar.functions.LocalRunner;
+import org.apache.pulsar.io.cassandra.producers.InputTopicProducerThread;
+import org.apache.pulsar.io.cassandra.producers.InputTopicStringProducer;
+import org.apache.pulsar.io.cassandra.producers.ReadingSchemaRecordProducer;
+import org.yaml.snakeyaml.Yaml;
+
+/**
+ * Useful for testing within IDE.
+ *
+ */
+public class CassandraSinkExec {
+
+ public static final String BROKER_URL = "pulsar://localhost:6650";
+ public static final String INPUT_TOPIC = "persistent://public/default/air-quality-reading-generic";
+ // public static final String INPUT_TOPIC = "persistent://public/default/air-quality-reading-string";
+ public static final String CONFIG_FILE = "cassandra-sink-config.yaml";
+
+ public static void main(String[] args) throws Exception {
+
+ SinkConfig config = getSinkConfig();
+
+ final LocalRunner localRunner =
+ LocalRunner.builder()
+ .brokerServiceUrl(BROKER_URL)
+ .sinkConfig(config)
+ .build();
+
+ localRunner.start(false);
+
+ sendData();
+ TimeUnit.MINUTES.sleep(10);
+
+ localRunner.stop();
+
+ System.exit(0);
+ }
+
+ private static SinkConfig getSinkConfig() throws FileNotFoundException {
+ SinkConfig sinkConfig = SinkConfig.builder()
+ .autoAck(true)
+ .cleanupSubscription(Boolean.TRUE)
+ .configs(getConfigs())
+ .className(CassandraGenericRecordSink.class.getName())
+ .inputs(Collections.singletonList(INPUT_TOPIC))
+ .name("CassandraSink")
+ .build();
+
+ return sinkConfig;
+ }
+
+ private static Map<String, Object> getConfigs() throws FileNotFoundException {
+ Map<String, Object> configs = new HashMap<String, Object>();
+
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ File file = new File(classLoader.getResource(CONFIG_FILE).getFile());
+
+ Yaml yaml = new Yaml();
+ configs = yaml.load(new FileInputStream(file));
Review Comment:
please close the stream
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] david-streamlio commented on a diff in pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink
Posted by GitBox <gi...@apache.org>.
david-streamlio commented on code in PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#discussion_r993962325
##########
pulsar-io/cassandra/src/test/java/org/apache/pulsar/io/cassandra/CassandraSinkExec.java:
##########
@@ -0,0 +1,98 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.pulsar.io.cassandra;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.pulsar.common.io.SinkConfig;
+import org.apache.pulsar.functions.LocalRunner;
+import org.apache.pulsar.io.cassandra.producers.InputTopicProducerThread;
+import org.apache.pulsar.io.cassandra.producers.InputTopicStringProducer;
+import org.apache.pulsar.io.cassandra.producers.ReadingSchemaRecordProducer;
+import org.yaml.snakeyaml.Yaml;
+
+/**
+ * Useful for testing within IDE.
+ *
+ */
+public class CassandraSinkExec {
+
+ public static final String BROKER_URL = "pulsar://localhost:6650";
+ public static final String INPUT_TOPIC = "persistent://public/default/air-quality-reading-generic";
+ // public static final String INPUT_TOPIC = "persistent://public/default/air-quality-reading-string";
+ public static final String CONFIG_FILE = "cassandra-sink-config.yaml";
+
+ public static void main(String[] args) throws Exception {
+
+ SinkConfig config = getSinkConfig();
+
+ final LocalRunner localRunner =
+ LocalRunner.builder()
+ .brokerServiceUrl(BROKER_URL)
+ .sinkConfig(config)
+ .build();
+
+ localRunner.start(false);
+
+ sendData();
+ TimeUnit.MINUTES.sleep(10);
+
+ localRunner.stop();
+
+ System.exit(0);
+ }
+
+ private static SinkConfig getSinkConfig() throws FileNotFoundException {
+ SinkConfig sinkConfig = SinkConfig.builder()
+ .autoAck(true)
+ .cleanupSubscription(Boolean.TRUE)
+ .configs(getConfigs())
+ .className(CassandraGenericRecordSink.class.getName())
+ .inputs(Collections.singletonList(INPUT_TOPIC))
+ .name("CassandraSink")
+ .build();
+
+ return sinkConfig;
+ }
+
+ private static Map<String, Object> getConfigs() throws FileNotFoundException {
+ Map<String, Object> configs = new HashMap<String, Object>();
+
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ File file = new File(classLoader.getResource(CONFIG_FILE).getFile());
+
+ Yaml yaml = new Yaml();
+ configs = yaml.load(new FileInputStream(file));
+
+ return configs;
+ }
+
+ private static final void sendData() throws InterruptedException {
+ TimeUnit.SECONDS.sleep(10);
Review Comment:
The only reason I sleep 10 seconds, is so I can easily visualize the data as it is published to the system. The delay allows me time to execute a query against Cassandra in order to detect the new records.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org