ADO.NET Provider for Apache Kafka

Build 21.0.7940

SELECT INTO Statements

You can use the SELECT INTO statement to export formatted data to a file.

Data Export with an SQL Query

The following query exports data into a file formatted in comma-separated values (CSV):

C#

String connectionString = "User=admin;Password=pass;BootStrapServers=https://localhost:9091;Topic=MyTopic;";

using (ApacheKafkaConnection connection = new ApacheKafkaConnection(connectionString)) {
  ApacheKafkaCommand cmd = new ApacheKafkaCommand("SELECT Id, Column1 INTO [csv://SampleTable_1.txt] FROM [SampleTable_1] WHERE Column2 = 'Bob' ", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "User=admin;Password=pass;BootStrapServers=https://localhost:9091;Topic=MyTopic;" 

Using connection As New ApacheKafkaConnection(connectionString)
  Dim cmd As New ApacheKafkaCommand("SELECT Id, Column1 INTO [csv://SampleTable_1.txt] FROM [SampleTable_1] WHERE Column2 = 'Bob'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using
You can specify other file formats in the URI. The following example exports tab-separated values:

C#

String connectionString = "User=admin;Password=pass;BootStrapServers=https://localhost:9091;Topic=MyTopic;";

using (ApacheKafkaConnection connection = new ApacheKafkaConnection(connectionString)) {
  ApacheKafkaCommand cmd = new ApacheKafkaCommand("SELECT * INTO [SampleTable_1] IN [csv://filename=c:/SampleTable_1.csv;delimiter=tab] FROM [SampleTable_1] WHERE Column2 = 'Bob'", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "User=admin;Password=pass;BootStrapServers=https://localhost:9091;Topic=MyTopic;" 

Using connection As New ApacheKafkaConnection(connectionString)
  Dim cmd As New ApacheKafkaCommand("SELECT * INTO [SampleTable_1] IN [csv://filename=c:/SampleTable_1.csv;delimiter=tab] FROM [SampleTable_1] WHERE Column2 = 'Bob'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using

Copyright (c) 2021 CData Software, Inc. - All rights reserved.
Build 21.0.7940