org.apache.calcite.config.NullCollation Java Examples

The following examples show how to use org.apache.calcite.config.NullCollation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SqlToRelConverterTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-2323">[CALCITE-2323]
 * Validator should allow alternative nullCollations for ORDER BY in
 * OVER</a>. */
@Test void testUserDefinedOrderByOver() {
  String sql = "select deptno,\n"
      + "  rank() over(partition by empno order by deptno)\n"
      + "from emp\n"
      + "order by row_number() over(partition by empno order by deptno)";
  Properties properties = new Properties();
  properties.setProperty(
      CalciteConnectionProperty.DEFAULT_NULL_COLLATION.camelName(),
      NullCollation.LOW.name());
  CalciteConnectionConfigImpl connectionConfig =
      new CalciteConnectionConfigImpl(properties);
  TesterImpl tester = new TesterImpl(getDiffRepos(), false, false, true, false, true,
      null, null, SqlToRelConverter.Config.DEFAULT,
      SqlConformanceEnum.DEFAULT, Contexts.of(connectionConfig));
  sql(sql).with(tester).ok();
}
 
Example #2
Source File: SqlDialectFactoryImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
private NullCollation getNullCollation(DatabaseMetaData databaseMetaData) {
  try {
    if (databaseMetaData.nullsAreSortedAtEnd()) {
      return NullCollation.LAST;
    } else if (databaseMetaData.nullsAreSortedAtStart()) {
      return NullCollation.FIRST;
    } else if (databaseMetaData.nullsAreSortedLow()) {
      return NullCollation.LOW;
    } else if (databaseMetaData.nullsAreSortedHigh()) {
      return NullCollation.HIGH;
    } else if (isBigQuery(databaseMetaData)) {
      return NullCollation.LOW;
    } else {
      throw new IllegalArgumentException("cannot deduce null collation");
    }
  } catch (SQLException e) {
    throw new IllegalArgumentException("cannot deduce null collation", e);
  }
}
 
Example #3
Source File: SqlDialect.java    From Bats with Apache License 2.0 6 votes vote down vote up
private ContextImpl(DatabaseProduct databaseProduct,
    String databaseProductName, String databaseVersion,
    int databaseMajorVersion, int databaseMinorVersion,
    String identifierQuoteString, NullCollation nullCollation,
    RelDataTypeSystem dataTypeSystem,
    JethroDataSqlDialect.JethroInfo jethroInfo) {
  this.databaseProduct = Objects.requireNonNull(databaseProduct);
  this.databaseProductName = databaseProductName;
  this.databaseVersion = databaseVersion;
  this.databaseMajorVersion = databaseMajorVersion;
  this.databaseMinorVersion = databaseMinorVersion;
  this.identifierQuoteString = identifierQuoteString;
  this.nullCollation = Objects.requireNonNull(nullCollation);
  this.dataTypeSystem = Objects.requireNonNull(dataTypeSystem);
  this.jethroInfo = Objects.requireNonNull(jethroInfo);
}
 
Example #4
Source File: SqlDialect.java    From calcite with Apache License 2.0 6 votes vote down vote up
private ContextImpl(DatabaseProduct databaseProduct,
    String databaseProductName, String databaseVersion,
    int databaseMajorVersion, int databaseMinorVersion,
    String literalQuoteString, String literalEscapedQuoteString,
    String identifierQuoteString, Casing quotedCasing,
    Casing unquotedCasing, boolean caseSensitive,
    SqlConformance conformance, NullCollation nullCollation,
    RelDataTypeSystem dataTypeSystem,
    JethroDataSqlDialect.JethroInfo jethroInfo) {
  this.databaseProduct = Objects.requireNonNull(databaseProduct);
  this.databaseProductName = databaseProductName;
  this.databaseVersion = databaseVersion;
  this.databaseMajorVersion = databaseMajorVersion;
  this.databaseMinorVersion = databaseMinorVersion;
  this.literalQuoteString = literalQuoteString;
  this.literalEscapedQuoteString = literalEscapedQuoteString;
  this.identifierQuoteString = identifierQuoteString;
  this.quotedCasing = Objects.requireNonNull(quotedCasing);
  this.unquotedCasing = Objects.requireNonNull(unquotedCasing);
  this.caseSensitive = caseSensitive;
  this.conformance = Objects.requireNonNull(conformance);
  this.nullCollation = Objects.requireNonNull(nullCollation);
  this.dataTypeSystem = Objects.requireNonNull(dataTypeSystem);
  this.jethroInfo = Objects.requireNonNull(jethroInfo);
}
 
