Java Code Examples for org.apache.cassandra.tools.BulkLoader

Following code examples demonstrate how to use org.apache.cassandra.tools.BulkLoader from cassandra. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.apache.cassandra.tools.BulkLoader and various code implementation of this class.
Example 1
Project : cassandra Source File : CqlBulkRecordWriter.java View Source Code on GitHub

    
    private void prepareWriter() throws IOException
    {
        try
        {
            if (writer == null)
            {
                writer = CQLSSTableWriter.builder()
                    .forTable(schema)
                    .using(insertStatement)
                    .withPartitioner(ConfigHelper.getOutputPartitioner(conf))
                    .inDirectory(outputDir)
                    .withBufferSizeInMB(Integer.parseInt(conf.get(BUFFER_SIZE_IN_MB, "64")))
                    .build();
            }
            if (loader == null)
            {
                BulkLoader.ExternalClient externalClient = getExternalClient(conf);
                this.loader = new SSTableLoader(outputDir, externalClient, new BulkRecordWriter.NullOutputHandler()) {
                    @Override
                    public void onSuccess(StreamState finalState)
                    {
                        if (deleteSrc)
                            FileUtils.deleteRecursive(outputDir);
                    }
                };
            }
        }
        catch (Exception e)
        {
            throw new IOException(e);
        }      
    }
			
Example 2
Project : cassandra Source File : CqlBulkRecordWriter.java View Source Code on GitHub

    }

    private BulkLoader.ExternalClient getExternalClient(Configuration conf)
    {
        Set<InetAddress> hosts = new HashSet<InetAddress>();
        String outputAddress = ConfigHelper.getOutputInitialAddress(conf);
        if (outputAddress == null) outputAddress = "localhost";
        String[] nodes = outputAddress.split(",");
        for (String node : nodes)
        {
            try
            {
                hosts.add(InetAddress.getByName(node));
            }
            catch (UnknownHostException e)
            {
                throw new RuntimeException(e);
            }
        }
        int rpcPort = ConfigHelper.getOutputRpcPort(conf);
        String username = ConfigHelper.getOutputKeyspaceUserName(conf);
        String password = ConfigHelper.getOutputKeyspacePassword(conf);
        ITransportFactory transportFactory = ConfigHelper.getClientTransportFactory(conf);
        return new BulkLoader.ExternalClient(hosts,
                rpcPort,
                username,
                password,
                transportFactory,
                CqlBulkOutputFormat.getStoragePort(conf),
                CqlBulkOutputFormat.getSSLStoragePort(conf),
                getServerEncryptOpt(conf));
    }