MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / createSource

Method createSource

test/chbench/chbench/src/materialized.cc:40–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40bool
41mz::createSource(pqxx::connection &c, const std::string& kafkaUrl, const std::string& registry, const std::string& source, const std::string& consistencySource, bool materialized) {
42 pqxx::nontransaction w(c);
43 auto topic = source;
44 std::replace(topic.begin(), topic.end(), '_', '.'); // Kafka topics are delimited by periods
45 try {
46 w.exec0("DROP SOURCE " + source + " CASCADE");
47 } catch (const pqxx::sql_error &e) {
48 fprintf(stderr, "Deleting source %s: %s\n", source.c_str(), e.what());
49 }
50 try {
51 std::string mat = materialized? "MATERIALIZED" : "";
52 std::string consistency = consistencySource.empty()? " " : " with (consistency= '" + consistencySource + "') ";
53 std::string csr_conn_creation = "CREATE CONNECTION IF NOT EXISTS csr_conn TO CONFLUENT SCHEMA REGISTRY (URL '" + registry + "')";
54 w.exec0(csr_conn_creation);
55 std::string kafka_conn_creation = "CREATE CONNECTION IF NOT EXISTS kafka_conn FROM KAFKA BROKER '" + kafkaUrl + "', SECURITY PROTOCOL PLAINTEXT";
56 w.exec0(kafka_conn_creation);
57 std::string source_creation = "CREATE " + mat + " SOURCE IF NOT EXISTS " + source + " FROM KAFKA CONNECTION kafka_conn (TOPIC '" + topic + "') " + consistency + " FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn ENVELOPE DEBEZIUM";
58 w.exec0(source_creation);
59 } catch (const pqxx::sql_error &e) {
60 fprintf(stderr, "Possibly temporary error creating source %s: %s\n", source.c_str(), e.what());
61 return false;
62 }
63 return true;
64}
65
66void mz::createMaterializedView(pqxx::connection& c, const std::string &name, const std::string &query) {
67 pqxx::nontransaction w(c);

Callers

nothing calls this directly

Calls 4

replaceFunction · 0.50
beginMethod · 0.45
whatMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected