Skip to content

Instantly share code, notes, and snippets.

View confluentgist's full-sized avatar

Confluent, Inc. confluentgist

View GitHub Profile
---
version: '2'
services:
zookeeper:
image: confluentinc/cp-zookeeper:5.3.1
hostname: zookeeper
container_name: zookeeper
ports:
- "2181:2181"
import numpy as np
import tensorflow as tf
import tensorflow_io.kafka as kafka_io
# 1. Consume streaming data with Kafka and TensorFlow I/O
def func_x(x):
# Decode image to (28, 28)
x = tf.io.decode_raw(x, out_type=tf.uint8)
x = tf.reshape(x, [28, 28])
# Convert to float32 for tf.keras
@confluentgist
confluentgist / increased-partitions.sql
Created January 11, 2020 00:14 — forked from miguno/increased-partitions.sql
ksqlDB example: Create a new stream with the desired number of partitions.
CREATE STREAM products ...;
CREATE STREAM products_repartitioned
WITH (PARTITIONS=30) AS
SELECT * FROM products
EMIT CHANGES;
@confluentgist
confluentgist / aggregation.java
Created January 9, 2020 22:16 — forked from miguno/aggregation.java
Kafka Streams Example: Continuously aggregating a stream into a table
// Continuously aggregating a KStream into a KTable.
KStream<String, String> locationUpdatesStream = ...;
KTable<String, Long> locationsPerUser
= locationUpdatesStream
.groupBy((k, v) -> v.username)
.count();
@confluentgist
confluentgist / aggregation.sql
Created January 9, 2020 22:15 — forked from miguno/aggregation.sql
ksqlDB example: Continuously aggregating a stream into a table with a push query
-- Continuously aggregating a stream into a table with a ksqlDB push query.
CREATE STREAM locationUpdatesStream ...;
CREATE TABLE locationsPerUser AS
SELECT username, COUNT(*)
FROM locationUpdatesStream
GROUP BY username
EMIT CHANGES;
@confluentgist
confluentgist / topic-as-table.java
Created January 9, 2020 07:56 — forked from miguno/topic-as-table.java
Kafka Streams Example: read topic as table
// Create KTable from Kafka topic.
KTable<String, String> table = builder.table("input-topic", Consumed.with(Serdes.String(), Serdes.String()));
@confluentgist
confluentgist / topic-as-table.sql
Created January 9, 2020 07:56 — forked from miguno/topic-as-table.sql
ksqlDB example: read topic as table
-- Create ksqlDB table from Kafka topic.
CREATE TABLE myTable (username VARCHAR, location VARCHAR)
WITH (KAFKA_TOPIC='input-topic', KEY='username', VALUE_FORMAT='...');
@confluentgist
confluentgist / topic-as-stream.java
Created January 9, 2020 07:38 — forked from miguno/topic-as-stream.java
Kafka Streams Example: read a topic as a stream
// Create KStream from Kafka topic.
StreamsBuilder builder = new StreamsBuilder();
KStream<String, String> stream =
builder.stream("input-topic", Consumed.with(Serdes.String(), Serdes.String()));
@confluentgist
confluentgist / topic-as-stream.sql
Created January 9, 2020 07:37 — forked from miguno/topic-as-stream.sql
ksqlDB example: read topic as stream
-- Create ksqlDB stream from Kafka topic.
CREATE STREAM myStream (username VARCHAR, location VARCHAR)
WITH (KAFKA_TOPIC='input-topic', VALUE_FORMAT='...');
@confluentgist
confluentgist / gist:5cc32f336179d2b37dfafcabfc220f7e
Created November 30, 2019 08:23 — forked from jolshan/gist:94a6335312ed7af35d77da3abbc6f13b
Example Task Spec for Sticky Partitioner
“task”: {
“type”: “.TaskRole,
“initialDelayMs”: 20000,
“taskSpecs”: {
"bench0": {
"class": "org.apache.kafka.trogdor.workload.ProduceBenchSpec",
"startMs": 0,
"durationMs": 720000,
"producerNode": "node0",
"bootstrapServers": "%{bootstrapServers}",