add some comments and two missing function registrations

This commit is contained in:
Gavin King 2022-09-17 11:25:27 +02:00
parent 7740121449
commit b6011ca9c8
4 changed files with 21 additions and 6 deletions

View File

@ -350,6 +350,7 @@ public abstract class AbstractHANADialect extends Dialect {
functionFactory.sinh(); functionFactory.sinh();
functionFactory.tanh(); functionFactory.tanh();
functionFactory.log10_log(); functionFactory.log10_log();
functionFactory.log();
functionFactory.bitand(); functionFactory.bitand();
functionFactory.hourMinuteSecond(); functionFactory.hourMinuteSecond();
functionFactory.yearMonthDay(); functionFactory.yearMonthDay();

View File

@ -16,7 +16,6 @@ import org.hibernate.dialect.function.CaseLeastGreatestEmulation;
import org.hibernate.dialect.function.InsertSubstringOverlayEmulation; import org.hibernate.dialect.function.InsertSubstringOverlayEmulation;
import org.hibernate.dialect.identity.DB2IdentityColumnSupport; import org.hibernate.dialect.identity.DB2IdentityColumnSupport;
import org.hibernate.dialect.identity.IdentityColumnSupport; import org.hibernate.dialect.identity.IdentityColumnSupport;
import org.hibernate.dialect.pagination.AbstractLimitHandler;
import org.hibernate.dialect.pagination.DerbyLimitHandler; import org.hibernate.dialect.pagination.DerbyLimitHandler;
import org.hibernate.dialect.pagination.LimitHandler; import org.hibernate.dialect.pagination.LimitHandler;
import org.hibernate.dialect.sequence.DerbySequenceSupport; import org.hibernate.dialect.sequence.DerbySequenceSupport;
@ -51,7 +50,6 @@ import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory;
import org.hibernate.sql.ast.tree.Statement; import org.hibernate.sql.ast.tree.Statement;
import org.hibernate.sql.exec.spi.JdbcOperation; import org.hibernate.sql.exec.spi.JdbcOperation;
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorDerbyDatabaseImpl; import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorDerbyDatabaseImpl;
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNoOpImpl;
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
import org.hibernate.type.BasicType; import org.hibernate.type.BasicType;
import org.hibernate.type.BasicTypeRegistry; import org.hibernate.type.BasicTypeRegistry;
@ -60,7 +58,6 @@ import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.descriptor.java.BigDecimalJavaType; import org.hibernate.type.descriptor.java.BigDecimalJavaType;
import org.hibernate.type.descriptor.jdbc.DecimalJdbcType; import org.hibernate.type.descriptor.jdbc.DecimalJdbcType;
import org.hibernate.type.descriptor.jdbc.ObjectNullResolvingJdbcType; import org.hibernate.type.descriptor.jdbc.ObjectNullResolvingJdbcType;
import org.hibernate.type.descriptor.jdbc.SmallIntJdbcType;
import org.hibernate.type.descriptor.jdbc.TimestampJdbcType; import org.hibernate.type.descriptor.jdbc.TimestampJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry; import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.type.descriptor.sql.internal.CapacityDependentDdlType; import org.hibernate.type.descriptor.sql.internal.CapacityDependentDdlType;
@ -254,6 +251,10 @@ public class DerbyDialect extends Dialect {
// AVG by default uses the input type, so we possibly need to cast the argument type, hence a special function // AVG by default uses the input type, so we possibly need to cast the argument type, hence a special function
functionFactory.avg_castingNonDoubleArguments( this, SqlAstNodeRenderingMode.DEFAULT ); functionFactory.avg_castingNonDoubleArguments( this, SqlAstNodeRenderingMode.DEFAULT );
// Note that Derby does not have chr() / ascii() functions.
// It does have a function named char(), but it's really a
// sort of to_char() function.
functionFactory.concat_pipeOperator(); functionFactory.concat_pipeOperator();
functionFactory.cot(); functionFactory.cot();
functionFactory.degrees(); functionFactory.degrees();

View File

@ -46,6 +46,7 @@ import org.hibernate.query.sqm.IntervalType;
import org.hibernate.query.sqm.NullOrdering; import org.hibernate.query.sqm.NullOrdering;
import org.hibernate.query.sqm.TemporalUnit; import org.hibernate.query.sqm.TemporalUnit;
import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
import org.hibernate.query.sqm.mutation.internal.temptable.AfterUseAction; import org.hibernate.query.sqm.mutation.internal.temptable.AfterUseAction;
import org.hibernate.dialect.temptable.TemporaryTable; import org.hibernate.dialect.temptable.TemporaryTable;
import org.hibernate.query.sqm.mutation.internal.temptable.BeforeUseAction; import org.hibernate.query.sqm.mutation.internal.temptable.BeforeUseAction;
@ -492,22 +493,28 @@ public class MySQLDialect extends Dialect {
BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry();
queryEngine.getSqmFunctionRegistry().noArgsBuilder( "localtime" ) SqmFunctionRegistry functionRegistry = queryEngine.getSqmFunctionRegistry();
functionRegistry.noArgsBuilder( "localtime" )
.setInvariantType(basicTypeRegistry.resolve( StandardBasicTypes.TIMESTAMP )) .setInvariantType(basicTypeRegistry.resolve( StandardBasicTypes.TIMESTAMP ))
.setUseParenthesesWhenNoArgs( false ) .setUseParenthesesWhenNoArgs( false )
.register(); .register();
queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "pi", "cast(pi() as double)" ) // pi() produces a value with 7 digits unless we're explicit
functionRegistry.patternDescriptorBuilder( "pi", "cast(pi() as double)" )
.setInvariantType(basicTypeRegistry.resolve( StandardBasicTypes.DOUBLE )) .setInvariantType(basicTypeRegistry.resolve( StandardBasicTypes.DOUBLE ))
.setExactArgumentCount(0) .setExactArgumentCount(0)
.setArgumentListSignature("") .setArgumentListSignature("")
.register(); .register();
queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "chr", "char(?1 using ascii)" ) // By default char() produces a binary string, not a character string.
// (Note also that char() is actually a variadic function in MySQL.)
functionRegistry.patternDescriptorBuilder( "chr", "char(?1 using ascii)" )
.setInvariantType(basicTypeRegistry.resolve( StandardBasicTypes.CHARACTER )) .setInvariantType(basicTypeRegistry.resolve( StandardBasicTypes.CHARACTER ))
.setExactArgumentCount(1) .setExactArgumentCount(1)
.setParameterTypes(FunctionParameterType.INTEGER) .setParameterTypes(FunctionParameterType.INTEGER)
.register(); .register();
functionRegistry.registerAlternateKey( "char", "chr" );
// MySQL timestamp type defaults to precision 0 (seconds) but // MySQL timestamp type defaults to precision 0 (seconds) but
// we want the standard default precision of 6 (microseconds) // we want the standard default precision of 6 (microseconds)

View File

@ -1696,6 +1696,12 @@ public class CommonFunctionFactory {
.register(); .register();
} }
/**
* Very widely supported, but we don't treat this as a "standard"
* function because it's hard to emulate on any database that
* doesn't have it (e.g. Derby) and because, well, ASCII. For the
* same reason we don't consider chr()/char() as "standard".
*/
public void ascii() { public void ascii() {
functionRegistry.namedDescriptorBuilder( "ascii" ) functionRegistry.namedDescriptorBuilder( "ascii" )
.setExactArgumentCount( 1 ) .setExactArgumentCount( 1 )