Codota Logo
SqlImplementor$Context
Code IndexAdd Codota to your IDE (free)

How to use
SqlImplementor$Context
in
org.apache.calcite.rel.rel2sql

Best Java code snippets using org.apache.calcite.rel.rel2sql.SqlImplementor$Context (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Charset c =
  • Codota IconString charsetName;Charset.forName(charsetName)
  • Codota IconCharset.defaultCharset()
  • Codota IconContentType contentType;contentType.getCharset()
  • Smart code suggestions by Codota
}
origin: apache/hive

public Result translate(Project e) {
 // This variant is for the top project as we want to keep
 // the column aliases instead of producing STAR
 Result x = visitChild(0, e.getInput());
 parseCorrelTable(e, x);
 final Builder builder =
   x.builder(e, Clause.SELECT);
 final List<SqlNode> selectList = new ArrayList<>();
 for (RexNode ref : e.getChildExps()) {
  SqlNode sqlExpr = builder.context.toSql(null, ref);
  addSelect(selectList, sqlExpr, e.getRowType());
 }
 builder.setSelect(new SqlNodeList(selectList, POS));
 return builder.result();
}
origin: Qihoo360/Quicksql

private SqlNode createLeftCall(SqlOperator op, List<SqlNode> nodeList) {
 if (nodeList.size() == 2) {
  return op.createCall(new SqlNodeList(nodeList, POS));
 }
 final List<SqlNode> butLast = Util.skipLast(nodeList);
 final SqlNode last = nodeList.get(nodeList.size() - 1);
 final SqlNode call = createLeftCall(op, butLast);
 return op.createCall(new SqlNodeList(ImmutableList.of(call, last), POS));
}
origin: Qihoo360/Quicksql

private SqlNode toSql(RexProgram program, RexFieldCollation rfc) {
 SqlNode node = toSql(program, rfc.left);
 switch (rfc.getDirection()) {
 case DESCENDING:
 case STRICTLY_DESCENDING:
  node = SqlStdOperatorTable.DESC.createCall(POS, node);
 }
 if (rfc.getNullDirection()
     != dialect.defaultNullDirection(rfc.getDirection())) {
  switch (rfc.getNullDirection()) {
  case FIRST:
   node = SqlStdOperatorTable.NULLS_FIRST.createCall(POS, node);
   break;
  case LAST:
   node = SqlStdOperatorTable.NULLS_LAST.createCall(POS, node);
   break;
  }
 }
 return node;
}
origin: Qihoo360/Quicksql

/** @see #dispatch */
public Result visit(Project e) {
 Result x = visitChild(0, e.getInput());
 parseCorrelTable(e, x);
 if (isStar(e.getChildExps(), e.getInput().getRowType(), e.getRowType())) {
  return x;
 }
 final Builder builder =
   x.builder(e, Clause.SELECT);
 final List<SqlNode> selectList = new ArrayList<>();
 for (RexNode ref : e.getChildExps()) {
  SqlNode sqlExpr = builder.context.toSql(null, ref);
  addSelect(selectList, sqlExpr, e.getRowType());
 }
 builder.setSelect(new SqlNodeList(selectList, POS));
 return builder.result();
}
origin: org.apache.calcite/calcite-core

/** Converts a collation to an ORDER BY item. */
public SqlNode toSql(RelFieldCollation collation) {
 SqlNode node = field(collation.getFieldIndex());
 switch (collation.getDirection()) {
 case DESCENDING:
 case STRICTLY_DESCENDING:
  node = SqlStdOperatorTable.DESC.createCall(POS, node);
 }
 if (collation.nullDirection != dialect.defaultNullDirection(collation.direction)) {
  switch (collation.nullDirection) {
  case FIRST:
   node = SqlStdOperatorTable.NULLS_FIRST.createCall(POS, node);
   break;
  case LAST:
   node = SqlStdOperatorTable.NULLS_LAST.createCall(POS, node);
   break;
  }
 }
 return node;
}
origin: org.apache.calcite/calcite-core

