国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

Apache Calcite 實(shí)現方言轉換的代碼

發(fā)布時(shí)間:2021-08-15 18:37 來(lái)源: 閱讀:0 作者:Nobi 欄目: 服務(wù)器 歡迎投稿:712375056

定義

Calcite能夠通過(guò)解析Sql為SqlNode,再將SqlNode轉化為特定數據的方言的形式實(shí)現Sql的統一。

實(shí)現

在Calcite中實(shí)現方言轉換的主要類(lèi)是SqlDialect基類(lèi),其具體的變量含義如下:

public class SqlDialect {

BUILT_IN_OPERATORS_LIST: 支持的內置定義函數或者運算符(例如:abs and..)

// 列 表的標識符
String identifierQuoteString:    標識符的開(kāi)始符號
String identifierEndQuoteString: 標識符的結束符號
String identifierEscapedQuote: (暫時(shí)沒(méi)有弄明白這個(gè)在做什么,像是字符串中的轉義符?)

// 常量的標識符
String literalQuoteString:    常量的開(kāi)始符號
String literalEndQuoteString: 常量的結束符號
String literalEscapedQuote:(暫時(shí)沒(méi)有弄明白這個(gè)在做什么,像是字符串中的轉義符?)

DatabaseProduct databaseProduct: 所屬的數據庫產(chǎn)品
NullCollation nullCollation: 在進(jìn)行排序查詢(xún)式,空值的返回順序
RelDataTypeSystem dataTypeSystem: 數據類(lèi)型

// 和解析相關(guān)
Casing unquotedCasing: 大小寫(xiě)轉換
Casing quotedCasing: 大小寫(xiě)轉換
boolean caseSensitive: 是否大小寫(xiě)敏感(列名 表明 函數名等)
}
// 方法區(不同的數據源根據細節的不同實(shí)現自定義的復寫(xiě)方法)
allowsAs
configureParser
configureParser
containsNonAscii
create
defaultNullDirection
emptyContext
emulateJoinTypeForCrossJoin
emulateNullDirection
emulateNullDirectionWithIsNull
getCalendarPolicy
getCastSpec
getConformance
getDatabaseProduct
getNullCollation
getProduct
getQuotedCasing
getQuoting
getSingleRowTableName
getTypeSystem
getUnquotedCasing
hasImplicitTableAlias
identifierNeedsQuote
isCaseSensitive
quoteIdentifier
quoteIdentifier
quoteIdentifier
quoteStringLiteral
quoteStringLiteral
quoteStringLiteralUnicode
quoteTimestampLiteral
requiresAliasForFromItems
rewriteSingleValueExpr
supportsAggregateFunction
supportsAliasedValues
supportsCharSet
supportsDataType
supportsFunction
supportsGroupByWithCube
supportsGroupByWithRollup
supportsImplicitTypeCoercion
supportsNestedAggregations
supportsOffsetFetch
supportsWindowFunctions
unparseCall
unparseDateTimeLiteral
unparseFetchUsingAnsi
unparseFetchUsingLimit
unparseLimit
unparseOffset
unparseOffsetFetch
unparseSqlDatetimeArithmetic
unparseSqlIntervalLiteral
unparseSqlIntervalQualifier
unparseTopN
unquoteStringLiteral

使用方式Demo

/** Returns SqlNode for type in "cast(column as type)", which might be
  * different between databases by type name, precision etc.
  *
  * <p>If this method returns null, the cast will be omitted. In the default
  * implementation, this is the case for the NULL type, and therefore
  * {@code CAST(NULL AS <nulltype>)} is rendered as {@code NULL}. */
  public SqlNode getCastSpec(RelDataType type)

  這個(gè)方法就可以根據具體的數據源的數據類(lèi)型進(jìn)行轉換,例如:

  @Override public SqlNode getCastSpec(RelDataType type) {
    switch (type.getSqlTypeName()) {
    case VARCHAR:
      // MySQL doesn't have a VARCHAR type, only CHAR.
      int vcMaxPrecision = this.getTypeSystem().getMaxPrecision(SqlTypeName.CHAR);
      int precision = type.getPrecision();
      if (vcMaxPrecision > 0 && precision > vcMaxPrecision) {
        precision = vcMaxPrecision;
      }
      return new SqlDataTypeSpec(
          new SqlBasicTypeNameSpec(SqlTypeName.CHAR, precision, SqlParserPos.ZERO),
          SqlParserPos.ZERO);
    }
    return super.getCastSpec(type);
  }

  就可以經(jīng)Sql中的Cast語(yǔ)句Cast為特定的類(lèi)型:

  final String query = "select cast(\"product_id\" as varchar(50)), \"product_id\" "
       + "from \"product\" ";
   final String expected = "SELECT CAST(`product_id` AS CHAR(50)), `product_id`\n"
       + "FROM `foodmart`.`product`";
// 解析過(guò)的SqlNode
sqlNode.toSqlString(CalciteSqlDialect.DEFAULT).getSql();

到此這篇關(guān)于A(yíng)pache Calcite 實(shí)現方言轉換的代碼的文章就介紹到這了,更多相關(guān)Apache Calcite方言轉換內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。

欧美牲交A欧美牲交| 亚洲AV成人综合网伊人APP| 中国丰满熟妇XXXX| 鲁丝片一区二区三区免费| GAY男同GV网站播放免费| 特黄大片AAAAA毛片|