Note that there are some explanatory texts on larger screens.

plurals
  1. POCassandra hector loader app runs out of memory
    primarykey
    data
    text
    <p>This simple app takes a comma delim file with headers and puts into Cassandra. It works for small file, however the memory just goes up until out of memory exception kills it. </p> <p>What am I missing?</p> <pre><code>package com.company; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import me.prettyprint.cassandra.serializers.StringSerializer; import me.prettyprint.hector.api.Cluster; import me.prettyprint.hector.api.Keyspace; import me.prettyprint.hector.api.beans.HColumn; import me.prettyprint.hector.api.factory.HFactory; import me.prettyprint.hector.api.mutation.Mutator; public class QuickLoad { public static Keyspace keyspace = null; public static void main(String[] args) { File file = new File(args[0]); String keyspaceName = args[1]; String columnFamilyName = args[2]; BufferedReader reader = null; try { keyspace = GetKeyspace(keyspaceName); reader = new BufferedReader(new FileReader(file)); String fileLine = null; String[] headers = null; String[] fields = null; boolean headerLine = true; while ((fileLine = reader.readLine()) != null) { if (headerLine){ headerLine = false; headers = fileLine.substring(1, fileLine.length()-1).split("\",\""); } else { fields = fileLine.substring(1, fileLine.length()-1).split("\",\""); CassandraSave(keyspace, columnFamilyName, headers, fields); } } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (reader != null) { reader.close(); } } catch (IOException e) { e.printStackTrace(); } } System.exit(0); } public static void CassandraSave(Keyspace keyspace, String columnFamily, String[] headers, String[] columns) { try { Mutator mutator = HFactory.createMutator(keyspace, StringSerializer.get()); for (int i = 1; i &lt; headers.length-1; i++) { if ((columns[i] != null) || (!columns[i].equals("null"))) { if (columns[i].length() &gt; 0) { HColumn&lt;String, String&gt; col = HFactory.createStringColumn(headers[i], columns[i]); mutator.insert(columns[1], columnFamily, col); } } } mutator.execute(); } catch (Exception e){ e.printStackTrace(); } } public static Keyspace GetKeyspace(String keyspaceName) { String serverAddress = "localhost:9160"; Cluster cluster = HFactory.getOrCreateCluster("My Cluster", serverAddress); Keyspace keyspace = HFactory.createKeyspace(keyspaceName, cluster); return keyspace; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload