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

Painless code generation error when returning nothing from a Function #22908

Closed
nik9000 opened this Issue Feb 1, 2017 · 5 comments

Comments

Projects
None yet
4 participants
@nik9000
Contributor

nik9000 commented Feb 1, 2017

This blows up on the Debug.explain.

DELETE /test

PUT /test
{
  "settings": {
    "number_of_replicas": 0,
    "number_of_shards": 2
  },
  "mappings": {
    "test": {
      "properties": {
        "k": {
          "type": "keyword"
        },
        "dc": {
          "type": "keyword"
        },
        "d": {
          "type": "date",
          "format": "yyyy-MM-dd"
        },
        "v": {
          "type": "long"
        }
      }
    }
  }
}

POST /test/test
{"k": "a", "dc": "dc1", "d": "2017-01-01", "v": 1}
POST /test/test
{"k": "a", "dc": "dc1", "d": "2017-01-02", "v": 2}
POST /test/test
{"k": "b", "dc": "dc1", "d": "2017-01-01", "v": 3}
POST /test/test
{"k": "c", "dc": "dc2", "d": "2017-01-01", "v": 4}
POST /test/test
{"k": "c", "dc": "dc2", "d": "2017-01-02", "v": 5}
POST /test/_refresh

POST /test/_search?size=0
{
  "aggs": {
    "dc": {
      "terms": {
        "field": "dc"
      },
      "aggs": {
        "k": {
          "terms": {"field": "k"},
          "aggs": {
            "k": {
              "top_hits": {
                "size": 1,
                "sort": [
                  {
                    "d": {
                      "order": "desc"
                    }
                  }
                ]
              }
            },
            "last_k": {
              "scripted_metric": {
                "init_script": "params._agg.v = 0; params._agg.t = 0",
                "map_script": "if (doc.d.value > params._agg.t) {params._agg.t = doc.d.value; params._agg.v = doc.v}",
                "reduce_script": "params._aggs.stream().reduce((lhs, rhs) -> lhs.t > rhs.t ? lhs.v : rhs.v).map(agg -> Debug.explain(agg)).orElse(0)", 
                "combine_script": "params._agg"
              }
            }
          }
        }
      }
    }
  }
}

@nik9000

This comment has been minimized.

Contributor

nik9000 commented Feb 1, 2017

I mean, it should blow up, but it blows up with a verify error:

            "reason": "Operand stack underflow\nException Details:\n  Location:\n    org/elasticsearch/painless/Executable$Script.lambda$1(Ljava/lang/Object;)Ljava/lang/Object; @4: areturn\n  Reason:\n    Attempt to pop empty stack.\n  Current Frame:\n    bci: @4\n    flags: { }\n    locals: { 'java/lang/Object' }\n    stack: { }\n  Bytecode:\n    0x0000000: 2ab8 0038 b0                           \n"
@jdconrad

This comment has been minimized.

Contributor

jdconrad commented Feb 1, 2017

I think this may be the same issue that @polyfractal had at some point when he was working with Painless for a different project. I'll have to check back through our conversations to see if I can find when he mentioned it.

@polyfractal

This comment has been minimized.

Member

polyfractal commented Feb 1, 2017

I was actually getting something slightly different. I can't seem to find the full stack trace, but from our chat it was:

ScriptException[runtime error
]; nested: PainlessExplainError;

I'll see if I can recreate it for a proper bug-report, but I think it was something unrelated

@nik9000

This comment has been minimized.

Contributor

nik9000 commented Feb 2, 2017

PainlessExplainError

That error shouldn't escape the node. It is supposed to be an implementation detail of Debug.explain. Uncatchable, invisible, and final. I was using it a bunch today and, other than this issue it was working pretty well.

@nik9000

This comment has been minimized.

Contributor

nik9000 commented Feb 3, 2017

I've tracked this down a bit further. The following painless script is broken:

def test(StringBuilder b, int i) {
  return b.setLength(i)
}
test(new StringBuilder(), 1)

I've almost found the right place to fix.

nik9000 added a commit to nik9000/elasticsearch that referenced this issue Feb 3, 2017

Painless: Don't allow casting from void to def
Painless can cast anything into the magic type `def` but it
really shouldn't try to cast **nothing** into `def`. That causes
the byte code generation library to freak out a little.

Closes elastic#22908

nik9000 added a commit that referenced this issue Feb 3, 2017

Painless: Don't allow casting from void to def (#22969)
Painless can cast anything into the magic type `def` but it
really shouldn't try to cast **nothing** into `def`. That causes
the byte code generation library to freak out a little.

Closes #22908

nik9000 added a commit that referenced this issue Feb 3, 2017

Painless: Don't allow casting from void to def (#22969)
Painless can cast anything into the magic type `def` but it
really shouldn't try to cast **nothing** into `def`. That causes
the byte code generation library to freak out a little.

Closes #22908

nik9000 added a commit that referenced this issue Feb 3, 2017

Painless: Don't allow casting from void to def (#22969)
Painless can cast anything into the magic type `def` but it
really shouldn't try to cast **nothing** into `def`. That causes
the byte code generation library to freak out a little.

Closes #22908
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment