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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations