You've already forked OpenIntegrations
mirror of
https://github.com/Bayselonarrend/OpenIntegrations.git
synced 2026-05-18 09:51:28 +02:00
92 lines
2.9 KiB
Plaintext
Vendored
92 lines
2.9 KiB
Plaintext
Vendored
// Connection settings
|
|
|
|
URL = "http://localhost:8123";
|
|
Login = "bayselonarrend";
|
|
Password = "12we...";
|
|
|
|
Authorization = New Structure(Login, Password);
|
|
|
|
Connection = OPI_ClickHouse.GetHTTPConnectionSettings(URL, Authorization);
|
|
|
|
// Request (table creation)
|
|
|
|
QueryText = "CREATE TABLE IF NOT EXISTS events (
|
|
| 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);
|
|
|
|
// Request (data insertion)
|
|
|
|
QueryText = "INSERT INTO events FORMAT JSON";
|
|
|
|
DataFormat = "JSON";
|
|
DataArray = New Array;
|
|
|
|
CurrentDate = Date("20260101100000");
|
|
|
|
Record1 = New Structure;
|
|
Record1.Insert("id" , 1);
|
|
Record1.Insert("timestamp" , CurrentDate);
|
|
Record1.Insert("user_id" , 100);
|
|
Record1.Insert("event_type", "click");
|
|
Record1.Insert("payload" , "{}");
|
|
|
|
Record2 = New Structure;
|
|
Record2.Insert("id" , 2);
|
|
Record2.Insert("timestamp" , CurrentDate);
|
|
Record2.Insert("user_id" , 200);
|
|
Record2.Insert("event_type", "hover");
|
|
Record2.Insert("payload" , "{}");
|
|
|
|
DataArray.Add(Record1);
|
|
DataArray.Add(Record2);
|
|
|
|
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);
|
|
Database = "default";
|
|
RequestID = String(New UUID());
|
|
|
|
Request = OPI_ClickHouse.GetRequestSettings(QueryText, Database, RequestID, Data, DataFormat);
|
|
Result = OPI_ClickHouse.ExecuteRequest(Connection, Request);
|
|
|
|
// Request with external table
|
|
|
|
TableName = "ext_users";
|
|
ColoumnsStruct = New Structure;
|
|
ColoumnsStruct.Insert("id" , "UInt64");
|
|
ColoumnsStruct.Insert("name", "String");
|
|
|
|
Tab = Chars.Tab;
|
|
TableData = "1" + Tab + "John
|
|
|2" + Tab + "Jane
|
|
|3" + Tab + "Bob";
|
|
|
|
ExternalTable = OPI_ClickHouse.GetExternalTableStructure(TableName, ColoumnsStruct, TableData, "TSV");
|
|
|
|
ExternalTablesArray = New Array;
|
|
ExternalTablesArray.Add(ExternalTable);
|
|
|
|
QueryText = "SELECT * FROM ext_users WHERE id > 1";
|
|
|
|
Request = OPI_ClickHouse.GetRequestSettings(QueryText, , , , "JSON", ExternalTablesArray);
|
|
Result = OPI_ClickHouse.ExecuteRequest(Connection, Request);
|
|
|
|
// Selection
|
|
|
|
SelectionText = "SELECT * FROM events";
|
|
|
|
Request = OPI_ClickHouse.GetRequestSettings(SelectionText, , , , "JSON");
|
|
Result = OPI_ClickHouse.ExecuteRequest(Connection, Request); |