Tabnine Logo
SqlDialect
Code IndexAdd Tabnine to your IDE (free)

How to use
SqlDialect
in
org.apache.calcite.sql

Best Java code snippets using org.apache.calcite.sql.SqlDialect (Showing top 20 results out of 315)

origin: apache/kylin

public String convertSql(String orig) {
  // for jdbc source, convert quote from backtick to double quote
  String converted = orig.replaceAll("`", "\"");
  if (!configurer.skipHandleDefault()) {
    String escapedDefault = SqlDialect.CALCITE
        .quoteIdentifier(configurer.useUppercaseDefault() ? "DEFAULT" : "default");
    converted = converted.replaceAll("(?i)default\\.", escapedDefault + "."); // use Calcite dialect to cater to SqlParser
    converted = converted.replaceAll("\"(?i)default\"\\.", escapedDefault + ".");
  }
  if (!configurer.skipDefaultConvert()) {
    try {
      SqlNode sqlNode = SqlParser.create(converted).parseQuery();
      sqlNode = sqlNode.accept(sqlNodeConverter);
      converted = sqlWriter.format(sqlNode);
    } catch (Throwable e) {
      logger.error("Failed to default convert sql, will use the input: {}", orig, e);
    } finally {
      sqlWriter.reset();
    }
  }
  converted = configurer.fixAfterDefaultConvert(converted);
  return converted;
}
origin: apache/hive

@Override
public boolean matches(RelOptRuleCall call) {
 final HiveAggregate agg = call.rel(0);
 final HiveJdbcConverter converter = call.rel(1);
 for (AggregateCall relOptRuleOperand : agg.getAggCallList()) {
  SqlAggFunction f = relOptRuleOperand.getAggregation();
  if (f instanceof HiveSqlCountAggFunction) {
   //count distinct with more that one argument is not supported
   HiveSqlCountAggFunction countAgg = (HiveSqlCountAggFunction)f;
   if (countAgg.isDistinct() && 1 < relOptRuleOperand.getArgList().size()) {
    return false;
   }
  }
  SqlKind kind = f.getKind();
  if (!converter.getJdbcDialect().supportsAggregateFunction(kind)) {
   return false;
  }
 }
 return true;
}
origin: org.apache.calcite/calcite-core

 @Override public void unparseCall(SqlWriter writer, SqlCall call,
   int leftPrec, int rightPrec) {
  if (call instanceof SqlSelect) {
   callsUnparseCallOnSqlSelect[0] = true;
  }
  super.unparseCall(writer, call, leftPrec, rightPrec);
 }
};
origin: Qihoo360/Quicksql

 public String toString() {
  return "SUBSTITUTE("
    + CalciteSqlDialect.DEFAULT.quoteStringLiteral(name)
    + ")";
 }
}
origin: Qihoo360/Quicksql

public void identifier(String name) {
 String qName = name;
 if (isQuoteAllIdentifiers()
   || dialect.identifierNeedsToBeQuoted(name)) {
  qName = dialect.quoteIdentifier(name);
 }
 maybeWhitespace(qName);
 pw.print(qName);
 charCount += qName.length();
 setNeedWhitespace(true);
}
origin: qubole/quark

private SqlNode toSql(RelDataType type) {
 switch (dialect.getDatabaseProduct()) {
  case MYSQL:
   switch (type.getSqlTypeName()) {
    case VARCHAR:
     // MySQL doesn't have a VARCHAR type, only CHAR.
     return new SqlDataTypeSpec(new SqlIdentifier("CHAR", POS),
       type.getPrecision(), -1, null, null, POS);
    case INTEGER:
     return new SqlDataTypeSpec(new SqlIdentifier("_UNSIGNED", POS),
       type.getPrecision(), -1, null, null, POS);
   }
   break;
 }
 if (type instanceof BasicSqlType) {
  return new SqlDataTypeSpec(
    new SqlIdentifier(type.getSqlTypeName().name(), POS),
    type.getPrecision(),
    type.getScale(),
    type.getCharset() != null
      && dialect.supportsCharSet()
      ? type.getCharset().name()
      : null,
    null,
    POS);
 }
 return SqlTypeUtil.convertTypeToSpec(type);
 //throw new AssertionError(type); // TODO: implement
}
origin: dremio/dremio-oss

