Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
P. Oscar Boykin
@johnynek
and in some cases the type can be inferred
Shane Delmore
@ShaneDelmore
That looks cleaner. Experimenting now but it seems the type inference may not work for my case.
P. Oscar Boykin
@johnynek
only thing else I can say it type = ...
Sorry
Shane Delmore
@ShaneDelmore
Where do you import TwitterFuture from?
for the scalaFut.as[TwitterFuture[List[Foo]]]
P. Oscar Boykin
@johnynek
com.twitter.util.{Future => TwitterFuture}
Shane Delmore
@ShaneDelmore
Ahhh…neat.
Raviv Pavel
@raviv

Hi, Looking for an example of converting a scala future to twitter future.
The following fails, looking for ExecutionContext

     val sf:ScalaFuture[Option[String]] = ...
     val tf:TwitterFuture[Option[String]]= twitter2ScalaFuture[Option[String]].invert(sf)

Thanks :)

P. Oscar Boykin
@johnynek
@raviv sorry, just saw this. You need to import an Execution context with scala futures: http://blog.jessitron.com/2014/02/scala-global-executioncontext-makes.html
Benjamin
@bdparrish
Can anyone provide the code for a java implementation of SpecificAvroCodecs such that I can use a toBinary with a SpecificRecordBase object?
Injection<GenericRecord, byte[]> genericRecordInjection = GenericAvroCodecs.toBinary(schema);
byte[] bytes = genericRecordInjection.apply(type);
P. Oscar Boykin
@johnynek
@bdparrish it is a big ugly but I can talk you through it.
Benjamin
@bdparrish
please
P. Oscar Boykin
@johnynek
the implicit parameters are just normal parameters for java
so you can pass them.
which one do you want?
Benjamin
@bdparrish
Class<T> clazz = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];

final ClassTag<T> classTag = ClassTag$.MODULE$.apply(clazz);

Injection<T, byte[]> binaryInjection = SpecificAvroCodecs.toBinary(classTag);
P. Oscar Boykin
@johnynek
that one?
Benjamin
@bdparrish
I have that but the toBinary doesn't like my ClassTag
P. Oscar Boykin
@johnynek
what happens?
that should work (I would wrap it in a static method where you pass a Class in)
Benjamin
@bdparrish
Error:(113, 70) java: method toBinary in class com.twitter.bijection.avro.SpecificAvroCodecs cannot be applied to given types;
required: scala.reflect.ClassTag<T>
found: scala.reflect.ClassTag<T>
reason: inference variable T has incompatible bounds
equality constraints: T
upper bounds: org.apache.avro.specific.SpecificRecordBase
P. Oscar Boykin
@johnynek
all, well just cast it do:
Class<org.apache.avro.specific.SpecificRecordBase>
rather than Class<T> I think
I mean, it is on you that cast is safe.
Benjamin
@bdparrish
yeah, i have Subscriber<T extends SpecificRecordBase>
so the cast will be safe
@johnynek: still doesn't like it
Error:(114, 70) java: method toBinary in class com.twitter.bijection.avro.SpecificAvroCodecs cannot be applied to given types;
required: scala.reflect.ClassTag<T>
found: java.lang.Class<org.apache.avro.specific.SpecificRecordBase>
reason: cannot infer type-variable(s) T
(argument mismatch; java.lang.Class<org.apache.avro.specific.SpecificRecordBase> cannot be converted to scala.reflect.ClassTag<T>)
P. Oscar Boykin
@johnynek
can you post a whole gist?
Benjamin
@bdparrish
of the class?
P. Oscar Boykin
@johnynek
did you change this like: final ClassTag<T> classTag
that still says T
Benjamin
@bdparrish
ahh, got it
T has to be changed on all 3
thanks
P. Oscar Boykin
@johnynek
@bdparrish let me know when it compiles and works for you
Benjamin
@bdparrish
it worked :+1:
@johnynek
P. Oscar Boykin
@johnynek
:)
Benjamin
@bdparrish
@johnynek: getting when picking up the messages off of Kafka
Exception in thread "main" java.lang.InstantiationException
    at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at com.twitter.bijection.avro.SpecificAvroCodecs$.toBinary(AvroCodecs.scala:106)
    at com.twitter.bijection.avro.SpecificAvroCodecs.toBinary(AvroCodecs.scala)
final ClassTag<SpecificRecordBase> classTag = ClassTag$.MODULE$.apply(SpecificRecordBase.class);

Injection<SpecificRecordBase, byte[]> binaryInjection = SpecificAvroCodecs.toBinary(classTag);
P. Oscar Boykin
@johnynek
okay, we might need the actual class of the actual type, not just SpecificRecordBase.
do you know what that type is?
Benjamin
@bdparrish
It is user defined
it is a generic