void addOrderItem(List<SqlNode> orderByList, RelFieldCollation field) {
 if (field.nullDirection != RelFieldCollation.NullDirection.UNSPECIFIED) {
  final boolean first =
    field.nullDirection == RelFieldCollation.NullDirection.FIRST;
  SqlNode nullDirectionNode =
    dialect.emulateNullDirection(field(field.getFieldIndex()),
      first, field.direction.isDescending());
  if (nullDirectionNode != null) {
   orderByList.add(nullDirectionNode);
   field = new RelFieldCollation(field.getFieldIndex(),
     field.getDirection(),
     RelFieldCollation.NullDirection.UNSPECIFIED);
  }
 }
 orderByList.add(toSql(field));
}
origin: org.apache.calcite/calcite-core

private SqlNode toSql(RexProgram program, RexFieldCollation rfc) {
 SqlNode node = toSql(program, rfc.left);
 switch (rfc.getDirection()) {
 case DESCENDING:
 case STRICTLY_DESCENDING:
  node = SqlStdOperatorTable.DESC.createCall(POS, node);
 }
 if (rfc.getNullDirection()
     != dialect.defaultNullDirection(rfc.getDirection())) {
  switch (rfc.getNullDirection()) {
  case FIRST:
   node = SqlStdOperatorTable.NULLS_FIRST.createCall(POS, node);
   break;
  case LAST:
   node = SqlStdOperatorTable.NULLS_LAST.createCall(POS, node);
   break;
  }
 }
 return node;
}
origin: Qihoo360/Quicksql

private SqlNode createSqlWindowBound(RexWindowBound rexWindowBound) {
 if (rexWindowBound.isCurrentRow()) {
  return SqlWindow.createCurrentRow(POS);
 }
 if (rexWindowBound.isPreceding()) {
  if (rexWindowBound.isUnbounded()) {
   return SqlWindow.createUnboundedPreceding(POS);
  } else {
   SqlNode literal = toSql(null, rexWindowBound.getOffset());
   return SqlWindow.createPreceding(literal, POS);
  }
 }
 if (rexWindowBound.isFollowing()) {
  if (rexWindowBound.isUnbounded()) {
   return SqlWindow.createUnboundedFollowing(POS);
  } else {
   SqlNode literal = toSql(null, rexWindowBound.getOffset());
   return SqlWindow.createFollowing(literal, POS);
  }
 }
 throw new AssertionError("Unsupported Window bound: "
   + rexWindowBound);
}
origin: org.apache.calcite/calcite-core

private SqlNode createSqlWindowBound(RexWindowBound rexWindowBound) {
 if (rexWindowBound.isCurrentRow()) {
  return SqlWindow.createCurrentRow(POS);
 }
 if (rexWindowBound.isPreceding()) {
  if (rexWindowBound.isUnbounded()) {
   return SqlWindow.createUnboundedPreceding(POS);
  } else {
   SqlNode literal = toSql(null, rexWindowBound.getOffset());
   return SqlWindow.createPreceding(literal, POS);
  }
 }
 if (rexWindowBound.isFollowing()) {
  if (rexWindowBound.isUnbounded()) {
   return SqlWindow.createUnboundedFollowing(POS);
  } else {
   SqlNode literal = toSql(null, rexWindowBound.getOffset());
   return SqlWindow.createFollowing(literal, POS);
  }
 }
 throw new AssertionError("Unsupported Window bound: "
   + rexWindowBound);
}
origin: Qihoo360/Quicksql