Example #5
Source File: SqlDialectFactoryImpl.java    From Bats with Apache License 2.0 6 votes vote down vote up
private NullCollation getNullCollation(DatabaseMetaData databaseMetaData) {
  try {
    if (databaseMetaData.nullsAreSortedAtEnd()) {
      return NullCollation.LAST;
    } else if (databaseMetaData.nullsAreSortedAtStart()) {
      return NullCollation.FIRST;
    } else if (databaseMetaData.nullsAreSortedLow()) {
      return NullCollation.LOW;
    } else if (databaseMetaData.nullsAreSortedHigh()) {
      return NullCollation.HIGH;
    } else {
      throw new IllegalArgumentException("cannot deduce null collation");
    }
  } catch (SQLException e) {
    throw new IllegalArgumentException("cannot deduce null collation", e);
  }
}
 
Example #6
Source File: SqlDialect.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Nonnull public Context withNullCollation(
    @Nonnull NullCollation nullCollation) {
  return new ContextImpl(databaseProduct, databaseProductName,
      databaseVersion, databaseMajorVersion, databaseMinorVersion,
      literalQuoteString, literalEscapedQuoteString,
      identifierQuoteString, quotedCasing, unquotedCasing, caseSensitive,
      conformance, nullCollation, dataTypeSystem, jethroInfo);
}
 
