You've already forked OpenIntegrations
mirror of
https://github.com/Bayselonarrend/OpenIntegrations.git
synced 2026-06-20 09:19:27 +02:00
83 lines
2.6 KiB
Plaintext
Vendored
83 lines
2.6 KiB
Plaintext
Vendored
URL = "";
|
|
|
|
Login = "";
|
|
Password = "...";
|
|
|
|
Authorization = New Structure(Login, Password);
|
|
|
|
// Connection creation
|
|
|
|
ConnectionSettings = OPI_ClickHouse.GetGRPCConnectionSettings(URL, Authorization);
|
|
Connection = OPI_ClickHouse.CreateGRPCConnection(ConnectionSettings);
|
|
|
|
// Request via open connection (table creation)
|
|
|
|
QueryText = "CREATE TABLE IF NOT EXISTS events_grpc (
|
|
| id UInt64,
|
|
| timestamp DateTime,
|
|
| user_id UInt32,
|
|
| event_type String,
|
|
| payload String
|
|
|) ENGINE = MergeTree()
|
|
|ORDER BY (timestamp, id)";
|
|
|
|
Request = OPI_ClickHouse.GetRequestSettings(QueryText);
|
|
Result = OPI_ClickHouse.ExecuteRequest(Connection, Request);
|
|
|
|
// Data insertion
|
|
|
|
QueryText = "INSERT INTO events_grpc FORMAT JSON";
|
|
|
|
DataFormat = "JSON";
|
|
DataArray = New Array;
|
|
|
|
CurrentDate = OPI_Tools.GetCurrentDate();
|
|
|
|
Record1 = New Structure;
|
|
Record1.Insert("id" , 1);
|
|
Record1.Insert("timestamp" , CurrentDate);
|
|
Record1.Insert("user_id" , 100);
|
|
Record1.Insert("event_type", "click");
|
|
Record1.Insert("payload" , "{}");
|
|
|
|
DataArray.Add(Record1);
|
|
|
|
Meta = New Array;
|
|
Meta.Add(New Structure("name,type", "id" , "UInt64"));
|
|
Meta.Add(New Structure("name,type", "timestamp" , "DateTime"));
|
|
Meta.Add(New Structure("name,type", "user_id" , "UInt32"));
|
|
Meta.Add(New Structure("name,type", "event_type", "String"));
|
|
Meta.Add(New Structure("name,type", "payload" , "String"));
|
|
|
|
Data = New Structure("meta,data", Meta, DataArray);
|
|
RequestID = String(New UUID());
|
|
|
|
Request = OPI_ClickHouse.GetRequestSettings(QueryText, "default", RequestID, Data, DataFormat);
|
|
Result = OPI_ClickHouse.ExecuteRequest(Connection, Request);
|
|
|
|
// Selection
|
|
|
|
SelectionText = "SELECT * FROM events_grpc";
|
|
|
|
Request = OPI_ClickHouse.GetRequestSettings(SelectionText, , , , "JSON");
|
|
Result = OPI_ClickHouse.ExecuteRequest(Connection, Request);
|
|
|
|
// Request with external table via gRPC
|
|
|
|
ColoumnsStruct = New Structure;
|
|
ColoumnsStruct.Insert("id" , "UInt64");
|
|
ColoumnsStruct.Insert("name", "String");
|
|
|
|
Tab = Chars.Tab;
|
|
TableData = "1" + Tab + "John
|
|
|2" + Tab + "Jane";
|
|
|
|
ExternalTable = OPI_ClickHouse.GetExternalTableStructure("ext_grpc", ColoumnsStruct, TableData, "TSV");
|
|
|
|
ExternalTablesArray = New Array;
|
|
ExternalTablesArray.Add(ExternalTable);
|
|
|
|
QueryText = "SELECT * FROM ext_grpc";
|
|
|
|
Request = OPI_ClickHouse.GetRequestSettings(QueryText, , , , "JSON", ExternalTablesArray);
|
|
Result = OPI_ClickHouse.ExecuteRequest(Connection, Request); |