/** @see #dispatch */
public Result visit(Sort e) {
 Result x = visitChild(0, e.getInput());
 Builder builder = x.builder(e, Clause.ORDER_BY);
 List<SqlNode> orderByList = Expressions.list();
 for (RelFieldCollation field : e.getCollation().getFieldCollations()) {
  builder.addOrderItem(orderByList, field);
 }
 if (!orderByList.isEmpty()) {
  builder.setOrderBy(new SqlNodeList(orderByList, POS));
  x = builder.result();
 }
 if (e.fetch != null) {
  builder = x.builder(e, Clause.FETCH);
  builder.setFetch(builder.context.toSql(null, e.fetch));
  x = builder.result();
 }
 if (e.offset != null) {
  builder = x.builder(e, Clause.OFFSET);
  builder.setOffset(builder.context.toSql(null, e.offset));
  x = builder.result();
 }
 return x;
}
origin: Qihoo360/Quicksql

/** Converts a collation to an ORDER BY item. */
public SqlNode toSql(RelFieldCollation collation) {
 SqlNode node = field(collation.getFieldIndex());
 switch (collation.getDirection()) {
 case DESCENDING:
 case STRICTLY_DESCENDING:
  node = SqlStdOperatorTable.DESC.createCall(POS, node);
 }
 if (collation.nullDirection != dialect.defaultNullDirection(collation.direction)) {
  switch (collation.nullDirection) {
  case FIRST:
   node = SqlStdOperatorTable.NULLS_FIRST.createCall(POS, node);
   break;
  case LAST:
   node = SqlStdOperatorTable.NULLS_LAST.createCall(POS, node);
   break;
  }
 }
 return node;
}
origin: Qihoo360/Quicksql

public void addOrderItem(List<SqlNode> orderByList,
  RelFieldCollation field) {
 if (field.nullDirection != RelFieldCollation.NullDirection.UNSPECIFIED) {
  boolean first = field.nullDirection == RelFieldCollation.NullDirection.FIRST;
  SqlNode nullDirectionNode =
    dialect.emulateNullDirection(context.field(field.getFieldIndex()),
      first, field.direction.isDescending());
  if (nullDirectionNode != null) {
   orderByList.add(nullDirectionNode);
   field = new RelFieldCollation(field.getFieldIndex(),
     field.getDirection(),
     RelFieldCollation.NullDirection.UNSPECIFIED);
  }
 }
 orderByList.add(context.toSql(field));
}
origin: org.apache.calcite/calcite-core

/** Converts a call to an aggregate function to an expression. */
public SqlNode toSql(AggregateCall aggCall) {
 final SqlOperator op = aggCall.getAggregation();
 final List<SqlNode> operandList = Expressions.list();
 for (int arg : aggCall.getArgList()) {
  operandList.add(field(arg));
 }
 final SqlLiteral qualifier =
   aggCall.isDistinct() ? SqlSelectKeyword.DISTINCT.symbol(POS) : null;
 final SqlNode[] operands = operandList.toArray(new SqlNode[0]);
 List<SqlNode> orderByList = Expressions.list();
 for (RelFieldCollation field : aggCall.collation.getFieldCollations()) {
  addOrderItem(orderByList, field);
 }
 SqlNodeList orderList = new SqlNodeList(orderByList, POS);
 if (op instanceof SqlSumEmptyIsZeroAggFunction) {
  final SqlNode node =
    withOrder(
      SqlStdOperatorTable.SUM.createCall(qualifier, POS, operands),
      orderList);
  return SqlStdOperatorTable.COALESCE.createCall(POS, node,
    SqlLiteral.createExactNumeric("0", POS));
 } else {
  return withOrder(op.createCall(qualifier, POS, operands), orderList);
 }
}
origin: org.apache.calcite/calcite-core

/** @see #dispatch */
public Result visit(Project e) {
 Result x = visitChild(0, e.getInput());
 parseCorrelTable(e, x);
 if (isStar(e.getChildExps(), e.getInput().getRowType(), e.getRowType())) {
  return x;
 }
 final Builder builder =
   x.builder(e, Clause.SELECT);
 final List<SqlNode> selectList = new ArrayList<>();
 for (RexNode ref : e.getChildExps()) {
  SqlNode sqlExpr = builder.context.toSql(null, ref);
  addSelect(selectList, sqlExpr, e.getRowType());
 }
 builder.setSelect(new SqlNodeList(selectList, POS));
 return builder.result();
}
origin: org.apache.calcite/calcite-core

