Search in sources :

Example 16 with HerdDBInternalException

use of herddb.core.HerdDBInternalException in project herddb by diennea.

the class TmpMapImpl method executeContainsKey.

private boolean executeContainsKey(byte[] serializedKey, String tmpTableName) throws CollectionsException {
    try {
        GetStatement get = new GetStatement(TableSpace.DEFAULT, tmpTableName, Bytes.from_array(serializedKey), null, false);
        GetResult getResult = (GetResult) tableSpaceManager.executeStatement(get, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), herddb.model.TransactionContext.NO_TRANSACTION);
        return getResult.found();
    } catch (HerdDBInternalException err) {
        throw new CollectionsException(err);
    }
}
Also used : HerdDBInternalException(herddb.core.HerdDBInternalException) GetResult(herddb.model.GetResult) GetStatement(herddb.model.commands.GetStatement)

Example 17 with HerdDBInternalException

use of herddb.core.HerdDBInternalException in project herddb by diennea.

the class SQLParserExpressionCompiler method getAggregateFunctionType.

public static int getAggregateFunctionType(Expression exp, OpSchema tableSchema) {
    if (exp instanceof net.sf.jsqlparser.expression.CastExpression) {
        // SELECT CAST(avg(n) as DOUBLE)
        net.sf.jsqlparser.expression.CastExpression c = (net.sf.jsqlparser.expression.CastExpression) exp;
        return JSQLParserPlanner.sqlDataTypeToColumnType(c.getType());
    }
    Function fn = (Function) exp;
    String functionNameLowercase = fn.getName().toLowerCase();
    switch(functionNameLowercase) {
        case COUNT:
            return ColumnTypes.LONG;
        case SUM:
        case SUM0:
        case AVG:
        case MIN:
        case MAX:
            checkSupported(fn.getParameters().getExpressions().size() == 1);
            final Expression first = fn.getParameters().getExpressions().get(0);
            if (first instanceof net.sf.jsqlparser.expression.CastExpression) {
                // SELECT AVG(CAST(n) as DOUBLE))
                net.sf.jsqlparser.expression.CastExpression c = (net.sf.jsqlparser.expression.CastExpression) first;
                return JSQLParserPlanner.sqlDataTypeToColumnType(c.getType());
            }
            checkSupported(first instanceof net.sf.jsqlparser.schema.Column, first.getClass());
            net.sf.jsqlparser.schema.Column cName = (net.sf.jsqlparser.schema.Column) first;
            String tableAlias = extractTableName(cName);
            ColumnRef col = findColumnInSchema(tableAlias, fixMySqlBackTicks(cName.getColumnName()), tableSchema, new IntHolder());
            checkSupported(col != null);
            // SUM of INTEGERS is an INTEGER (this is what Calcite does, but it is smarter than this)
            return col.type;
        default:
            throw new HerdDBInternalException(functionNameLowercase);
    }
}
Also used : HerdDBInternalException(herddb.core.HerdDBInternalException) Function(net.sf.jsqlparser.expression.Function) CaseExpression(net.sf.jsqlparser.expression.CaseExpression) NotExpression(net.sf.jsqlparser.expression.NotExpression) IsNullExpression(net.sf.jsqlparser.expression.operators.relational.IsNullExpression) Expression(net.sf.jsqlparser.expression.Expression) OrExpression(net.sf.jsqlparser.expression.operators.conditional.OrExpression) TimeKeyExpression(net.sf.jsqlparser.expression.TimeKeyExpression) BinaryExpression(net.sf.jsqlparser.expression.BinaryExpression) LikeExpression(net.sf.jsqlparser.expression.operators.relational.LikeExpression) InExpression(net.sf.jsqlparser.expression.operators.relational.InExpression) AndExpression(net.sf.jsqlparser.expression.operators.conditional.AndExpression) SignedExpression(net.sf.jsqlparser.expression.SignedExpression) IntHolder(herddb.utils.IntHolder)

Example 18 with HerdDBInternalException

use of herddb.core.HerdDBInternalException in project herddb by diennea.

the class SQLParserExpressionCompiler method getAggregateFunctionArgument.

public static ColumnRef getAggregateFunctionArgument(Function fn, OpSchema tableSchema) {
    String functionNameLowercase = fn.getName().toLowerCase();
    switch(functionNameLowercase) {
        case COUNT:
            return null;
        case SUM:
        case SUM0:
        case AVG:
        case MIN:
        case MAX:
            checkSupported(fn.getParameters().getExpressions().size() == 1);
            Expression first = fn.getParameters().getExpressions().get(0);
            if (first instanceof net.sf.jsqlparser.expression.CastExpression) {
                // SELECT AVG(CAST(n) as DOUBLE))
                first = ((net.sf.jsqlparser.expression.CastExpression) first).getLeftExpression();
            }
            checkSupported(first instanceof net.sf.jsqlparser.schema.Column);
            net.sf.jsqlparser.schema.Column cName = (net.sf.jsqlparser.schema.Column) first;
            String tableAlias = extractTableName(cName);
            // validate that it is a valid column referece in the input schema
            ColumnRef col = findColumnInSchema(tableAlias, fixMySqlBackTicks(cName.getColumnName()), tableSchema, new IntHolder());
            checkSupported(col != null);
            return col;
        default:
            throw new HerdDBInternalException(functionNameLowercase);
    }
}
Also used : HerdDBInternalException(herddb.core.HerdDBInternalException) CaseExpression(net.sf.jsqlparser.expression.CaseExpression) NotExpression(net.sf.jsqlparser.expression.NotExpression) IsNullExpression(net.sf.jsqlparser.expression.operators.relational.IsNullExpression) Expression(net.sf.jsqlparser.expression.Expression) OrExpression(net.sf.jsqlparser.expression.operators.conditional.OrExpression) TimeKeyExpression(net.sf.jsqlparser.expression.TimeKeyExpression) BinaryExpression(net.sf.jsqlparser.expression.BinaryExpression) LikeExpression(net.sf.jsqlparser.expression.operators.relational.LikeExpression) InExpression(net.sf.jsqlparser.expression.operators.relational.InExpression) AndExpression(net.sf.jsqlparser.expression.operators.conditional.AndExpression) SignedExpression(net.sf.jsqlparser.expression.SignedExpression) IntHolder(herddb.utils.IntHolder)

