Create GRPC connection
Opens a GRPC connection for working with ClickHouse
- Parameters
- Advanced call ?
Function CreateGRPCConnection(Val ConnectionSettings) Export
| Parameter | CLI option | Type | Required | Description |
|---|---|---|---|---|
| ConnectionSettings | - | Structure Of KeyAndValue | ✔ | Connection parameters. See GetGRPCConnectionSettings |
Returns
Arbitrary - Client object or map with error information
This method has no additional advanced call parameters.
Caution
NOCLI: this method is not available in CLI version
1C:Enterprise/OneScript code example
URL = "http://localhost:9101";
Login = "bayselonarrend";
Password = "12we...";
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);
Result
{
"data": {
"cancelled": false,
"exception": {
"code": 0,
"display_text": "",
"name": "",
"stack_trace": ""
},
"extremes": {
"BYTES": ""
},
"logs": [],
"output": {
"meta": [
{
"name": "id",
"type": "UInt64"
},
{
"name": "name",
"type": "String"
}
],
"data": [
{
"id": "1",
"name": "John"
},
{
"id": "2",
"name": "Jane"
}
],
"rows": 2,
"statistics": {
"elapsed": 0.001120989,
"rows_read": 0,
"bytes_read": 0
}
},
"output_columns": [],
"output_format": "JSON",
"progress": {
"read_bytes": 42,
"read_rows": 2,
"total_rows_to_read": 0,
"written_bytes": 0,
"written_rows": 0
},
"query_id": "ac421539-2376-4349-a2f2-c190e742a634",
"stats": {
"allocated_bytes": 8448,
"applied_aggregation": false,
"applied_limit": false,
"blocks": 1,
"rows": 2,
"rows_before_aggregation": 0,
"rows_before_limit": 0
},
"time_zone": "Europe/Moscow",
"totals": {
"BYTES": ""
}
},
"result": true
}