Hello! Following the example in the spymemcached module, I have a static
definer as so:
public static RubyClass defineDataBag(Ruby runtime) {
RubyClass result =
runtime.defineClass("DataBag",runtime.getObject(), DATABAG_ALLOCATOR);
result.defineAnnotatedMethods(RubyDataBag.class);
RubyClass rubybagiterator = result.defineClassUnder("BagIterator",
runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
result.defineAnnotatedMethods(RubyBagIterator.class);
return result;
}
which I invoke from a class that extends Library, as so:
@Override
public void load(Ruby runtime, boolean wrap) throws IOException {
this.ruby=runtime;
RubyDataBag.defineDataBag(ruby);
}
In jruby:
require 'jruby'
=> true
ree-1.8.7-2010.02 :002 > require 'pig.jar'
=> true
ree-1.8.7-2010.02 :003 >
org.apache.pig.scripting.jruby.PigLibrary.new.load(JRuby.runtime,false)
It is dying on the "defineAnnotatedMethods," saying that there is "Unknown
coercion target: interface org.apache.pig.data.DataBag"
I don't know what this means! Looking at the JRuby source (RubyBigDecimal
for example), there are plenty of classes that take java types are arguments
and so on. My class basically just wraps a DataBag, and makes it clean to
manipulate one from Ruby.
I can actually instantiate it from Ruby as so:
org.apache.pig.scripting.jruby.RubyDataBag.new(JRuby.runtime,JRuby.runtime.getObject)
but since none of the annotations worked, I can't really do anything.
I continue to appreciate your help in this.
Oh, and I found a page that explains some of the stuff on @JRubyMethod, but
it's not linked to from anywhere (that I could see):
https://github.com/jruby/jruby/wiki/JRubyMethod_Signatures
stack trace of the error follows:
org.apache.pig.scripting.jruby.PigLibrary.new.load(JRuby.runtime,false)
java.lang.RuntimeException: Unknown coercion target: interface
org.apache.pig.data.DataBag
at
org.jruby.internal.runtime.methods.InvocationMethodFactory.loadArgumentWithCast(InvocationMethodFactory.java:1242)
at
org.jruby.internal.runtime.methods.InvocationMethodFactory.loadArguments(InvocationMethodFactory.java:1222)
at
org.jruby.internal.runtime.methods.InvocationMethodFactory.createAnnotatedMethodInvocation(InvocationMethodFactory.java:1503)
at
org.jruby.internal.runtime.methods.InvocationMethodFactory.addAnnotatedMethodInvoker(InvocationMethodFactory.java:1451)
at
org.jruby.internal.runtime.methods.InvocationMethodFactory.getAnnotatedMethodClass(InvocationMethodFactory.java:790)
at
org.jruby.internal.runtime.methods.InvocationMethodFactory.getAnnotatedMethod(InvocationMethodFactory.java:810)
at org.jruby.RubyModule.defineAnnotatedMethod(RubyModule.java:692)
at org.jruby.RubyModule.defineAnnotatedMethod(RubyModule.java:660)
at
org.jruby.anno.TypePopulator$DefaultTypePopulator.populate(TypePopulator.java:75)
at
org.jruby.RubyModule.defineAnnotatedMethodsIndividually(RubyModule.java:654)
at org.jruby.RubyModule.defineAnnotatedMethods(RubyModule.java:542)
at
org.apache.pig.scripting.jruby.RubyDataBag.defineDataBag(RubyDataBag.java:48)
at org.apache.pig.scripting.jruby.PigLibrary.load(PigLibrary.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.jruby.javasupport.JavaMethod.invokeDirectWithExceptionHandling(JavaMethod.java:542)
at org.jruby.javasupport.JavaMethod.invokeDirect(JavaMethod.java:392)
at
org.jruby.java.invokers.InstanceMethodInvoker.call(InstanceMethodInvoker.java:69)
at
org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:332)
at
org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:203)
at org.jruby.ast.CallTwoArgNode.interpret(CallTwoArgNode.java:59)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.RootNode.interpret(RootNode.java:129)
at
org.jruby.evaluator.ASTInterpreter.INTERPRET_EVAL(ASTInterpreter.java:96)
at
org.jruby.evaluator.ASTInterpreter.evalWithBinding(ASTInterpreter.java:161)
at org.jruby.RubyKernel.evalCommon(RubyKernel.java:1135)
at org.jruby.RubyKernel.eval(RubyKernel.java:1088)
at org.jruby.RubyKernel$s$0$3$eval.call(RubyKernel$s$0$3$eval.gen:65535)
at
org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:181)
at
org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:69)
at org.jruby.ast.FCallManyArgsNode.interpret(FCallManyArgsNode.java:60)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at
org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.java:75)
at
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:120)
at
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:134)
at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:154)
at
org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:69)
at org.jruby.ast.CallManyArgsNode.interpret(CallManyArgsNode.java:59)
at org.jruby.ast.FCallOneArgNode.interpret(FCallOneArgNode.java:36)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
at
org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.java:75)
at
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:233)
at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:195)
at
org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:201)
at org.jruby.ast.CallTwoArgNode.interpret(CallTwoArgNode.java:59)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
at org.jruby.ast.RescueNode.executeBody(RescueNode.java:216)
at
org.jruby.ast.RescueNode.interpretWithJavaExceptions(RescueNode.java:120)
at org.jruby.ast.RescueNode.interpret(RescueNode.java:110)
at org.jruby.ast.BeginNode.interpret(BeginNode.java:83)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
at
org.jruby.evaluator.ASTInterpreter.INTERPRET_BLOCK(ASTInterpreter.java:112)
at
org.jruby.runtime.InterpretedBlock.evalBlockBody(InterpretedBlock.java:374)
at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:295)
at
org.jruby.runtime.InterpretedBlock.yieldSpecific(InterpretedBlock.java:229)
at org.jruby.runtime.Block.yieldSpecific(Block.java:99)
at org.jruby.ast.ZYieldNode.interpret(ZYieldNode.java:25)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.EnsureNode.interpret(EnsureNode.java:96)
at org.jruby.ast.BeginNode.interpret(BeginNode.java:83)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
at
org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.java:75)
at
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:212)
at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:187)
at
org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:176)
at
org.jruby.runtime.callsite.CachingCallSite.callIter(CachingCallSite.java:187)
at
org.jruby.ast.FCallOneArgBlockNode.interpret(FCallOneArgBlockNode.java:34)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at
org.jruby.evaluator.ASTInterpreter.INTERPRET_BLOCK(ASTInterpreter.java:112)
at
org.jruby.runtime.InterpretedBlock.evalBlockBody(InterpretedBlock.java:374)
at
org.jruby.runtime.InterpretedBlock.yieldSpecific(InterpretedBlock.java:260)
at org.jruby.runtime.Block.yieldSpecific(Block.java:117)
at org.jruby.ast.YieldTwoNode.interpret(YieldTwoNode.java:31)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.IfNode.interpret(IfNode.java:117)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
at org.jruby.ast.RescueNode.executeBody(RescueNode.java:216)
at
org.jruby.ast.RescueNode.interpretWithJavaExceptions(RescueNode.java:120)
at org.jruby.ast.RescueNode.interpret(RescueNode.java:110)
at org.jruby.ast.BeginNode.interpret(BeginNode.java:83)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at
org.jruby.evaluator.ASTInterpreter.INTERPRET_BLOCK(ASTInterpreter.java:112)
at
org.jruby.runtime.InterpretedBlock.evalBlockBody(InterpretedBlock.java:374)
at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:295)
at
org.jruby.runtime.InterpretedBlock.yieldSpecific(InterpretedBlock.java:229)
at org.jruby.runtime.Block.yieldSpecific(Block.java:99)
at org.jruby.RubyKernel.loop(RubyKernel.java:1419)
at org.jruby.RubyKernel$s$0$0$loop.call(RubyKernel$s$0$0$loop.gen:65535)
at
org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:302)
at
org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:144)
at
org.jruby.runtime.callsite.CachingCallSite.callIter(CachingCallSite.java:153)
at
org.jruby.ast.FCallNoArgBlockNode.interpret(FCallNoArgBlockNode.java:32)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at
org.jruby.evaluator.ASTInterpreter.INTERPRET_BLOCK(ASTInterpreter.java:112)
at
org.jruby.runtime.InterpretedBlock.evalBlockBody(InterpretedBlock.java:374)
at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:347)
at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:304)
at org.jruby.runtime.Block.yield(Block.java:130)
at org.jruby.RubyContinuation.enter(RubyContinuation.java:106)
at org.jruby.RubyKernel.rbCatch(RubyKernel.java:1191)
at
org.jruby.RubyKernel$s$1$0$rbCatch.call(RubyKernel$s$1$0$rbCatch.gen:65535)
at
org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:322)
at
org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:178)
at
org.jruby.runtime.callsite.CachingCallSite.callIter(CachingCallSite.java:187)
at
org.jruby.ast.FCallOneArgBlockNode.interpret(FCallOneArgBlockNode.java:34)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
at
org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.java:75)
at
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:169)
at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:171)
at
org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:302)
at
org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:144)
at
org.jruby.runtime.callsite.CachingCallSite.callIter(CachingCallSite.java:153)
at
org.jruby.ast.CallNoArgBlockNode.interpret(CallNoArgBlockNode.java:64)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
at
org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.java:75)
at
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:147)
at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:163)
at
org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:292)
at
org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:135)
at org.jruby.ast.CallNoArgNode.interpret(CallNoArgNode.java:63)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at
org.jruby.evaluator.ASTInterpreter.INTERPRET_BLOCK(ASTInterpreter.java:112)
at
org.jruby.runtime.InterpretedBlock.evalBlockBody(InterpretedBlock.java:374)
at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:347)
at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:304)
at org.jruby.runtime.Block.yield(Block.java:130)
at org.jruby.RubyContinuation.enter(RubyContinuation.java:106)
at org.jruby.RubyKernel.rbCatch(RubyKernel.java:1191)
at
org.jruby.RubyKernel$s$1$0$rbCatch.call(RubyKernel$s$1$0$rbCatch.gen:65535)
at
org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:322)
at
org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:178)
at
org.jruby.runtime.callsite.CachingCallSite.callIter(CachingCallSite.java:187)
at
org.jruby.ast.FCallOneArgBlockNode.interpret(FCallOneArgBlockNode.java:34)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.EnsureNode.interpret(EnsureNode.java:96)
at org.jruby.ast.BeginNode.interpret(BeginNode.java:83)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
at
org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.java:75)
at
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:190)
at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:179)
at
org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:312)
at
org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:169)
at
Library.Frameworks.JRuby_dot_framework.Versions.$1_dot_6_dot_4.bin.jirb.__file__(/Library/Frameworks/JRuby.framework/Versions/1.6.4/bin/jirb:13)
at
Library.Frameworks.JRuby_dot_framework.Versions.$1_dot_6_dot_4.bin.jirb.load(/Library/Frameworks/JRuby.framework/Versions/1.6.4/bin/jirb)
at org.jruby.Ruby.runScript(Ruby.java:679)
at org.jruby.Ruby.runScript(Ruby.java:672)
at org.jruby.Ruby.runNormally(Ruby.java:579)
at org.jruby.Ruby.runFromMain(Ruby.java:428)
at org.jruby.Main.doRunFromMain(Main.java:278)
at org.jruby.Main.internalRun(Main.java:198)
at org.jruby.Main.run(Main.java:164)
at org.jruby.Main.run(Main.java:148)
at org.jruby.Main.main(Main.java:128)
LoadError: Unknown coercion target: interface org.apache.pig.data.DataBag
from (irb):3:in `evaluate'
from org/jruby/RubyKernel.java:1088:in `eval'
from
/Library/Frameworks/JRuby.framework/Versions/1.6.4/lib/ruby/1.8/irb.rb:158:in
`eval_input'
from
/Library/Frameworks/JRuby.framework/Versions/1.6.4/lib/ruby/1.8/irb.rb:271:in
`signal_status'
from
/Library/Frameworks/JRuby.framework/Versions/1.6.4/lib/ruby/1.8/irb.rb:155:in
`eval_input'
from org/jruby/RubyKernel.java:1419:in `loop'
from org/jruby/RubyKernel.java:1191:in `catch'
from
/Library/Frameworks/JRuby.framework/Versions/1.6.4/lib/ruby/1.8/irb.rb:154:in
`eval_input'
from
/Library/Frameworks/JRuby.framework/Versions/1.6.4/lib/ruby/1.8/irb.rb:71:in
`start'
from org/jruby/RubyKernel.java:1191:in `catch'
from
/Library/Frameworks/JRuby.framework/Versions/1.6.4/lib/ruby/1.8/irb.rb:70:in
`start'
from /Library/Frameworks/JRuby.framework/Versions/1.6.4/bin/jirb:13:in
`(root)'