Skip to content

Commit

Permalink
[oracle] Compile some expression functions
Browse files Browse the repository at this point in the history
Greatly speeds up case-insensitive value matches for oracle
expression based feature requests

(cherry-picked from 63e450a)
  • Loading branch information
nyalldawson committed Apr 17, 2018
1 parent b7507fa commit 62aefd7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
25 changes: 25 additions & 0 deletions src/providers/oracle/qgsoracleexpressioncompiler.cpp
Expand Up @@ -108,3 +108,28 @@ QString QgsOracleExpressionCompiler::quotedValue( const QVariant &value, bool &o
return QgsOracleConn::quotedValue( value );
}
}

static const QMap<QString, QString> FUNCTION_NAMES_SQL_FUNCTIONS_MAP
{
{ "sqrt", "sqrt" },
{ "abs", "abs" },
{ "cos", "cos" },
{ "sin", "sin" },
{ "tan", "tan" },
{ "acos", "acos" },
{ "asin", "asin" },
{ "atan", "atan" },
{ "exp", "exp" },
{ "ln", "ln" },
{ "log", "log" },
{ "round", "round" },
{ "floor", "floor" },
{ "ceil", "ceil" },
{ "lower", "lower" },
{ "upper", "upper" },
};

QString QgsOracleExpressionCompiler::sqlFunctionFromFunctionName( const QString &fnName ) const
{
return FUNCTION_NAMES_SQL_FUNCTIONS_MAP.value( fnName, QString() );
}
1 change: 1 addition & 0 deletions src/providers/oracle/qgsoracleexpressioncompiler.h
Expand Up @@ -30,6 +30,7 @@ class QgsOracleExpressionCompiler : public QgsSqlExpressionCompiler
virtual Result compileNode( const QgsExpressionNode *node, QString &result ) override;
virtual QString quotedIdentifier( const QString &identifier ) override;
virtual QString quotedValue( const QVariant &value, bool &ok ) override;
QString sqlFunctionFromFunctionName( const QString &fnName ) const override;
};

#endif // QGSORACLEEXPRESSIONCOMPILER_H
22 changes: 1 addition & 21 deletions tests/src/python/test_provider_oracle.py
Expand Up @@ -74,34 +74,14 @@ def uncompiledFilters(self):
'NULL or true',
'NULL or NULL',
'not null',
'sqrt(pk) >= 2',
'radians(cnt) < 2',
'degrees(pk) <= 200',
'abs(cnt) <= 200',
'cos(pk) < 0',
'sin(pk) < 0',
'tan(pk) < 0',
'acos(-1) < pk',
'asin(1) < pk',
'atan(3.14) < pk',
'atan2(3.14, pk) < 1',
'exp(pk) < 10',
'ln(pk) <= 1',
'log(3, pk) <= 1',
'log10(pk) < 0.5',
'round(3.14) <= pk',
'round(0.314,1) * 10 = pk',
'floor(3.14) <= pk',
'ceil(3.14) <= pk',
'pk < pi()',
'round(cnt / 66.67) <= 2',
'floor(cnt / 66.67) <= 2',
'ceil(cnt / 66.67) <= 2',
'log10(pk) < 0.5',
'pk < pi() / 2',
'pk = char(51)',
'pk = coalesce(NULL,3,4)',
'lower(name) = \'apple\'',
'upper(name) = \'APPLE\'',
'name = trim(\' Apple \')',
'x($geometry) < -70',
'y($geometry) > 70',
Expand Down

0 comments on commit 62aefd7

Please sign in to comment.