当前位置: 代码迷 >> SQL >> 【Spark108】Spark SQL动态代码生成4
  详细解决方案

【Spark108】Spark SQL动态代码生成4

热度:314   发布时间:2016-05-05 09:58:17.0
【Spark108】Spark SQL动态代码生成四

?

日志:

?

2015-09-02 14:46:27,765-[TS] DEBUG Executor task launch worker-3 org.apache.spark.sql.execution.joins.SortMergeJoin - Creating Projection: List(classId#2), inputSchema: List(stuId#0, stuName#1, classId#2), codegen:true2015-09-02 14:46:27,766-[TS] DEBUG Executor task launch worker-3 org.apache.spark.sql.catalyst.expressions.codegen.GenerateProjection - MutableRow, initExprs: input[2, StringType] code:

?

?

代码

public SpecificProjection generate(org.apache.spark.sql.catalyst.expressions.Expression[] expr) {  return new SpecificProjection(expr);}class SpecificProjection extends org.apache.spark.sql.catalyst.expressions.codegen.BaseProjection {  private org.apache.spark.sql.catalyst.expressions.Expression[] expressions;        public SpecificProjection(org.apache.spark.sql.catalyst.expressions.Expression[] expr) {    expressions = expr;      }    @Override  public Object apply(Object r) {    return new SpecificRow((InternalRow) r);  }    final class SpecificRow extends org.apache.spark.sql.catalyst.expressions.codegen.CodeGenMutableRow {        private UTF8String c0 = null;            public SpecificRow(InternalRow i) {            {        // column0        /* input[2, StringType] */                boolean isNull0 = i.isNullAt(2);        UTF8String primitive1 = isNull0 ? null : (i.getUTF8String(2));                nullBits[0] = isNull0;        if (!isNull0) {          c0 = primitive1;        }      }          }        public int numFields() { return 1;}    protected boolean[] nullBits = new boolean[1];    public void setNullAt(int i) { nullBits[i] = true; }    public boolean isNullAt(int i) { return nullBits[i]; }        @Override    public Object genericGet(int i) {      if (isNullAt(i)) return null;      switch (i) {        case 0: return c0;      }      return null;    }    public void update(int i, Object value) {      if (value == null) {        setNullAt(i);        return;      }      nullBits[i] = false;      switch (i) {        case 0: { c0 = (UTF8String)value; return;}      }    }                @Override    public int hashCode() {      int result = 37;            result *= 37; result += isNullAt(0) ? 0 : (c0.hashCode());      return result;    }        @Override    public boolean equals(Object other) {      if (other instanceof SpecificRow) {        SpecificRow row = (SpecificRow) other;                if (nullBits[0] != row.nullBits[0] ||          (!nullBits[0] && !(c0.equals(row.c0)))) {          return false;        }                return true;      }      return super.equals(other);    }        @Override    public InternalRow copy() {      Object[] arr = new Object[1];      if (!nullBits[0]) arr[0] = c0;      return new org.apache.spark.sql.catalyst.expressions.GenericInternalRow(arr);    }  }}

?

  相关解决方案