private void GetDBObjectNames(string name, List <string> list) { DataTable schema = null; string databaseName = ""; DbConnection connection = GetConnection(); try { OpenConnection(connection); ClickHouseConnectionStringBuilder builder = new ClickHouseConnectionStringBuilder(); builder.ConnectionString = ConnectionString; schema = connection.GetSchema(name); databaseName = builder.Database; } finally { DisposeConnection(connection); } foreach (DataRow row in schema.Rows) { if ((!list.Contains(row[1].ToString()) && (String.Compare(row[0].ToString(), databaseName) == 0))) { list.Add(row[1].ToString()); } } connection.Dispose(); }
private ClickHouseConnection GetConnection(string cstr = "Compress=False;BufferSize=32768;SocketTimeout=10000;CheckCompressedHash=False;Compressor=lz4;Host=file-server;Port=9000;Database=default;User=test;Password=123") { var settings = new ClickHouseConnectionStringBuilder(cstr); var cnn = new ClickHouseConnection(settings); cnn.Open(); return(cnn); }
public void SetConnectionString() { var builder = new ClickHouseConnectionStringBuilder( "host=ClickHouse.example.com;port=65500;DataBase=\"don't; connect\"\" to me :)\";user=root; password=123456;\r\n bufferSize=1337; ReadWriteTimeout=42; clientname=ClickHouse.NetCore Tests;clientversion=3.2.1"); Assert.Equal(9, builder.Count); builder.ConnectionString = "host=localhost; port=31337"; Assert.Equal(2, builder.Count); }
public override DatabaseModel Create(DbConnection connection, DatabaseModelFactoryOptions options) { var sb = new ClickHouseConnectionStringBuilder(connection.ConnectionString); var result = new DatabaseModel { DatabaseName = sb.Database }; var tables = LoadTables(connection, result); tables.ForEach(e => result.Tables.Add(e)); return(result); }
protected override void SetConnectionString(string value) { FConnectionString = value; ClickHouseConnectionStringBuilder builder = new ClickHouseConnectionStringBuilder(FConnectionString); tbServer.Text = builder.Host; tbUserName.Text = builder.Username; tbPassword.Text = builder.Password; tbDatabase.Text = builder.Database; tbPort.Text = builder.Port.ToString(); }
protected override string GetConnectionStringWithLoginInfo(string userName, string password) { ClickHouseConnectionStringBuilder builder = new ClickHouseConnectionStringBuilder(); builder.ConnectionString = ConnectionString; builder.Username = userName; builder.Password = password; return(builder.ToString()); }
public void ShouldUnwrapConnectionOpenExceptions() { var sb = new ClickHouseConnectionStringBuilder { Host = "none.example.com" }; using var conn = new ClickHouseConnection(sb); var exception = Assert.Throws <SocketException>(() => conn.Open()); Assert.Equal(SocketError.HostNotFound, exception.SocketErrorCode); }
public void ChangePropertyValue() { const string connectionString = "Compress=True;CheckCompressedHash=False;Compressor=lz4;Host=clickhouse;Port=9000;User=default;Password=;SocketTimeout=600000;Database=Test;"; var settings = new ClickHouseConnectionStringBuilder(connectionString) { Database = "New" }; Assert.AreEqual( "Async=\"False\";BufferSize=\"4096\";ApacheBufferSize=\"0\";SocketTimeout=\"600000\";ConnectionTimeout=\"1000\";DataTransferTimeout=\"1000\";KeepAliveTimeout=\"1000\";TimeToLiveMillis=\"0\";DefaultMaxPerRoute=\"0\";MaxTotal=\"0\";Host=\"clickhouse\";Port=\"9000\";MaxCompressBufferSize=\"0\";MaxParallelReplicas=\"0\";Priority=\"0\";Database=\"New\";Compress=\"True\";Compressor=\"lz4\";CheckCompressedHash=\"False\";Decompress=\"False\";Extremes=\"False\";MaxThreads=\"0\";MaxExecutionTime=\"0\";MaxBlockSize=\"0\";MaxRowsToGroupBy=\"0\";User=\"default\";Password=\"\";DistributedAggregationMemoryEfficient=\"False\";MaxBytesBeforeExternalGroupBy=\"0\";MaxBytesBeforeExternalSort=\"0\";", settings.ToString()); }
protected override string GetConnectionString() { ClickHouseConnectionStringBuilder builder = new ClickHouseConnectionStringBuilder(FConnectionString); builder.Username = tbUserName.Text; builder.Host = tbServer.Text; builder.Port = ushort.Parse(tbPort.Text); builder.Password = tbPassword.Text; builder.Database = tbDatabase.Text; return(builder.ToString()); }
public void Default() { var builder = new ClickHouseConnectionStringBuilder(); Assert.Equal(string.Empty, builder.ConnectionString); Assert.Empty(builder); // The host is required Assert.Throws <ArgumentException>(() => builder.BuildSettings()); builder.Host = "localhost"; Assert.Equal("Host=localhost", builder.ConnectionString); var settings = builder.BuildSettings(); var checkedPropertiesCount = 0; Assert.Equal("localhost", settings.Host); ++checkedPropertiesCount; Assert.Equal(ClickHouseConnectionStringBuilder.DefaultPort, settings.Port); ++checkedPropertiesCount; Assert.Equal(ClickHouseConnectionStringBuilder.DefaultDatabase, settings.Database); ++checkedPropertiesCount; Assert.Equal(ClickHouseConnectionStringBuilder.DefaultUser, settings.User); ++checkedPropertiesCount; Assert.Null(settings.Password); ++checkedPropertiesCount; Assert.Equal(ClickHouseConnectionStringBuilder.DefaultBufferSize, settings.BufferSize); ++checkedPropertiesCount; Assert.Equal(ClickHouseConnectionStringBuilder.DefaultReadWriteTimeout, settings.ReadWriteTimeout); ++checkedPropertiesCount; Assert.Equal(ClickHouseConnectionStringBuilder.DefaultClientName, settings.ClientName); ++checkedPropertiesCount; Assert.Equal(ClickHouseConnectionStringBuilder.DefaultClientVersion, settings.ClientVersion); ++checkedPropertiesCount; Assert.Equal(ClickHouseConnectionStringBuilder.DefaultCompress, settings.Compress); ++checkedPropertiesCount; Assert.Equal(ClickHouseConnectionStringBuilder.DefaultCommandTimeout, settings.CommandTimeout); ++checkedPropertiesCount; Assert.Equal(checkedPropertiesCount, settings.GetType().GetProperties().Length); }
protected override string GetConnectionString() { ClickHouseConnectionStringBuilder builder = new ClickHouseConnectionStringBuilder(); builder.ConnectionString = FConnectionString; builder.Host = tbServer.Text; builder.SessionId = tbUserName.Text; builder.Password = tbPassword.Text; builder.Database = tbDatabase.Text; return(builder.ToString()); }
private void btnAdvanced_Click(object sender, EventArgs e) { using (AdvancedConnectionPropertiesForm form = new AdvancedConnectionPropertiesForm()) { ClickHouseConnectionStringBuilder builder = new ClickHouseConnectionStringBuilder(); builder.ConnectionString = ConnectionString; form.AdvancedProperties = builder; if (form.ShowDialog() == DialogResult.OK) { ConnectionString = form.AdvancedProperties.ToString(); } } }
public override string GetConnectionId() { ClickHouseConnectionStringBuilder builder = new ClickHouseConnectionStringBuilder(ConnectionString); string info = ""; try { info = builder.Database; } catch { } return("ClickHouse: " + info); }
public void Clone() { var builder = new ClickHouseConnectionStringBuilder( $"host=ClickHouse.example.com;port=65500;DataBase=\"don't; connect\";user=root; password=123456;\r\n bufferSize=1337; ReadWriteTimeout=42; clientname=ClickHouse.NetCore Tests;clientversion=3.2.1;COMPRESS={!ClickHouseConnectionStringBuilder.DefaultCompress};CommandTimeout=123"); var settings = builder.BuildSettings(); var builderCopy = new ClickHouseConnectionStringBuilder(settings); settings = builderCopy.BuildSettings(); var checkedPropertiesCount = 0; Assert.Equal("ClickHouse.example.com", settings.Host); ++checkedPropertiesCount; Assert.Equal(65500, settings.Port); ++checkedPropertiesCount; Assert.Equal("don't; connect", settings.Database); ++checkedPropertiesCount; Assert.Equal("root", settings.User); ++checkedPropertiesCount; Assert.Equal("123456", settings.Password); ++checkedPropertiesCount; Assert.Equal(1337, settings.BufferSize); ++checkedPropertiesCount; Assert.Equal(42, settings.ReadWriteTimeout); ++checkedPropertiesCount; Assert.Equal("ClickHouse.NetCore Tests", settings.ClientName); ++checkedPropertiesCount; Assert.Equal(new ClickHouseVersion(3, 2, 1), settings.ClientVersion); ++checkedPropertiesCount; Assert.Equal(!ClickHouseConnectionStringBuilder.DefaultCompress, settings.Compress); ++checkedPropertiesCount; Assert.Equal(123, settings.CommandTimeout); ++checkedPropertiesCount; Assert.Equal(checkedPropertiesCount, settings.GetType().GetProperties().Length); }
public async Task CancelOnCommandTimeout() { var csb = new ClickHouseConnectionStringBuilder(GetDefaultConnectionSettings()) { CommandTimeout = 2 }; await using (var cn = new ClickHouseConnection(csb)) { await cn.OpenAsync(); await using var cmd = cn.CreateCommand("SELECT sleep(3)"); Assert.Throws <OperationCanceledException>(() => cmd.ExecuteNonQuery()); } }
private ClickHouseConnectionStringBuilder ReadConfigFile() { string configPath = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..\\..\\..\\")); configPath += "clickHouse.dbconfig"; Assert.True(File.Exists(configPath), "Need database connection config: " + configPath + " \t" + ConfigExample); string configText = File.ReadAllText(configPath); ClickHouseConnectionStringBuilder builder = new ClickHouseConnectionStringBuilder(configText); Assert.True(builder.Host != null, "Example \t" + ConfigExample); return(builder); }
public IClickHouseRelationalConnection CreateMasterConnection() { var csb = new ClickHouseConnectionStringBuilder(ConnectionString) { Database = "" }; var relationalOptions = RelationalOptionsExtension.Extract(Dependencies.ContextOptions); var connectionString = csb.ToString(); relationalOptions = relationalOptions.WithConnectionString(connectionString); var optionsBuilder = new DbContextOptionsBuilder(); ((IDbContextOptionsBuilderInfrastructure)optionsBuilder).AddOrUpdateExtension(relationalOptions); return(new ClickHouseRelationalConnection(Dependencies.With(optionsBuilder.Options))); }
public void ShouldConvertIntoConnectionStringAndBack() { const string connectionString = "Compress=True;CheckCompressedHash=False;Compressor=lz4;Host=clickhouse;Port=9000;User=default;Password=;SocketTimeout=600000;Database=Test;"; var expectedSettings = new ClickHouseConnectionStringBuilder(connectionString); var actualSettings = new ClickHouseConnectionStringBuilder(expectedSettings.ToString()); Assert.AreEqual(expectedSettings.BufferSize, actualSettings.BufferSize); Assert.AreEqual(expectedSettings.SocketTimeout, actualSettings.SocketTimeout); Assert.AreEqual(expectedSettings.Host, actualSettings.Host); Assert.AreEqual(expectedSettings.Port, actualSettings.Port); Assert.AreEqual(expectedSettings.Database, actualSettings.Database); Assert.AreEqual(expectedSettings.Compress, actualSettings.Compress); Assert.AreEqual(expectedSettings.Compressor, actualSettings.Compressor); Assert.AreEqual(expectedSettings.CheckCompressedHash, actualSettings.CheckCompressedHash); Assert.AreEqual(expectedSettings.User, actualSettings.User); Assert.AreEqual(expectedSettings.Password, actualSettings.Password); }
public void Handshake(ClickHouseConnectionStringBuilder connectionSettings) { _connectionSettings = connectionSettings; _compressor = connectionSettings.Compress ? Compressor.Create(connectionSettings):null; WriteUInt((int)ClientMessageType.Hello); WriteString(ClientInfo.ClientName); WriteUInt(ClientInfo.ClientVersionMajor); WriteUInt(ClientInfo.ClientVersionMinor); WriteUInt(ClientInfo.ClientRevision); WriteString(connectionSettings.Database); WriteString(connectionSettings.User); WriteString(connectionSettings.Password); _ioStream.Flush(); var serverHello = ReadUInt(); if (serverHello == (int)ServerMessageType.Hello) { var serverName = ReadString(); var serverMajor = ReadUInt(); var serverMinor = ReadUInt(); var serverBuild = ReadUInt(); string serverTz = null; if (serverBuild >= ProtocolCaps.DbmsMinRevisionWithServerTimezone) { serverTz = ReadString(); } ServerInfo = new ServerInfo { Build = serverBuild, Major = serverMajor, Minor = serverMinor, Name = serverName, Timezone = serverTz }; } else if (serverHello == (int)ServerMessageType.Exception) { ReadAndThrowException(); } else { throw new FormatException($"Bad message type {serverHello:X} received from server."); } }
public void FromString() { var builder = new ClickHouseConnectionStringBuilder( "host=ClickHouse.example.com;port=65500;compress = off;DataBase=\"don't; connect\"\" to me :)\";user=root; password=123456;\r\n bufferSize=1337; ReadWriteTimeout=42; clientname=ClickHouse.NetCore Tests;clientversion=3.2.1"); var settings = builder.BuildSettings(); Assert.Equal("ClickHouse.example.com", settings.Host); Assert.Equal(65500, settings.Port); Assert.Equal("don't; connect\" to me :)", settings.Database); Assert.Equal("root", settings.User); Assert.Equal("123456", settings.Password); Assert.Equal(1337, settings.BufferSize); Assert.Equal(42, settings.ReadWriteTimeout); Assert.Equal("ClickHouse.NetCore Tests", settings.ClientName); Assert.Equal(new ClickHouseVersion(3, 2, 1), settings.ClientVersion); Assert.Equal(false, settings.Compress); }
public void Remove() { var builder = new ClickHouseConnectionStringBuilder { Host = "some_instance.example.com", Port = ClickHouseConnectionStringBuilder.DefaultPort * 2, ClientName = "Test!" }; Assert.Equal(3, builder.Count); Assert.True(builder.Remove("pORT")); Assert.Equal(2, builder.Count); Assert.Equal(ClickHouseConnectionStringBuilder.DefaultPort, builder.Port); Assert.False(builder.Remove("Port")); Assert.True(builder.Remove("ClientName")); Assert.Equal(1, builder.Count); Assert.Equal(ClickHouseConnectionStringBuilder.DefaultClientName, builder.ClientName); }
public static Compressor Create(ClickHouseConnectionStringBuilder settings) { switch ((settings.Compressor ?? "").ToLower()) { case "zstd": throw new NotImplementedException(); //Actually server doesn't interpret this well. Maybe ZSTD implementation is slightly different? #if false return(new ZstdCompressor()); #endif case "lz4hc": throw new NotImplementedException(); //Actually server doesn't interpret this well. Maybe LZ4HC implementation is slightly different? return(new Lz4Compressor(true, settings)); case "lz4": default: return(new Lz4Compressor(false, settings)); } }
public async Task CancelOnSocketTimeout() { // Attempt to emulate a network error. It doesn't work sometimes because ClickHouse server sends Progress messages var csb = new ClickHouseConnectionStringBuilder(GetDefaultConnectionSettings()) { ReadWriteTimeout = 25 }; await using (var cn = new ClickHouseConnection(csb)) { await cn.OpenAsync(); await using var cmd = cn.CreateCommand("SELECT sleep(3)"); var ioEx = Assert.Throws <IOException>(() => cmd.ExecuteNonQuery()); var socketEx = Assert.IsType <SocketException>(ioEx.InnerException); Assert.Equal(SocketError.TimedOut, socketEx.SocketErrorCode); } }
private ClickHouseConnectionStringBuilder ReadConfigFile() { //each benchmark makes new project path, it config file needs to be with Runner path string configPath = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "../../../../clickHouse.dbconfig")); if (!File.Exists(configPath)) { throw new ClickHouseException(ClickHouseErrorCodes.InvalidConnectionState, $"Need database connection config: {configPath} \t {ConfigExample}"); } string configText = File.ReadAllText(configPath); ClickHouseConnectionStringBuilder builder = new ClickHouseConnectionStringBuilder(configText); if (builder.Host == null) { throw new ClickHouseException(ClickHouseErrorCodes.InvalidConnectionState, $"Example \t {ConfigExample}"); } return(builder); }
private static string GetConnectionString(string[] args) { var builder = new ClickHouseConnectionStringBuilder(); int i = 0; while (i < args.Length) { switch (args[i]) { case "--host": builder.Host = args[++i]; break; case "--port": builder.Port = UInt16.Parse(args[++i]); break; case "--user": builder.Username = args[++i]; break; case "--password": builder.Password = args[++i]; break; case "--database": builder.Database = args[++i]; break; default: i++; break; } } return(builder.ToString()); }
public async Task CanConnectWithUserAndPassword() { var settings = GetDefaultConnectionSettings(); settings = new ClickHouseConnectionStringBuilder(settings) { Database = null }.BuildSettings(); Assert.False(string.IsNullOrEmpty(settings.User)); Assert.Null(settings.Database); await using var conn = new ClickHouseConnection(settings); await conn.OpenAsync(); Assert.Null(conn.Database); var currentUser = await conn.CreateCommand("select currentUser()").ExecuteScalarAsync <string>(); var currentDb = await conn.CreateCommand("select currentDatabase()").ExecuteScalarAsync <string>(); Assert.Equal(settings.User, currentUser); Assert.NotNull(currentDb); }
public Lz4Compressor(bool useHc, ClickHouseConnectionStringBuilder settings) : base(settings) { _useHc = useHc; }
public void Clone() { var builder = new ClickHouseConnectionStringBuilder( "host=ClickHouse.example.com;" + "port=65500;" + "DataBase=\"don't; connect\";" + "user=root; " + "password=123456;\r\n " + "bufferSize=1337; " + "ReadWriteTimeout=42; " + "clientname=ClickHouse.NetCore Tests;" + "clientversion=3.2.1;" + $"COMPRESS={!ClickHouseConnectionStringBuilder.DefaultCompress};" + "CommandTimeout=123;" + "TLSMode=rEqUIrE;" + "RootCertificate=/usr/local/share/ca-certificates/Yandex/YandexInternalRootCA.pem;" + "ServerCertificateHash=1234-5678 9abc-def0;" + "ParametersMode=Interpolate"); var settings = builder.BuildSettings(); var builderCopy = new ClickHouseConnectionStringBuilder(settings); settings = builderCopy.BuildSettings(); var checkedPropertiesCount = 0; Assert.Equal("ClickHouse.example.com", settings.Host); ++checkedPropertiesCount; Assert.Equal(65500, settings.Port); ++checkedPropertiesCount; Assert.Equal("don't; connect", settings.Database); ++checkedPropertiesCount; Assert.Equal("root", settings.User); ++checkedPropertiesCount; Assert.Equal("123456", settings.Password); ++checkedPropertiesCount; Assert.Equal(1337, settings.BufferSize); ++checkedPropertiesCount; Assert.Equal(42, settings.ReadWriteTimeout); ++checkedPropertiesCount; Assert.Equal("ClickHouse.NetCore Tests", settings.ClientName); ++checkedPropertiesCount; Assert.Equal(new ClickHouseVersion(3, 2, 1), settings.ClientVersion); ++checkedPropertiesCount; Assert.Equal(!ClickHouseConnectionStringBuilder.DefaultCompress, settings.Compress); ++checkedPropertiesCount; Assert.Equal(123, settings.CommandTimeout); ++checkedPropertiesCount; Assert.Equal(ClickHouseTlsMode.Require, settings.TlsMode); ++checkedPropertiesCount; Assert.Equal("/usr/local/share/ca-certificates/Yandex/YandexInternalRootCA.pem", settings.RootCertificate); ++checkedPropertiesCount; Assert.Equal(new byte[] { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 }, settings.ServerCertificateHash.ToArray()); ++checkedPropertiesCount; Assert.Equal(ClickHouseParameterMode.Interpolate, settings.ParametersMode); ++checkedPropertiesCount; Assert.Equal(checkedPropertiesCount, settings.GetType().GetProperties().Length); }
protected HashingCompressor(ClickHouseConnectionStringBuilder settings) { _settings = settings; }