Skip to content

Instantly share code, notes, and snippets.

@julianpeeters
julianpeeters / spark-avro-reading-noIDL
Last active February 8, 2021 17:05
read avros in spark without an IDL with GenericRecord
//Adapted from: https://github.com/jcrobak/avro-examples
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.avro.generic.GenericRecord
import org.apache.avro.mapred.AvroKey
import org.apache.avro.mapreduce.AvroKeyInputFormat
import org.apache.hadoop.io.NullWritable
import org.apache.commons.lang.StringEscapeUtils.escapeCsv
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
@julianpeeters
julianpeeters / gist:892bf83ad9defea3a160
Created October 26, 2014 23:11
Case-Class-Generator error - classloader not working after upgrading build.properties to use sbt0.13+ instead of sbt0.12
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.julianpeeters.caseclass.generator.DynamicClassLoader.loadClass(DynamicClassLoader.java:18)
at com.julianpeeters.caseclass.generator.DynamicCaseClass.<init>(DynamicCaseClass.scala:24)
at Example$delayedInit$body.apply(TEST.scala:8)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
@julianpeeters
julianpeeters / gist:210d54a211d3c10a767e
Created October 29, 2014 04:16
error: custom classloader succeeds with run, fails with test after upgrading from sbt 0.12.2 to sbt 0.13.7-M4
> test
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.julianpeeters.caseclass.generator.DynamicClassLoader.loadClass(DynamicClassLoader.java:19)
at com.julianpeeters.caseclass.generator.DynamicCaseClass.<init>(DynamicCaseClass.scala:24)
at IntIntSpec.<init>(IntIntSpec.scala:17)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
@julianpeeters
julianpeeters / gist:a8023c57d7bf5f460c9f
Created November 8, 2014 09:11
option test failing for case-class-generator
[error] (run-main) scala.reflect.internal.FatalError: bad symbolic reference. A signature in sample.MyRecord_TYPESpec refers to type scala.Option[String]
[error] in package sample which is not available.
[error] It may be completely missing from the current classpath, or the version on
[error] the classpath might be incompatible with the version used when compiling sample.MyRecord_TYPESpec.
scala.reflect.internal.FatalError: bad symbolic reference. A signature in sample.MyRecord_TYPESpec refers to type scala.Option[String]
in package sample which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling sample.MyRecord_TYPESpec.
at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:49)
at scala.reflect.internal.SymbolTable.globalError(SymbolTable.scala:48)
@julianpeeters
julianpeeters / gist:17b208713a2f922f8706
Created November 25, 2014 00:25
match strings to types
def stringToType(classNamespace: Option[String], fieldType: String): scala.reflect.runtime.universe.Type = {
def getBoxed(typeName: String): String = {
typeName.dropWhile( c => (c != '[') ).drop(1).dropRight(1)
}
fieldType match {
case "Byte" => typeOf[Byte]
case "Short" => typeOf[Short]
@julianpeeters
julianpeeters / gist:0fd3b23dc26f4f757e37
Created December 15, 2014 07:13
scala signature bytes to human-readable
correctParsedSig.get.bytes.map { byte => (byte & 0xff).toHexString }.mkString("[ ", " ", " ]")
@julianpeeters
julianpeeters / test.avdl
Last active November 26, 2015 00:56 — forked from delagoya/test.avdl
Avro IDL comments to Avrodoc example 2
@namespace("com.example")
/**
This is a comment for the whole protocol
*/
protocol Example {
/**
The comment applies to the `NoSpaces` record, but is not indented to the
@julianpeeters
julianpeeters / TwitterSourceConnector.java
Created April 12, 2016 19:37
How do Kafka configs work? Surprised that this fails. How can I avoid duplicating configs between the main app and the twitter connector?
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
case class DoSomething()
class ComputationActor extends Actor with Listeners {
def receive = listenerManagement orElse {
case DoSomething() = gossip(doSomething())
}
def doSomething(): Compuation = ???
}