final String viewSql = createView.getQuery().toSqlString(new SqlDialect(SqlDialect.CALCITE.getDatabaseProduct(), SqlDialect.CALCITE.getDatabaseProduct().name(), ParserConfig.QUOTING.string)).getSql();
final ConvertedRelNode convertedRelNode = PrelTransformer.validateAndConvert(config, createView.getQuery());
final RelDataType validatedRowType = convertedRelNode.getValidatedRowType();
origin: org.apache.calcite/calcite-core

/**
 * Converts a string into a string literal. For example, <code>can't
 * run</code> becomes <code>'can''t run'</code>.
 */
public String quoteStringLiteral(String val) {
 if (containsNonAscii(val)) {
  final StringBuilder buf = new StringBuilder();
  quoteStringLiteralUnicode(buf, val);
  return buf.toString();
 } else {
  val = FakeUtil.replace(val, "'", "''");
  return "'" + val + "'";
 }
}
origin: org.apache.calcite/calcite-core

public SqlNode getCastSpec(RelDataType type) {
 if (type instanceof BasicSqlType) {
  int precision = type.getPrecision();
  switch (type.getSqlTypeName()) {
  case VARCHAR:
   // if needed, adjust varchar length to max length supported by the system
   int maxPrecision = getTypeSystem().getMaxPrecision(type.getSqlTypeName());
   if (type.getPrecision() > maxPrecision) {
    precision = maxPrecision;
   }
  }
  return new SqlDataTypeSpec(
    new SqlIdentifier(type.getSqlTypeName().name(), SqlParserPos.ZERO),
      precision,
      type.getScale(),
      type.getCharset() != null
        && supportsCharSet()
        ? type.getCharset().name()
        : null,
      null,
      SqlParserPos.ZERO);
 }
 return SqlTypeUtil.convertTypeToSpec(type);
}
origin: org.apache.calcite/calcite-core

DatabaseProduct(String databaseProductName, String quoteString,
  NullCollation nullCollation) {
 Objects.requireNonNull(databaseProductName);
 Objects.requireNonNull(nullCollation);
 dialect = Suppliers.memoize(() -> {
  final SqlDialect dialect =
    SqlDialectFactoryImpl.simple(DatabaseProduct.this);
  if (dialect != null) {
   return dialect;
  }
  return new SqlDialect(SqlDialect.EMPTY_CONTEXT
    .withDatabaseProduct(DatabaseProduct.this)
    .withDatabaseProductName(databaseProductName)
    .withIdentifierQuoteString(quoteString)
    .withNullCollation(nullCollation));
 })::get;
}
origin: Qihoo360/Quicksql

public SqlNode getCastSpec(RelDataType type) {
 if (type instanceof BasicSqlType) {
  return new SqlDataTypeSpec(
    new SqlIdentifier(type.getSqlTypeName().name(), SqlParserPos.ZERO),
      type.getPrecision(),
      type.getScale(),
      type.getCharset() != null
        && supportsCharSet()
        ? type.getCharset().name()
        : null,
      null,
      SqlParserPos.ZERO);
 }
 return SqlTypeUtil.convertTypeToSpec(type);
}
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 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 unparse(
  SqlWriter writer,
  SqlCall call,
  int leftPrec,
  int rightPrec) {
 assert call.operandCount() >= 2;
 final SqlWriter.Frame frame =
   writer.startList(
     SqlWriter.FrameTypeEnum.SIMPLE);
 call.operand(0).unparse(writer, leftPrec, getLeftPrec());
 final boolean needsSpace = true;
 writer.setNeedWhitespace(needsSpace);
 if (writer.getDialect().allowsAs()) {
  writer.sep("AS");
  writer.setNeedWhitespace(needsSpace);
 }
 call.operand(1).unparse(writer, getRightPrec(), rightPrec);
 if (call.operandCount() > 2) {
  final SqlWriter.Frame frame1 =
    writer.startList(SqlWriter.FrameTypeEnum.SIMPLE, "(", ")");
  for (SqlNode operand : Util.skip(call.getOperandList(), 2)) {
   writer.sep(",", false);
   operand.unparse(writer, 0, 0);
  }
  writer.endList(frame1);
 }
 writer.endList(frame);
}
origin: Qihoo360/Quicksql

 @Override public void unparseCall(SqlWriter writer, SqlCall call,
   int leftPrec, int rightPrec) {
  if (call instanceof SqlSelect) {
   callsUnparseCallOnSqlSelect[0] = true;
  }
  super.unparseCall(writer, call, leftPrec, rightPrec);
 }
};
origin: org.apache.calcite/calcite-core

 public String toString() {
  return "SUBSTITUTE("
    + CalciteSqlDialect.DEFAULT.quoteStringLiteral(name)
    + ")";
 }
}
origin: org.apache.calcite/calcite-core

