-
Notifications
You must be signed in to change notification settings - Fork 441
GEOMESA-1111 Return null for non-existant field names #817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: David Seapy <ddseapy@ccri.com>
| idx = ctx.indexOf(n) | ||
| } | ||
| ctx.get(idx) | ||
| if (idx < 0) null else ctx.get(idx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i wonder if we could code this a little smarter - we're going to be calling ctx.indexOf for every eval if the idx is -1. Nothing is springing to mind though...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well actually we could just make it default to -2 - but we're still doing 2 checks every time. probably doesn't really matter...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could wrap the get in a try/catch, which would be basically free for the normal case, but make the null case way more expensive...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this?
var doEval: EvaluationContext => Any = null
override def eval(args: Array[Any])(implicit ctx: EvaluationContext): Any = {
if (idx == -1) {
idx = ctx.indexOf(n)
doEval =
if(idx < 0) _ => null
else ec => ec.get(idx)
}
doEval(ctx)
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see how this would work if default and the "idx ==" check where both -2 instead of -1. Then it would only do ctx.indexOf on the first eval() execution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or if "idx == -1" was "doEval == null", which is a bit clearer, basically saying "if we don't have a doEval defined then define it")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would this work to avoid the check altogether?:
var doEval: EvaluationContext => Any = { ctx =>
val idx = ctx.indexOf(n)
doEval =
if(idx < 0) _ => null
else ec => ec.get(idx)
doEval(ctx)
}
override def eval(args: Array[Any])(implicit ctx: EvaluationContext): Any = doEval(ctx)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks reasonable
Signed-off-by: David Seapy <ddseapy@ccri.com>
Signed-off-by: David Seapy ddseapy@ccri.com