Skip to content

Instantly share code, notes, and snippets.

View rsds143's full-sized avatar

rsds143

View GitHub Profile
@rsds143
rsds143 / OracleDialect.scala
Created February 5, 2016 21:17
working oracle dialect
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)) {
return Option.apply(new JdbcType("VARCHAR2(255)", java.sql.Types.VARCHAR));
/**
* :: 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, md: MetadataBuilder): Option[DataType] = {
// Handle NUMBER fields that have no precision/scale in special way
@rsds143
rsds143 / create_temp_file.sql
Created December 13, 2015 15:56
spark sql 1.4.0 with cassandra 2.2 and spark-cassandra-connector 1.4.0
CREATE TEMPORARY TABLE words using org.apache.spark.sql.cassandra OPTIONS ( table "words", keyspace "test", cluster "Test Cluster", pushdown "true")
@rsds143
rsds143 / batchwrite.java
Created December 3, 2015 20:18
batch write java example
private void writeBatch(final Statement statement, final String recordString){
try {
getSession().execute(statement);
} catch (WriteTimeoutException timeoutException){
WriteType writeType = timeoutException.getWriteType();
switch (writeType){
case BATCH:
LOG.warn("Batch did not complete fully on the initial coordinator. This batch will be retried on " +
"two other nodes and will likely complete, however there may be a time window where it is out of sync."
+ recordString, timeoutException);
@rsds143
rsds143 / BaseIntegrationTest.java
Created December 2, 2015 18:59
sharing junit tests between different repository types
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
/**
* Created by rsvihla on 12/2/2015.
*/
public abstract class BaseIntegrationTest {
protected abstract DataRepository getDataRepository();
private MyService service;
public class Record{
private String value;
private Integer id;
//setters and getters follow
}
CREATE TABLE work_counts ( status varchar(50), count int, PRIMARY KEY(status));
-- against server for Western US users
SELECT * FROM users WHERE last_name = 'Jones'
-- against server for Eastern US users
SELECT * FROM users WHERE last_name = 'Jones'
INSERT INTO work_queue (work_id, work, status) values ( 100898, 'data to process', 'PENDING')
--against a bunch of separate servers because of sharding and probably done in a batch job
-- not at write time as that may take minutes
SELECT count(*) FROM work_queue where status='PENDING'
--against yet another server again because of sharding
INSERT INTO work_counts ( status, count) values ( 'PENDING', 1298008)
@rsds143
rsds143 / SimpleStateHandling.java
Created April 14, 2015 14:21
Simple State Example
*
* Copyright 2015 Foundational Development
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software