Skip to content

Instantly share code, notes, and snippets.

View dbtsai's full-sized avatar

DB Tsai dbtsai

View GitHub Profile
package org.apache.spark.sql.sources.v2
import org.apache.spark.annotation.Experimental
import org.apache.spark.sql.catalog.v2.expressions.NamedReference
/**
* A filter that evaluates to `true` iff the field evaluates to a value
* equal to `value`.
*
* @since 3.0.0
package org.apache.spark.sql.sources.v2;
import org.apache.spark.annotation.Experimental;
import org.apache.spark.sql.catalog.v2.expressions.NamedReference;
@Experimental
public abstract class Filter {
/**
* Returns list of columns that are referenced by this filter.
*/
object ObjWithMethod {
def runClosure(body: () => Boolean): Boolean = {
println("In runClosure")
val method = Class.forName("ObjWithMethod")
.getDeclaredMethod("calledByRefection", classOf[() => Boolean])
method.invoke(null, body).asInstanceOf[Boolean]
}
def calledByRefection(body: => Boolean): Boolean = {
@dbtsai
dbtsai / JsonParser.scala
Created April 6, 2018 07:13
testing json stream parser
val jsonTxt =
"""
|{
| "name": "Tom",
| "age": 25,
| "address": ["Poland", "5th avenue"]
|}
|""".stripMargin
/**
#!/usr/bin/perl
#
# Pre-commit hook for running checkstyle on changed Java sources
#
# To use this you need:
# 1. checkstyle's jar file somewhere
# 2. a checkstyle XML check file somewhere
# 3. To configure git:
# * git config --add checkstyle.jar <location of jar>
# * git config --add checkstyle.checkfile <location of checkfile>
@dbtsai
dbtsai / gist:7488981
Last active December 28, 2015 10:49
InMapperCombiner
public class InMapperCombiner < KEY extends WritableComparable, VALUE extends Writable > {
private static final int DEFAULT_CAPACITY = 8388608;
private static final int DEFAULT_INITIAL_CAPACITY = 65536;
private static final float DEFAULT_LOAD_FACTOR = .75F;
private final int maxCacheCapacity;
private final Map < KEY, VALUE > lruCache;
private CombiningFunction < VALUE > combiningFunction;
private Mapper.Context context;
class UserResource(DuJourModelResource):
profile_image_thumbnail = fields.OneToOneField('website.api.v1.media_resources.ImageResource', 'profile_image_thumbnail',full=True, null=True)
profile_image_standard = fields.OneToOneField('website.api.v1.media_resources.ImageResource', 'profile_image_standard', full=True, null=True)
created_time = fields.DateTimeField(attribute='created_time', readonly=True, default=now)
updated_time = fields.DateTimeField(attribute='updated_time', readonly=True, default=now)
age = fields.IntegerField(attribute='age')
class Meta:
serializer = TzSerializer()
always_return_data = True
@dbtsai
dbtsai / gist:2970244
Created June 22, 2012 04:33
tastypie obj_update
def obj_update(self, bundle, request=None, skip_errors=False, **kwargs):
"""
A ORM-specific implementation of ``obj_update``.
"""
# import pdb
# pdb.set_trace()
setattr(bundle.obj,self._meta.detail_uri_name,None)
if not bundle.obj or not getattr(bundle.obj,self._meta.detail_uri_name):
# Attempt to hydrate data from kwargs before doing a lookup for the object.
# This step is needed so certain values (like datetime) will pass model validation.