Skip to content

Instantly share code, notes, and snippets.

View rsds143's full-sized avatar

rsds143

View GitHub Profile
JdbcDialect dialect = new JdbcDialect() {
@Override
public boolean canHandle(String url) {
return url.startsWith("jdbc:oracle")
|| url.contains("oracle");
}
@Override
public Option<JdbcType> getJDBCType(DataType dt) {
if(DataTypes.StringType.sameType(dt)) {
/**
* :: DeveloperApi ::
* Default Oracle dialect, mapping a nonspecific numeric type to a general decimal type.
*/
@DeveloperApi
case object OracleDialect extends JdbcDialect {
override def canHandle(url: String): Boolean =
url.startsWith("jdbc:oracle")
override def getCatalystType(
sqlType: Int, typeName: String, size: Int,
—NEVER EVER EVER DO
BEGIN BATCH;
INSERT INTO tester.users (userID, firstName, lastName) VALUES (1, 'Jim', 'James')
INSERT INTO tester.users (userID, firstName, lastName) VALUES (2, 'Ernie', 'Orosco')
INSERT INTO tester.users (userID, firstName, lastName) VALUES (3, 'Jose', 'Garza')
INSERT INTO tester.users (userID, firstName, lastName) VALUES (4, 'Sammy', 'Mason')
INSERT INTO tester.users (userID, firstName, lastName) VALUES (5, 'Larry', 'Bird')
INSERT INTO tester.users (userID, firstName, lastName) VALUES (6, 'Jim', 'Smith')
APPLY BATCH;
BEGIN BATCH;
UPDATE users SET name='Jim' where id =1;
UPDATE users_by_ssn set name='Jim' where ssn='888–99–9999';
APPLY BATCH;
—NEVER EVER EVER DO
BEGIN UNLOGGED BATCH;
INSERT INTO tester.users (userID, firstName, lastName) VALUES (1, 'Jim', 'James')
INSERT INTO tester.users (userID, firstName, lastName) VALUES (2, 'Ernie', 'Orosco')
INSERT INTO tester.users (userID, firstName, lastName) VALUES (3, 'Jose', 'Garza')
INSERT INTO tester.users (userID, firstName, lastName) VALUES (4, 'Sammy', 'Mason')
INSERT INTO tester.users (userID, firstName, lastName) VALUES (5, 'Larry', 'Bird')
INSERT INTO tester.users (userID, firstName, lastName) VALUES (6, 'Jim', 'Smith')
APPLY BATCH;
BEGIN UNLOGGED BATCH;
INSERT INTO weather_readings (date, timestamp, temp) values (20140822,'2014-08-22T11:00:00.00+0000', 98.2);
INSERT INTO weather_readings (date, timestamp, temp) values (20140822,'2014-08-22T11:00:15.00+0000', 99.2);
APPLY BATCH;
@rsds143
rsds143 / BulkLoader.java
Last active March 3, 2017 17:52
with thread pool
/**
* I HAVE NOT BEEN FULLY TESTED DO NOT USE ME IN PRODUCTION CODE THERE ARE NO WARRANTIES
*/
public class BulkLoader {
private final int threads;
private final String[] contactHosts;
public BulkLoader(int threads, String...contactHosts){
this.threads = threads;
/**
* I HAVE NOT BEEN FULLY TESTED DO NOT USE ME IN PRODUCTION CODE THERE ARE NO WARRANTIES
* This is with using the approach in the previous blog post
*/
public class BulkLoader {
private final int threads;
private final String[] contactHosts;
public BulkLoader(int threads, String...contactHosts){
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark._
import org.apache.spark.storage._
import org.apache.spark.streaming._
object MapWithState {
val batchCountKey = "batchCount"
public class KeepAlive{
public static void main(String[] args){
Cluster cluster = Cluster.builder().addContactPoint("foo")
.withSocketOptions(new SocketOptions().setKeepAlive(true))
.build();
}
}