當前位置: 首頁>>代碼示例>>Java>>正文


Java JExpr.direct方法代碼示例

本文整理匯總了Java中com.sun.codemodel.JExpr.direct方法的典型用法代碼示例。如果您正苦於以下問題:Java JExpr.direct方法的具體用法?Java JExpr.direct怎麽用?Java JExpr.direct使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.codemodel.JExpr的用法示例。


在下文中一共展示了JExpr.direct方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createClassInstances

import com.sun.codemodel.JExpr; //導入方法依賴的package包/類
private List<Partitioner> createClassInstances(int actualPartitions) throws SchemaChangeException {
  // set up partitioning function
  final LogicalExpression expr = config.getExpr();
  final ClassGenerator<Partitioner> cg = context.getClassProducer().createGenerator(Partitioner.TEMPLATE_DEFINITION).getRoot();
  ClassGenerator<Partitioner> cgInner = cg.getInnerGenerator("OutgoingRecordBatch");

  final LogicalExpression materializedExpr = context.getClassProducer().materialize(expr, incoming);

  // generate code to copy from an incoming value vector to the destination partition's outgoing value vector
  JExpression bucket = JExpr.direct("bucket");

  // generate evaluate expression to determine the hash
  ClassGenerator.HoldingContainer exprHolder = cg.addExpr(materializedExpr);
  cg.getEvalBlock().decl(JType.parse(cg.getModel(), "int"), "bucket", exprHolder.getValue().mod(JExpr.lit(outGoingBatchCount)));
  cg.getEvalBlock()._return(cg.getModel().ref(Math.class).staticInvoke("abs").arg(bucket));

  CopyUtil.generateCopies(cgInner, incoming, incoming.getSchema().getSelectionVectorMode() == SelectionVectorMode.FOUR_BYTE);

  // compile and setup generated code
  List<Partitioner> subPartitioners = cg.getCodeGenerator().getImplementationClass(actualPartitions);
  return subPartitioners;
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:23,代碼來源:PartitionSenderOperator.java

示例2: generateCopies

import com.sun.codemodel.JExpr; //導入方法依賴的package包/類
public static void generateCopies(ClassGenerator g, VectorAccessible batch, boolean hyper){
  // we have parallel ids for each value vector so we don't actually have to deal with managing the ids at all.
  int fieldId = 0;

  JExpression inIndex = JExpr.direct("inIndex");
  JExpression outIndex = JExpr.direct("outIndex");
  for(VectorWrapper<?> vv : batch) {
    String copyMethod;
    if (!Types.isFixedWidthType(vv.getField().getType()) || Types.isRepeated(vv.getField().getType()) || Types.isComplex(vv.getField().getType())) {
      copyMethod = "copyFromSafe";
    } else {
      copyMethod = "copyFrom";
    }
    g.rotateBlock();
    JVar inVV = g.declareVectorValueSetupAndMember("incoming", new TypedFieldId(vv.getField().getType(), vv.isHyper(), fieldId));
    JVar outVV = g.declareVectorValueSetupAndMember("outgoing", new TypedFieldId(vv.getField().getType(), false, fieldId));

    if(hyper){

      g.getEvalBlock().add(
              outVV
                      .invoke(copyMethod)
                      .arg(
                              inIndex.band(JExpr.lit((int) Character.MAX_VALUE)))
                      .arg(outIndex)
                      .arg(
                              inVV.component(inIndex.shrz(JExpr.lit(16)))
                      )
      );
    }else{
      g.getEvalBlock().add(outVV.invoke(copyMethod).arg(inIndex).arg(outIndex).arg(inVV));
    }

    g.rotateBlock();
    fieldId++;
  }
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:38,代碼來源:CopyUtil.java

示例3: createClassInstances

import com.sun.codemodel.JExpr; //導入方法依賴的package包/類
private List<Partitioner> createClassInstances(int actualPartitions) throws SchemaChangeException {
  // set up partitioning function
  final LogicalExpression expr = operator.getExpr();
  final ErrorCollector collector = new ErrorCollectorImpl();
  final ClassGenerator<Partitioner> cg ;

  cg = CodeGenerator.getRoot(Partitioner.TEMPLATE_DEFINITION, context.getFunctionRegistry());
  ClassGenerator<Partitioner> cgInner = cg.getInnerGenerator("OutgoingRecordBatch");

  final LogicalExpression materializedExpr = ExpressionTreeMaterializer.materialize(expr, incoming, collector, context.getFunctionRegistry());
  if (collector.hasErrors()) {
    throw new SchemaChangeException(String.format(
        "Failure while trying to materialize incoming schema.  Errors:\n %s.",
        collector.toErrorString()));
  }

  // generate code to copy from an incoming value vector to the destination partition's outgoing value vector
  JExpression bucket = JExpr.direct("bucket");

  // generate evaluate expression to determine the hash
  ClassGenerator.HoldingContainer exprHolder = cg.addExpr(materializedExpr);
  cg.getEvalBlock().decl(JType.parse(cg.getModel(), "int"), "bucket", exprHolder.getValue().mod(JExpr.lit(outGoingBatchCount)));
  cg.getEvalBlock()._return(cg.getModel().ref(Math.class).staticInvoke("abs").arg(bucket));

  CopyUtil.generateCopies(cgInner, incoming, incoming.getSchema().getSelectionVectorMode() == SelectionVectorMode.FOUR_BYTE);

  try {
    // compile and setup generated code
    List<Partitioner> subPartitioners = context.getImplementationClass(cg, actualPartitions);
    return subPartitioners;

  } catch (ClassTransformationException | IOException e) {
    throw new SchemaChangeException("Failure while attempting to load generated class", e);
  }
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:36,代碼來源:PartitionSenderRootExec.java

示例4: generateCopies

import com.sun.codemodel.JExpr; //導入方法依賴的package包/類
public static void generateCopies(ClassGenerator<?> g, VectorAccessible batch, boolean hyper){
  // we have parallel ids for each value vector so we don't actually have to deal with managing the ids at all.
  int fieldId = 0;

  JExpression inIndex = JExpr.direct("inIndex");
  JExpression outIndex = JExpr.direct("outIndex");
  for(VectorWrapper<?> vv : batch) {
    String copyMethod;
    if (!Types.isFixedWidthType(getMajorTypeForField(vv.getField())) || Types.isRepeated(getMajorTypeForField(vv.getField())) || Types.isComplex(getMajorTypeForField(vv.getField()))) {
      copyMethod = "copyFromSafe";
    } else {
      copyMethod = "copyFrom";
    }
    g.rotateBlock();
    JVar inVV = g.declareVectorValueSetupAndMember("incoming", new TypedFieldId(CompleteType.fromField(vv.getField()), vv.isHyper(), fieldId));
    JVar outVV = g.declareVectorValueSetupAndMember("outgoing", new TypedFieldId(CompleteType.fromField(vv.getField()), false, fieldId));

    if(hyper){

      g.getEvalBlock().add(
              outVV
                      .invoke(copyMethod)
                      .arg(
                              inIndex.band(JExpr.lit((int) Character.MAX_VALUE)))
                      .arg(outIndex)
                      .arg(
                              inVV.component(inIndex.shrz(JExpr.lit(16)))
                      )
      );
    }else{
      g.getEvalBlock().add(outVV.invoke(copyMethod).arg(inIndex).arg(outIndex).arg(inVV));
    }

    g.rotateBlock();
    fieldId++;
  }
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:38,代碼來源:CopyUtil.java

示例5: generateEvalBody

import com.sun.codemodel.JExpr; //導入方法依賴的package包/類
@Override
  protected HoldingContainer generateEvalBody(ClassGenerator<?> g, CompleteType resolvedOutput, HoldingContainer[] inputVariables, String body, JVar[] workspaceJVars) {

    g.getEvalBlock().directStatement(String.format("//---- start of eval portion of %s function. ----//", registeredNames[0]));

    JBlock sub = new JBlock(true, true);
    JBlock topSub = sub;

    JVar complexWriter = g.declareClassField("complexWriter", g.getModel()._ref(ComplexWriter.class));

    //Default name is "col", if not passed in a reference name for the output vector.
    String refName = ref == null? "col" : ref.getRootSegment().getPath();
    final JExpression writerCreator = JExpr.direct("writerCreator");
    g.getSetupBlock().assign(complexWriter, writerCreator.invoke("addComplexWriter").arg(refName));

    g.getEvalBlock().add(complexWriter.invoke("setPosition").arg(g.getMappingSet().getValueWriteIndex()));

    sub.decl(g.getModel()._ref(ComplexWriter.class), getReturnName(), complexWriter);

    // add the subblock after the out declaration.
    g.getEvalBlock().add(topSub);

    addProtectedBlock(g, sub, body, inputVariables, workspaceJVars, false);


//    JConditional jc = g.getEvalBlock()._if(complexWriter.invoke("ok").not());

//    jc._then().add(complexWriter.invoke("reset"));
    //jc._then().directStatement("System.out.println(\"debug : write ok fail!, inIndex = \" + inIndex);");
//    jc._then()._return(JExpr.FALSE);

    //jc._else().directStatement("System.out.println(\"debug : write successful, inIndex = \" + inIndex);");

    g.getEvalBlock().directStatement(String.format("//---- end of eval portion of %s function. ----//", registeredNames[0]));

    return null;
  }
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:38,代碼來源:ComplexWriterFunctionHolder.java


注:本文中的com.sun.codemodel.JExpr.direct方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。