Example #7
Source File: SqlDialect.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates an empty context. Use {@link #EMPTY_CONTEXT} to reference the instance. */
private static Context emptyContext() {
  return new ContextImpl(DatabaseProduct.UNKNOWN, null, null, -1, -1,
      "'", "''", null,
      Casing.UNCHANGED, Casing.TO_UPPER, true, SqlConformanceEnum.DEFAULT,
      NullCollation.HIGH, RelDataTypeSystemImpl.DEFAULT,
      JethroDataSqlDialect.JethroInfo.EMPTY);
}
 
Example #8
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 4 votes vote down vote up
public void setDefaultNullCollation(NullCollation nullCollation) {
	this.nullCollation = Objects.requireNonNull(nullCollation);
}
 
Example #9
Source File: SqlValidator.java    From calcite with Apache License 2.0 4 votes vote down vote up
/** Returns how NULL values should be collated if an ORDER BY item does not
 * contain NULLS FIRST or NULLS LAST. */
@ImmutableBeans.Property
@ImmutableBeans.EnumDefault("HIGH")
NullCollation defaultNullCollation();
 
Example #10
Source File: SqlDialect.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Nonnull public NullCollation nullCollation() {
  return nullCollation;
}
 
Example #11
Source File: SqlDialect.java    From calcite with Apache License 2.0 4 votes vote down vote up
/** Returns how NULL values are sorted if an ORDER BY item does not contain
 * NULLS ASCENDING or NULLS DESCENDING. */
public NullCollation getNullCollation() {
  return nullCollation;
}
 
Example #12
Source File: DremioSqlDialect.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
protected DremioSqlDialect(String databaseProductName,
                           String identifierQuoteString,
                           NullCollation nullCollation) {
  super(getDbProduct(databaseProductName), databaseProductName, identifierQuoteString, nullCollation);
  this.databaseName = databaseProductName.toUpperCase(Locale.ROOT);
}
 
Example #13
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 4 votes vote down vote up
public NullCollation getDefaultNullCollation() {
	return nullCollation;
}
 
Example #14
Source File: SqlValidatorImpl.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public NullCollation getDefaultNullCollation() {
	return nullCollation;
}
 
Example #15
Source File: SqlValidatorImpl.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public void setDefaultNullCollation(NullCollation nullCollation) {
	this.nullCollation = Objects.requireNonNull(nullCollation);
}
 
Example #16
Source File: SqlDialectFactoryImpl.java    From Bats with Apache License 2.0 4 votes vote down vote up
public SqlDialect create(DatabaseMetaData databaseMetaData) {
  String databaseProductName;
  int databaseMajorVersion;
  int databaseMinorVersion;
  String databaseVersion;
  try {
    databaseProductName = databaseMetaData.getDatabaseProductName();
    databaseMajorVersion = databaseMetaData.getDatabaseMajorVersion();
    databaseMinorVersion = databaseMetaData.getDatabaseMinorVersion();
    databaseVersion = databaseMetaData.getDatabaseProductVersion();
  } catch (SQLException e) {
    throw new RuntimeException("while detecting database product", e);
  }
  final String upperProductName =
      databaseProductName.toUpperCase(Locale.ROOT).trim();
  final String quoteString = getIdentifierQuoteString(databaseMetaData);
  final NullCollation nullCollation = getNullCollation(databaseMetaData);
  final SqlDialect.Context c = SqlDialect.EMPTY_CONTEXT
      .withDatabaseProductName(databaseProductName)
      .withDatabaseMajorVersion(databaseMajorVersion)
      .withDatabaseMinorVersion(databaseMinorVersion)
      .withDatabaseVersion(databaseVersion)
      .withIdentifierQuoteString(quoteString)
      .withNullCollation(nullCollation);
  switch (upperProductName) {
  case "ACCESS":
    return new AccessSqlDialect(c);
  case "APACHE DERBY":
    return new DerbySqlDialect(c);
  case "DBMS:CLOUDSCAPE":
    return new DerbySqlDialect(c);
  case "HIVE":
    return new HiveSqlDialect(c);
  case "INGRES":
    return new IngresSqlDialect(c);
  case "INTERBASE":
    return new InterbaseSqlDialect(c);
  case "JETHRODATA":
    return new JethroDataSqlDialect(
        c.withJethroInfo(jethroCache.get(databaseMetaData)));
  case "LUCIDDB":
    return new LucidDbSqlDialect(c);
  case "ORACLE":
    return new OracleSqlDialect(c);
  case "PHOENIX":
    return new PhoenixSqlDialect(c);
  case "MYSQL (INFOBRIGHT)":
    return new InfobrightSqlDialect(c);
  case "MYSQL":
    return new MysqlSqlDialect(c);
  case "REDSHIFT":
    return new RedshiftSqlDialect(c);
  case "SPARK":
    return new SparkSqlDialect(c);
  }
  // Now the fuzzy matches.
  if (databaseProductName.startsWith("DB2")) {
    return new Db2SqlDialect(c);
  } else if (upperProductName.contains("FIREBIRD")) {
    return new FirebirdSqlDialect(c);
  } else if (databaseProductName.startsWith("Informix")) {
    return new InformixSqlDialect(c);
  } else if (upperProductName.contains("NETEZZA")) {
    return new NetezzaSqlDialect(c);
  } else if (upperProductName.contains("PARACCEL")) {
    return new ParaccelSqlDialect(c);
  } else if (databaseProductName.startsWith("HP Neoview")) {
    return new NeoviewSqlDialect(c);
  } else if (upperProductName.contains("POSTGRE")) {
    return new PostgresqlSqlDialect(c);
  } else if (upperProductName.contains("SQL SERVER")) {
    return new MssqlSqlDialect(c);
  } else if (upperProductName.contains("SYBASE")) {
    return new SybaseSqlDialect(c);
  } else if (upperProductName.contains("TERADATA")) {
    return new TeradataSqlDialect(c);
  } else if (upperProductName.contains("HSQL")) {
    return new HsqldbSqlDialect(c);
  } else if (upperProductName.contains("H2")) {
    return new H2SqlDialect(c);
  } else if (upperProductName.contains("VERTICA")) {
    return new VerticaSqlDialect(c);
  } else if (upperProductName.contains("SPARK")) {
    return new SparkSqlDialect(c);
  } else {
    return new AnsiSqlDialect(c);
  }
}
 
Example #17
Source File: SqlDialect.java    From Bats with Apache License 2.0 4 votes vote down vote up
public Context withNullCollation(NullCollation nullCollation) {
  return new ContextImpl(databaseProduct, databaseProductName,
      databaseVersion, databaseMajorVersion, databaseMinorVersion,
      identifierQuoteString, nullCollation, dataTypeSystem, jethroInfo);
}
 
Example #18
Source File: SqlDialect.java    From Bats with Apache License 2.0 4 votes vote down vote up
public NullCollation nullCollation() {
  return nullCollation;
}
 
Example #19
Source File: SqlDialect.java    From Bats with Apache License 2.0 4 votes vote down vote up
/** Returns how NULL values are sorted if an ORDER BY item does not contain
 * NULLS ASCENDING or NULLS DESCENDING. */
public NullCollation getNullCollation() {
  return nullCollation;
}
 
Example #20
Source File: SqlDialect.java    From Bats with Apache License 2.0 4 votes vote down vote up
/** Creates an empty context. Use {@link #EMPTY_CONTEXT} if possible. */
protected static Context emptyContext() {
  return new ContextImpl(DatabaseProduct.UNKNOWN, null, null, -1, -1, null,
      NullCollation.HIGH, RelDataTypeSystemImpl.DEFAULT, JethroDataSqlDialect.JethroInfo.EMPTY);
}
 
Example #21
Source File: SqlDialect.java    From Bats with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a SqlDialect.
 *
 * @param databaseProduct       Database product; may be UNKNOWN, never null
 * @param databaseProductName   Database product name from JDBC driver
 * @param identifierQuoteString String to quote identifiers. Null if quoting
 *                              is not supported. If "[", close quote is
 *                              deemed to be "]".
 * @param nullCollation         Whether NULL values appear first or last
 *
 * @deprecated Use {@link #SqlDialect(Context)}
 */
@Deprecated // to be removed before 2.0
public SqlDialect(DatabaseProduct databaseProduct, String databaseProductName,
    String identifierQuoteString, NullCollation nullCollation) {
  this(EMPTY_CONTEXT
      .withDatabaseProduct(databaseProduct)
      .withDatabaseProductName(databaseProductName)
      .withIdentifierQuoteString(identifierQuoteString)
      .withNullCollation(nullCollation));
}
 
Example #22
Source File: SqlDialect.java    From calcite with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a SqlDialect.
 *
 * @param databaseProduct       Database product; may be UNKNOWN, never null
 * @param databaseProductName   Database product name from JDBC driver
 * @param identifierQuoteString String to quote identifiers. Null if quoting
 *                              is not supported. If "[", close quote is
 *                              deemed to be "]".
 * @param nullCollation         Whether NULL values appear first or last
 *
 * @deprecated Use {@link #SqlDialect(Context)}
 */
@Deprecated // to be removed before 2.0
public SqlDialect(DatabaseProduct databaseProduct, String databaseProductName,
    String identifierQuoteString, NullCollation nullCollation) {
  this(EMPTY_CONTEXT
      .withDatabaseProduct(databaseProduct)
      .withDatabaseProductName(databaseProductName)
      .withIdentifierQuoteString(identifierQuoteString)
      .withNullCollation(nullCollation));
}
 
Example #23
Source File: SqlValidator.java    From Bats with Apache License 2.0 2 votes vote down vote up
/** Returns how NULL values should be collated if an ORDER BY item does not
 * contain NULLS FIRST or NULLS LAST. */
NullCollation getDefaultNullCollation();
 
Example #24
Source File: SqlValidator.java    From Bats with Apache License 2.0 2 votes vote down vote up
/** Sets how NULL values should be collated if an ORDER BY item does not
 * contain NULLS FIRST or NULLS LAST. */
void setDefaultNullCollation(NullCollation nullCollation);
 
Example #25
Source File: SqlValidator.java    From calcite with Apache License 2.0 2 votes vote down vote up
/** Sets how NULL values should be collated if an ORDER BY item does not
 * contain NULLS FIRST or NULLS LAST. */
Config withDefaultNullCollation(NullCollation nullCollation);
 
Example #26
Source File: SqlDialect.java    From calcite with Apache License 2.0 votes vote down vote up
@Nonnull NullCollation nullCollation(); 
Example #27
Source File: SqlDialect.java    From calcite with Apache License 2.0 votes vote down vote up
@Nonnull Context withNullCollation(@Nonnull NullCollation nullCollation); 
Example #28
Source File: SqlDialect.java    From Bats with Apache License 2.0 votes vote down vote up
Context withNullCollation(NullCollation nullCollation); 
Example #29
Source File: SqlDialect.java    From Bats with Apache License 2.0 votes vote down vote up
NullCollation nullCollation();