五月综合激情婷婷六月,日韩欧美国产一区不卡,他扒开我内裤强吻我下面视频 ,无套内射无矿码免费看黄,天天躁,日日躁,狠狠躁

新聞動態(tài)

Apache Calcite 實現(xiàn)方言轉(zhuǎn)換的代碼

發(fā)布日期:2021-12-21 16:59 | 文章來源:源碼中國

定義

Calcite能夠通過解析Sql為SqlNode,再將SqlNode轉(zhuǎn)化為特定數(shù)據(jù)庫的方言的形式實現(xiàn)Sql的統(tǒng)一。

實現(xiàn)

在Calcite中實現(xiàn)方言轉(zhuǎn)換的主要類是SqlDialect基類,其具體的變量含義如下:

public class SqlDialect {
BUILT_IN_OPERATORS_LIST: 支持的內(nèi)置定義函數(shù)或者運算符(例如:abs and..)
// 列 表的標(biāo)識符
String identifierQuoteString:    標(biāo)識符的開始符號
String identifierEndQuoteString: 標(biāo)識符的結(jié)束符號
String identifierEscapedQuote: (暫時沒有弄明白這個在做什么,像是字符串中的轉(zhuǎn)義符?)
// 常量的標(biāo)識符
String literalQuoteString:    常量的開始符號
String literalEndQuoteString: 常量的結(jié)束符號
String literalEscapedQuote:(暫時沒有弄明白這個在做什么,像是字符串中的轉(zhuǎn)義符?)
DatabaseProduct databaseProduct: 所屬的數(shù)據(jù)庫產(chǎn)品
NullCollation nullCollation: 在進行排序查詢式,空值的返回順序
RelDataTypeSystem dataTypeSystem: 數(shù)據(jù)類型
// 和解析相關(guān)
Casing unquotedCasing: 大小寫轉(zhuǎn)換
Casing quotedCasing: 大小寫轉(zhuǎn)換
boolean caseSensitive: 是否大小寫敏感(列名 表明 函數(shù)名等)
}
// 方法區(qū)(不同的數(shù)據(jù)源根據(jù)細節(jié)的不同實現(xiàn)自定義的復(fù)寫方法)
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)
  這個方法就可以根據(jù)具體的數(shù)據(jù)源的數(shù)據(jù)類型進行轉(zhuǎ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語句Cast為特定的類型:
  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`";
// 解析過的SqlNode
sqlNode.toSqlString(CalciteSqlDialect.DEFAULT).getSql();

到此這篇關(guān)于Apache Calcite 實現(xiàn)方言轉(zhuǎn)換的代碼的文章就介紹到這了,更多相關(guān)Apache Calcite方言轉(zhuǎn)換內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

實時開通

自選配置、實時開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時在線

客服
熱線

400-630-3752
7*24小時客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部