Example 19 with HerdDBInternalException

use of herddb.core.HerdDBInternalException in project herddb by diennea.

the class ServerSideConnectionPeer method executeScan.

public ScanResultSet executeScan(String tableSpace, String query, boolean usePreparedStatement, List<Object> parameters, long txId, int maxRows, int fetchSize, boolean keepReadLocks) throws HDBException {
    if (query == null) {
        throw new HDBException("bad query null");
    }
    parameters = PduCodec.normalizeParametersList(parameters);
    try {
        TranslatedQuery translatedQuery = server.getManager().getPlanner().translate(tableSpace, query, parameters, true, true, false, maxRows);
        translatedQuery.context.setForceRetainReadLock(keepReadLocks);
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.log(Level.FINEST, "{0} -> {1}", new Object[] { query, translatedQuery.plan.mainStatement });
        }
        TransactionContext transactionContext = new TransactionContext(txId);
        if (translatedQuery.plan.mainStatement instanceof SQLPlannedOperationStatement || translatedQuery.plan.mainStatement instanceof ScanStatement) {
            ScanResult scanResult = (ScanResult) server.getManager().executePlan(translatedQuery.plan, translatedQuery.context, transactionContext);
            DataScanner dataScanner = scanResult.dataScanner;
            return new LocalClientScanResultSetImpl(dataScanner);
        } else {
            throw new HDBException("unsupported query type for scan " + query + ": PLAN is " + translatedQuery.plan);
        }
    } catch (HerdDBInternalException err) {
        if (err.getCause() != null && err.getCause() instanceof ValidationException) {
            // no stacktraces for bad queries
            LOGGER.log(Level.FINE, "SQL error on scanner: " + err);
        } else {
            LOGGER.log(Level.SEVERE, "error on scanner: " + err, err);
        }
        throw new HDBException(err);
    }
}
Also used : ScanResult(herddb.model.ScanResult) TranslatedQuery(herddb.sql.TranslatedQuery) DataScanner(herddb.model.DataScanner) HerdDBInternalException(herddb.core.HerdDBInternalException) ValidationException(org.apache.calcite.tools.ValidationException) TransactionContext(herddb.model.TransactionContext) HDBException(herddb.client.HDBException) SQLPlannedOperationStatement(herddb.model.commands.SQLPlannedOperationStatement) ScanStatement(herddb.model.commands.ScanStatement)

Example 20 with HerdDBInternalException

use of herddb.core.HerdDBInternalException in project herddb by diennea.

the class ServerSideConnectionPeer method beginTransaction.

public long beginTransaction(String tableSpace) throws HDBException {
    try {
        BeginTransactionStatement statement = new BeginTransactionStatement(tableSpace);
        TransactionContext transactionContext = TransactionContext.NO_TRANSACTION;
        return server.getManager().executeStatement(statement, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), transactionContext).transactionId;
    } catch (HerdDBInternalException t) {
        throw new HDBException(t);
    }
}
Also used : HerdDBInternalException(herddb.core.HerdDBInternalException) TransactionContext(herddb.model.TransactionContext) BeginTransactionStatement(herddb.model.commands.BeginTransactionStatement) HDBException(herddb.client.HDBException)

Aggregations

HerdDBInternalException (herddb.core.HerdDBInternalException)23 TransactionContext (herddb.model.TransactionContext)8 HDBException (herddb.client.HDBException)5 DataScannerException (herddb.model.DataScannerException)5 SQLPlannedOperationStatement (herddb.model.commands.SQLPlannedOperationStatement)5 ScanStatement (herddb.model.commands.ScanStatement)5 TranslatedQuery (herddb.sql.TranslatedQuery)5 RawString (herddb.utils.RawString)5 TuplesList (herddb.utils.TuplesList)5 DataScanner (herddb.model.DataScanner)4 StatementExecutionException (herddb.model.StatementExecutionException)4 RollbackTransactionStatement (herddb.model.commands.RollbackTransactionStatement)4 DataStorageManagerException (herddb.storage.DataStorageManagerException)4 TableStatus (herddb.storage.TableStatus)4 ArrayList (java.util.ArrayList)4 DDLStatementExecutionResult (herddb.model.DDLStatementExecutionResult)3 DMLStatementExecutionResult (herddb.model.DMLStatementExecutionResult)3 Record (herddb.model.Record)3 Statement (herddb.model.Statement)3 StatementExecutionResult (herddb.model.StatementExecutionResult)3