/** @see #dispatch */
public Result visit(Sort e) {
 Result x = visitChild(0, e.getInput());
 Builder builder = x.builder(e, Clause.ORDER_BY);
 List<SqlNode> orderByList = Expressions.list();
 for (RelFieldCollation field : e.getCollation().getFieldCollations()) {
  builder.addOrderItem(orderByList, field);
 }
 if (!orderByList.isEmpty()) {
  builder.setOrderBy(new SqlNodeList(orderByList, POS));
  x = builder.result();
 }
 if (e.fetch != null) {
  builder = x.builder(e, Clause.FETCH);
  builder.setFetch(builder.context.toSql(null, e.fetch));
  x = builder.result();
 }
 if (e.offset != null) {
  builder = x.builder(e, Clause.OFFSET);
  builder.setOffset(builder.context.toSql(null, e.offset));
  x = builder.result();
 }
 return x;
}
origin: org.apache.calcite/calcite-core

public SqlNode get(int index) {
 return field(index);
}
origin: org.apache.calcite/calcite-core

/** @see #dispatch */
public Result visit(Filter e) {
 final RelNode input = e.getInput();
 Result x = visitChild(0, input);
 parseCorrelTable(e, x);
 if (input instanceof Aggregate) {
  final Builder builder;
  if (((Aggregate) input).getInput() instanceof Project) {
   builder = x.builder(e);
   builder.clauses.add(Clause.HAVING);
  } else {
   builder = x.builder(e, Clause.HAVING);
  }
  builder.setHaving(builder.context.toSql(null, e.getCondition()));
  return builder.result();
 } else {
  final Builder builder = x.builder(e, Clause.WHERE);
  builder.setWhere(builder.context.toSql(null, e.getCondition()));
  return builder.result();
 }
}
origin: org.apache.calcite/calcite-core

public void addOrderItem(List<SqlNode> orderByList,
  RelFieldCollation field) {
 context.addOrderItem(orderByList, field);
}
origin: Qihoo360/Quicksql

/** @see #dispatch */
public Result visit(Calc e) {
 Result x = visitChild(0, e.getInput());
 parseCorrelTable(e, x);
 final RexProgram program = e.getProgram();
 Builder builder =
   program.getCondition() != null
     ? x.builder(e, Clause.WHERE)
     : x.builder(e);
 if (!isStar(program)) {
  final List<SqlNode> selectList = new ArrayList<>();
  for (RexLocalRef ref : program.getProjectList()) {
   SqlNode sqlExpr = builder.context.toSql(program, ref);
   addSelect(selectList, sqlExpr, e.getRowType());
  }
  builder.setSelect(new SqlNodeList(selectList, POS));
 }
 if (program.getCondition() != null) {
  builder.setWhere(
    builder.context.toSql(program, program.getCondition()));
 }
 return builder.result();
}
origin: Qihoo360/Quicksql

public SqlNode get(int index) {
 return field(index);
}
org.apache.calcite.rel.rel2sqlSqlImplementor$Context

Javadoc

Context for translating a RexNode expression (within a RelNode) into a SqlNode expression (within a SQL parse tree).

Most used methods

  • toSql
  • createLeftCall
  • createSqlWindowBound
  • field
  • implementor
  • addOrderItem
  • createOverCall
  • getAliasContext
  • withOrder
    Wraps a call in a SqlKind#WITHIN_GROUP call, if orderList is non-empty.

Popular in Java

  • Making http post requests using okhttp
  • getSystemService (Context)
  • onCreateOptionsMenu (Activity)
  • addToBackStack (FragmentTransaction)
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • ArrayList (java.util)
    Resizable-array implementation of the List interface. Implements all optional list operations, and p
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • SortedSet (java.util)
    A Set that further provides a total ordering on its elements. The elements are ordered using their C
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now