public void identifier(String name) {
 String qName = name;
 if (isQuoteAllIdentifiers()
   || dialect.identifierNeedsToBeQuoted(name)) {
  qName = dialect.quoteIdentifier(name);
 }
 maybeWhitespace(qName);
 pw.print(qName);
 charCount += qName.length();
 setNeedWhitespace(true);
}
origin: Qihoo360/Quicksql

/**
 * Converts a string into a string literal. For example, <code>can't
 * run</code> becomes <code>'can''t run'</code>.
 */
public String quoteStringLiteral(String val) {
 if (containsNonAscii(val)) {
  final StringBuilder buf = new StringBuilder();
  quoteStringLiteralUnicode(buf, val);
  return buf.toString();
 } else {
  val = FakeUtil.replace(val, "'", "''");
  return "'" + val + "'";
 }
}
origin: Qihoo360/Quicksql

DatabaseProduct(String databaseProductName, String quoteString,
  NullCollation nullCollation) {
 Objects.requireNonNull(databaseProductName);
 Objects.requireNonNull(nullCollation);
 dialect = Suppliers.memoize(() -> {
  final SqlDialect dialect =
    SqlDialectFactoryImpl.simple(DatabaseProduct.this);
  if (dialect != null) {
   return dialect;
  }
  return new SqlDialect(SqlDialect.EMPTY_CONTEXT
    .withDatabaseProduct(DatabaseProduct.this)
    .withDatabaseProductName(databaseProductName)
    .withIdentifierQuoteString(quoteString)
    .withNullCollation(nullCollation));
 })::get;
}
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));
}
org.apache.calcite.sqlSqlDialect

Javadoc

SqlDialect encapsulates the differences between dialects of SQL.

It is used by classes such as SqlWriter and org.apache.calcite.sql.util.SqlBuilder.

Most used methods

  • quoteStringLiteral
    Converts a string into a string literal. For example, can't run becomes 'can''t run'.
  • unparseCall
  • <init>
    Creates a SqlDialect.
  • quoteIdentifier
    Quotes a multi-part identifier.
  • supportsAggregateFunction
  • supportsCharSet
    Returns whether the dialect supports character set names as part of a data type, for instance VARCHA
  • allowsAs
  • containsNonAscii
    Returns whether the string contains any characters outside the comfortable 7-bit ASCII range (32 thr
  • defaultNullDirection
    Returns whether NULL values are sorted first or last, in this dialect, in an ORDER BY item of a give
  • emulateNullDirection
    Returns the SqlNode for emulating the null direction for the given field or null if no emulation ne
  • getCalendarPolicy
  • getCastSpec
  • getCalendarPolicy,
  • getCastSpec,
  • getDatabaseProduct,
  • getNullCollation,
  • hasImplicitTableAlias,
  • identifierNeedsToBeQuoted,
  • quoteStringLiteralUnicode,
  • quoteTimestampLiteral,
  • rewriteSingleValueExpr,
  • supportsAliasedValues

Popular in Java

  • Updating database using SQL prepared statement
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • startActivity (Activity)
  • getExternalFilesDir (Context)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • JLabel (javax.swing)
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now