Reputation: 737
Hi guys i would like to get data in a specified table in cassandra and save it into csv file .Here what i did
//using c# api
// Cluster cluster = Cluster.Builder().AddContactPoint("192.168.0.214").Build();
Cluster cluster = Cluster.Builder().AddContactPoint("127.0.0.1").Build();
List<string> lstOfKeyspaces =cluster.Metadata.GetKeyspaces().ToList<string>();
ISession session = cluster.Connect("integrationobjects");
//get tables in the keysapce
List<string> lstString = cluster.Metadata.GetTables("integrationobjects").ToList<string>();
Console.WriteLine("Connection succeeded");
// Console.ReadLine();
RowSet resultRequest = session.Execute("select json * from emp");
Any help would be appreciated in order to save results into csv file. Thank you in advance
Upvotes: 1
Views: 979
Reputation: 5180
This is as simple as traversing the RowSet your query is returning. Something like that should be enough:
// Open the file for output...
...
// Loop over all the rows
IEnumerable<Row> rowEnumerator = resultRequest.GetEnumerator();
while (rowEnumerator.MoveNext()) {
// Get the row
Row r = rowEnumerator.Current;
// Prepare a new line
List<string> values = new List<string>;
// Loop over all the columns of the row
IEnumerator<Object> colEnumerator = r.GetEnumerator();
while (colEnumerator.MoveNext()) {
values.Add(...); // Stack the strings here
}
// Create the row
string line = String.Join(",", values.ToArray());
// Output line to file
// ...
}
// Close the file
...
Upvotes: 0
Reputation: 12830
Use Cqlsh COPY TO Command
Login To Cqlsh then use the below command :
COPY emp TO 'exp.csv';
Upvotes: 1