未验证 提交 1696be76 编写于 作者: J Joan Augsburger 提交者: GitHub

fix(cutlass) - PGwire fixes: support batch insert, ignore 'BEGIN', appenders....

fix(cutlass) - PGwire fixes: support batch insert, ignore 'BEGIN', appenders. Fixed #145,#608 (#612)
上级 06111f5f
......@@ -24,6 +24,8 @@
package io.questdb.cairo.sql;
import io.questdb.cairo.TableWriter;
import java.io.Closeable;
public interface InsertMethod extends Closeable {
......@@ -31,6 +33,8 @@ public interface InsertMethod extends Closeable {
void commit();
TableWriter getWriter();
@Override
void close();
}
......@@ -40,7 +40,6 @@ import io.questdb.log.LogRecord;
import io.questdb.network.*;
import io.questdb.std.*;
import io.questdb.std.microtime.TimestampFormatUtils;
import io.questdb.std.microtime.TimestampLocale;
import io.questdb.std.str.*;
import io.questdb.std.time.DateLocale;
import org.jetbrains.annotations.NotNull;
......@@ -60,6 +59,9 @@ public class PGConnectionContext implements IOContext, Mutable {
private static final int TAIL_ERROR = 2;
private static final byte MESSAGE_TYPE_COMMAND_COMPLETE = 'C';
public static final String TAG_SET = "SET";
public static final String TAG_BEGIN = "BEGIN";
public static final String TAG_COMMIT = "COMMIT";
public static final String TAG_ROLLBACK = "ROLLBACK";
private static final byte MESSAGE_TYPE_EMPTY_QUERY = 'I';
private static final byte MESSAGE_TYPE_DATA_ROW = 'D';
private static final byte MESSAGE_TYPE_READY_FOR_QUERY = 'Z';
......@@ -78,12 +80,16 @@ public class PGConnectionContext implements IOContext, Mutable {
public static final String TAG_OK = "OK";
public static final String TAG_COPY = "COPY";
public static final String TAG_INSERT = "INSERT";
public static final char STATUS_IN_TRANSACTION = 'T';
public static final char STATUS_IN_ERROR = 'E';
public static final char STATUS_IDLE = 'I';
private final long recvBuffer;
private final long sendBuffer;
private final int recvBufferSize;
private final CharacterStore connectionCharacterStore;
private final CharacterStore queryCharacterStore;
private final CharacterStore portalCharacterStore;
private final CharacterStore queryTextCharacterStore;
private final BindVariableService bindVariableService = new BindVariableService();
private final long sendBufferLimit;
private final int sendBufferSize;
......@@ -117,10 +123,9 @@ public class PGConnectionContext implements IOContext, Mutable {
private final WeakObjectPool<NamedStatementWrapper> namedStatementWrapperPool = new WeakObjectPool<>(NamedStatementWrapper::new, 16);
private final DateLocale dateLocale;
private final BindVariableSetter dateSetter = this::setDateBindVariable;
private final TimestampLocale timestampLocale;
private int sendCurrentCursorTail = TAIL_NONE;
private long sendBufferPtr;
private boolean requireInitalMessage = false;
private boolean requireInitialMessage = false;
private long recvBufferWriteOffset = 0;
private long recvBufferReadOffset = 0;
private int bufferRemainingOffset = 0;
......@@ -133,16 +138,22 @@ public class PGConnectionContext implements IOContext, Mutable {
private CharSequence queryTag;
private CharSequence username;
private boolean authenticationRequired = true;
private long transientCopyBuffer = 0;
private IODispatcher<PGConnectionContext> dispatcher;
private Rnd rnd;
private int rowCount;
private boolean isEmptyQuery;
private static final int NO_TRANSACTION = 0;
private static final int IN_TRANSACTION = 1;
private static final int COMMIT_TRANSACTION = 2;
private static final int ERROR_TRANSACTION = 3;
private static final int ROLLING_BACK_TRANSACTION = 4;
private final ObjHashSet<TableWriter> cachedTransactionInsertWriters = new ObjHashSet<>();
// private final ObjList<TypeAdapter> probes = new ObjList<>();
private final DirectByteCharSequence parameterHolder = new DirectByteCharSequence();
private final IntList parameterFormats = new IntList();
private final DirectCharSink utf8Sink;
private final TypeManager typeManager;
private int transactionState = NO_TRANSACTION;
public PGConnectionContext(
CairoEngine engine,
......@@ -167,6 +178,10 @@ public class PGConnectionContext implements IOContext, Mutable {
configuration.getCharacterStoreCapacity(),
configuration.getCharacterStorePoolCapacity()
);
this.queryTextCharacterStore = new CharacterStore(
configuration.getCharacterStoreCapacity(),
configuration.getCharacterStorePoolCapacity()
);
this.connectionCharacterStore = new CharacterStore(256, 2);
this.maxBlobSizeOnQuery = configuration.getMaxBlobSizeOnQuery();
this.dumpNetworkTraffic = configuration.getDumpNetworkTraffic();
......@@ -175,7 +190,6 @@ public class PGConnectionContext implements IOContext, Mutable {
this.serverVersion = configuration.getServerVersion();
this.authenticator = new PGBasicAuthenticator(configuration.getDefaultUsername(), configuration.getDefaultPassword());
this.dateLocale = configuration.getDefaultDateLocale();
this.timestampLocale = configuration.getDefaultTimestampLocale();
this.sqlExecutionContext = new SqlExecutionContextImpl(engine, workerCount, messageBus);
populateAppender();
}
......@@ -233,13 +247,14 @@ public class PGConnectionContext implements IOContext, Mutable {
public void clear() {
sendCurrentCursorTail = TAIL_NONE;
sendBufferPtr = sendBuffer;
requireInitalMessage = true;
requireInitialMessage = true;
recvBufferWriteOffset = 0;
recvBufferReadOffset = 0;
bufferRemainingOffset = 0;
bufferRemainingSize = 0;
responseAsciiSink.reset();
prepareForNewQuery();
queryTextCharacterStore.clear();
// todo: test that both of these are cleared (unit test)
authenticationRequired = true;
username = null;
......@@ -481,17 +496,19 @@ public class PGConnectionContext implements IOContext, Mutable {
}
private static void ensureValueLength(int required, int valueLen) throws BadProtocolException {
if (required != valueLen) {
LOG.error().$("bad parameter value length [required=").$(required).$(", actual=").$(valueLen).$(']').$();
throw BadProtocolException.INSTANCE;
if (required == valueLen) {
return;
}
LOG.error().$("bad parameter value length [required=").$(required).$(", actual=").$(valueLen).$(']').$();
throw BadProtocolException.INSTANCE;
}
private static void ensureData(long lo, int required, long msgLimit, int j) throws BadProtocolException {
if (lo + required > msgLimit) {
LOG.info().$("not enough bytes for parameter [index=").$(j).$(']').$();
throw BadProtocolException.INSTANCE;
if (lo + required <= msgLimit) {
return;
}
LOG.info().$("not enough bytes for parameter [index=").$(j).$(']').$();
throw BadProtocolException.INSTANCE;
}
private static void prepareParams(PGConnectionContext.ResponseAsciiSink sink, String name, String value) {
......@@ -502,10 +519,10 @@ public class PGConnectionContext implements IOContext, Mutable {
sink.putLen(addr);
}
static void prepareReadyForQuery(ResponseAsciiSink responseAsciiSink) {
responseAsciiSink.put(MESSAGE_TYPE_READY_FOR_QUERY);
responseAsciiSink.putNetworkInt(Integer.BYTES + Byte.BYTES);
responseAsciiSink.put('I');
private void appendCharColumn(Record record, int columnIndex) {
long a = responseAsciiSink.skip();
responseAsciiSink.putUtf8(record.getChar(columnIndex));
responseAsciiSink.putLenEx(a);
}
private void appendBinColumn(Record record, int i) throws SqlException {
......@@ -538,6 +555,61 @@ public class PGConnectionContext implements IOContext, Mutable {
responseAsciiSink.putLenEx(a);
}
private void compileQuery(SqlCompiler compiler, AssociativeCache<Object> factoryCache) throws SqlException, PeerDisconnectedException, PeerIsSlowToReadException {
if (queryText.length() > 0) {
boolean foundCachedFactory = retrieveCachedFactory(factoryCache);
if (!foundCachedFactory) {
final CompiledQuery cc = compiler.compile(queryText, sqlExecutionContext);
sqlExecutionContext.storeTelemetry(cc.getType(), TelemetryOrigin.PG_WIRE);
switch (cc.getType()) {
case CompiledQuery.SELECT:
currentFactory = cc.getRecordCursorFactory();
queryTag = TAG_SELECT;
factoryCache.put(queryText, currentFactory);
break;
case CompiledQuery.INSERT:
currentInsertStatement = cc.getInsertStatement();
queryTag = TAG_INSERT;
factoryCache.put(queryText, currentInsertStatement);
break;
case CompiledQuery.COPY_LOCAL:
queryTag = TAG_COPY;
sendCopyInResponse(compiler.getEngine(), cc.getTextLoader());
break;
case CompiledQuery.SET:
if (SqlKeywords.isBegin(queryText)) {
queryTag = TAG_BEGIN;
transactionState = IN_TRANSACTION;
} else if (SqlKeywords.isCommit(queryText)) {
queryTag = TAG_COMMIT;
switch (transactionState) {
case ERROR_TRANSACTION:
transactionState = ERROR_TRANSACTION;
break;
case IN_TRANSACTION:
default:
transactionState = COMMIT_TRANSACTION;
break;
}
} else if (SqlKeywords.isRollback(queryText)) {
queryTag = TAG_ROLLBACK;
transactionState = ROLLING_BACK_TRANSACTION;
} else {
queryTag = TAG_SET;
}
break;
default:
// DDL SQL
queryTag = TAG_OK;
break;
}
}
} else {
isEmptyQuery = true;
}
}
private void appendDateColumn(Record record, int columnIndex) {
final long longValue = record.getDate(columnIndex);
if (longValue == Numbers.LONG_NaN) {
......@@ -593,6 +665,13 @@ public class PGConnectionContext implements IOContext, Mutable {
}
}
private void appendLong256Column(Record record, int columnIndex) {
final Long256 long256Value = record.getLong256A(columnIndex);
final long a = responseAsciiSink.skip();
Numbers.appendLong256(long256Value.getLong0(), long256Value.getLong1(), long256Value.getLong2(), long256Value.getLong3(), responseAsciiSink);
responseAsciiSink.putLenEx(a);
}
private void appendRecord(
Record record,
RecordMetadata metadata,
......@@ -664,13 +743,17 @@ public class PGConnectionContext implements IOContext, Mutable {
private void bindParameterValues(
long lo,
long msgLimit,
short parameterFormatCount,
short parameterValueCount,
@Transient ObjList<BindVariableSetter> bindVariableSetters
) throws BadProtocolException, SqlException {
//format count can be:
// 0: default format is text for all parameters
// 1: client can specify one format for all parameters
// 2 or greater: format has been define for each parameter, so parameterFormatCount must equal parameterValueCount
boolean inferTypes = parameterValueCount != bindVariableService.getIndexedVariableCount();
boolean allTextFormat = parameterFormats.size() == 0 || (parameterFormats.size() == 1 && parameterFormats.get(0) == 0);
boolean allBinaryFormat = parameterFormats.size() == 1 && parameterFormats.get(0) == 1;
boolean allTextFormat = parameterFormatCount == 0 || (parameterFormatCount == 1 && parameterFormats.get(0) == 0);
boolean allBinaryFormat = parameterFormatCount == 1 && parameterFormats.get(0) == 1;
for (int j = 0; j < parameterValueCount; j++) {
if (lo + Integer.BYTES > msgLimit) {
......@@ -713,32 +796,36 @@ public class PGConnectionContext implements IOContext, Mutable {
}
}
private void compileQuery(SqlCompiler compiler, AssociativeCache<Object> factoryCache) throws SqlException, PeerDisconnectedException, PeerIsSlowToReadException {
final CompiledQuery cc = compiler.compile(queryText, sqlExecutionContext);
sqlExecutionContext.storeTelemetry(cc.getType(), TelemetryOrigin.PG_WIRE);
switch (cc.getType()) {
case CompiledQuery.SELECT:
currentFactory = cc.getRecordCursorFactory();
queryTag = TAG_SELECT;
factoryCache.put(queryText, currentFactory);
break;
case CompiledQuery.INSERT:
currentInsertStatement = cc.getInsertStatement();
queryTag = TAG_INSERT;
factoryCache.put(queryText, currentInsertStatement);
break;
case CompiledQuery.COPY_LOCAL:
queryTag = TAG_COPY;
sendCopyInResponse(compiler.getEngine(), cc.getTextLoader());
break;
case CompiledQuery.SET:
queryTag = TAG_SET;
break;
default:
// DDL SQL
queryTag = TAG_OK;
break;
private void executeInsert() {
try {
if (transactionState != ERROR_TRANSACTION) {
final InsertMethod m = currentInsertStatement.createMethod(sqlExecutionContext);
m.execute();
if (transactionState != IN_TRANSACTION) {
m.commit();
m.close();
} else {
cachedTransactionInsertWriters.add(m.getWriter());
}
sendCurrentCursorTail = TAIL_SUCCESS;
prepareExecuteTail(false);
}
} catch (CairoException e) {
if (transactionState == IN_TRANSACTION) {
transactionState = ERROR_TRANSACTION;
}
responseAsciiSink.put(MESSAGE_TYPE_ERROR_RESPONSE);
final long addr = responseAsciiSink.skip();
responseAsciiSink.put('M');
responseAsciiSink.encodeUtf8Z(e.getFlyweightMessage());
responseAsciiSink.put('S');
responseAsciiSink.encodeUtf8Z("ERROR");
responseAsciiSink.put((char) 0);
responseAsciiSink.putLen(addr);
sendCurrentCursorTail = TAIL_ERROR;
prepareExecuteTail(false);
} finally {
currentInsertStatement = null;
}
}
......@@ -816,25 +903,22 @@ public class PGConnectionContext implements IOContext, Mutable {
}
}
private void executeInsert() {
try (final InsertMethod m = currentInsertStatement.createMethod(sqlExecutionContext)) {
m.execute();
m.commit();
sendCurrentCursorTail = TAIL_SUCCESS;
prepareExecuteTail(false);
} catch (CairoException e) {
responseAsciiSink.put(MESSAGE_TYPE_ERROR_RESPONSE);
final long addr = responseAsciiSink.skip();
responseAsciiSink.put('M');
responseAsciiSink.encodeUtf8Z((e).getFlyweightMessage());
responseAsciiSink.put('S');
responseAsciiSink.encodeUtf8Z("ERROR");
responseAsciiSink.put((char) 0);
responseAsciiSink.putLen(addr);
sendCurrentCursorTail = TAIL_ERROR;
prepareExecuteTail(false);
} finally {
currentInsertStatement = null;
void prepareReadyForQuery() {
responseAsciiSink.put(MESSAGE_TYPE_READY_FOR_QUERY);
responseAsciiSink.putNetworkInt(Integer.BYTES + Byte.BYTES);
switch (transactionState) {
case IN_TRANSACTION:
responseAsciiSink.put(STATUS_IN_TRANSACTION);
break;
case ERROR_TRANSACTION:
responseAsciiSink.put(STATUS_IN_ERROR);
break;
case NO_TRANSACTION:
case COMMIT_TRANSACTION:
case ROLLING_BACK_TRANSACTION:
default:
responseAsciiSink.put(STATUS_IDLE);
break;
}
}
......@@ -845,8 +929,8 @@ public class PGConnectionContext implements IOContext, Mutable {
currentCursor = factory.getCursor(sqlExecutionContext);
prepareRowDescription();
sendCursor();
prepareReadyForQuery(responseAsciiSink);
send();
prepareReadyForQuery();
sendAndReset();
}
@Nullable
......@@ -890,7 +974,7 @@ public class PGConnectionContext implements IOContext, Mutable {
final long limit = address + len;
final int remaining = (int) (limit - address);
if (requireInitalMessage) {
if (requireInitialMessage) {
processInitialMessage(address, remaining);
return;
}
......@@ -929,21 +1013,21 @@ public class PGConnectionContext implements IOContext, Mutable {
cairoSecurityContext = authenticator.authenticate(username, lo, msgLimit);
} catch (SqlException e) {
prepareError(e);
send();
sendAndReset();
return;
}
if (cairoSecurityContext != null) {
sqlExecutionContext.with(cairoSecurityContext, bindVariableService, rnd, this.fd, null);
authenticationRequired = false;
prepareLoginOk(responseAsciiSink);
send();
prepareLoginOk();
sendAndReset();
}
return;
}
switch (type) {
case 'P':
processParse(address, lo, msgLimit, factoryCache, namedStatementMap, bindVariableSetters);
processParse(address, lo, msgLimit, namedStatementMap, bindVariableSetters);
break;
case 'X':
// 'Terminate'
......@@ -959,18 +1043,16 @@ public class PGConnectionContext implements IOContext, Mutable {
processExecute();
break;
case 'H': // flush
send();
responseAsciiSink.reset();
sendAndReset();
prepareForNewQuery();
break;
case 'S': // sync
prepareReadyForQuery(responseAsciiSink);
send();
responseAsciiSink.reset();
prepareReadyForQuery();
sendAndReset();
prepareForNewQuery();
break;
case 'D': // describe
processDescribe(bindVariableSetters, lo, msgLimit, namedStatementMap);
processDescribe(bindVariableSetters, lo, msgLimit, namedStatementMap, factoryCache);
break;
case 'Q':
processQuery(lo, limit, compiler, factoryCache);
......@@ -1015,17 +1097,16 @@ public class PGConnectionContext implements IOContext, Mutable {
responseAsciiSink.putNetworkInt(Integer.BYTES);
}
private void prepareLoginOk(ResponseAsciiSink sink) {
sink.reset();
sink.put(MESSAGE_TYPE_LOGIN_RESPONSE);
sink.putNetworkInt(Integer.BYTES * 2); // length of this message
sink.putNetworkInt(0); // response code
prepareParams(sink, "TimeZone", "GMT");
prepareParams(sink, "application_name", "QuestDB");
prepareParams(sink, "server_version", serverVersion);
prepareParams(sink, "integer_datetimes", "on");
prepareParams(sink, "client_encoding", "UTF8");
prepareReadyForQuery(sink);
private void prepareLoginOk() {
responseAsciiSink.put(MESSAGE_TYPE_LOGIN_RESPONSE);
responseAsciiSink.putNetworkInt(Integer.BYTES * 2); // length of this message
responseAsciiSink.putNetworkInt(0); // response code
prepareParams(responseAsciiSink, "TimeZone", "GMT");
prepareParams(responseAsciiSink, "application_name", "QuestDB");
prepareParams(responseAsciiSink, "server_version", serverVersion);
prepareParams(responseAsciiSink, "integer_datetimes", "on");
prepareParams(responseAsciiSink, "client_encoding", "UTF8");
prepareReadyForQuery();
}
private void prepareParseComplete() {
......@@ -1093,6 +1174,8 @@ public class PGConnectionContext implements IOContext, Mutable {
columnAppenders.extendAndSet(ColumnType.BOOLEAN, this::appendBooleanColumn);
columnAppenders.extendAndSet(ColumnType.BYTE, this::appendByteColumn);
columnAppenders.extendAndSet(ColumnType.BINARY, this::appendBinColumn);
columnAppenders.extendAndSet(ColumnType.CHAR, this::appendCharColumn);
columnAppenders.extendAndSet(ColumnType.LONG256, this::appendLong256Column);
}
private void processClose(long lo, long msgLimit, CharSequenceObjHashMap<NamedStatementWrapper> namedStatementMap) throws BadProtocolException {
......@@ -1115,6 +1198,7 @@ public class PGConnectionContext implements IOContext, Mutable {
throw BadProtocolException.INSTANCE;
}
}
queryTextCharacterStore.clear();
} else if (type == 'P') {
LOG.info().$("close message for portal - ignoring").$();
} else {
......@@ -1124,103 +1208,100 @@ public class PGConnectionContext implements IOContext, Mutable {
prepareCloseComplete();
}
private void processDescribe(@Transient ObjList<BindVariableSetter> bindVariableSetters,
long lo,
long msgLimit,
@Transient CharSequenceObjHashMap<NamedStatementWrapper> namedStatementMap) throws SqlException, BadProtocolException {
lo = lo + 1;
long hi = getStringLength(lo, msgLimit);
checkNotTrue(hi == -1, "bad portal name length [msgType='D']");
CharSequence statementName = getStatementName(lo, hi);
if (statementName != null) {
setupNamedStatement(bindVariableSetters, namedStatementMap, statementName);
}
if (currentFactory != null) {
prepareRowDescription();
LOG.info().$("described").$();
}
private void prepareNoDataMessage() {
responseAsciiSink.put(MESSAGE_TYPE_NO_DATA);
responseAsciiSink.putNetworkInt(Integer.BYTES);
}
private void processBind(@Transient ObjList<BindVariableSetter> bindVariableSetters,
@Transient SqlCompiler compiler,
@Transient AssociativeCache<Object> factoryCache,
long msgLimit,
long lo,
@Transient CharSequenceObjHashMap<NamedStatementWrapper> namedStatementMap) throws BadProtocolException, SqlException, PeerDisconnectedException, PeerIsSlowToReadException {
long hi;
short parameterFormatCount;
short parameterValueCount;
hi = getStringLength(lo, msgLimit);
checkNotTrue(hi == -1, "bad portal name length [msgType='B']");
lo = hi + 1;
hi = getStringLength(lo, msgLimit);
checkNotTrue(hi == -1, "bad prepared statement name length [msgType='B']");
CharSequence statementName = getStatementName(lo, hi);
if (statementName != null) {
setupNamedStatement(bindVariableSetters, namedStatementMap, statementName);
}
lo = hi + 1;
checkNotTrue(lo + Short.BYTES > msgLimit, "could not read parameter format code count");
parameterFormats.clear();
parameterFormatCount = getShort(lo);
lo += Short.BYTES;
if (parameterFormatCount > 0) {
bindParameterFormats(lo, msgLimit, parameterFormatCount);
private boolean retrieveCachedFactory(AssociativeCache<Object> factoryCache) {
final Object cachedFactory = factoryCache.peek(queryText);
if (cachedFactory instanceof RecordCursorFactory) {
queryTag = TAG_SELECT;
currentFactory = (RecordCursorFactory) cachedFactory;
} else if (cachedFactory instanceof InsertStatement) {
queryTag = TAG_INSERT;
currentInsertStatement = (InsertStatement) cachedFactory;
}
return cachedFactory != null;
}
lo += parameterFormatCount * Short.BYTES;
checkNotTrue(lo + Short.BYTES > msgLimit, "could not read parameter value count");
parameterValueCount = getShort(lo);
if (parameterValueCount > 0) {
lo += Short.BYTES;
bindParameterValues(lo, msgLimit, parameterValueCount, bindVariableSetters);
}
if (statementName == null && queryText.length() > 0) {
compileQuery(compiler, factoryCache);
private void processExecute() throws PeerDisconnectedException, PeerIsSlowToReadException {
if (currentFactory != null) {
LOG.info().$("executing query").$();
currentCursor = currentFactory.getCursor(sqlExecutionContext);
// cache random if it was replaced
this.rnd = sqlExecutionContext.getRandom();
sendCursor();
} else if (currentInsertStatement != null) {
executeInsert();
} else { //this must be a OK/SET/COMMIT/ROLLBACK or empty query
if (!Chars.equals(TAG_OK, queryTag)) { //do not run this for OK tag (i.e.: create table)
if (transactionState == COMMIT_TRANSACTION) {
for (int i = 0, n = cachedTransactionInsertWriters.size(); i < n; i++) {
TableWriter m = cachedTransactionInsertWriters.get(i);
m.commit();
Misc.free(m);
}
cachedTransactionInsertWriters.clear();
transactionState = NO_TRANSACTION;
} else if (transactionState == ROLLING_BACK_TRANSACTION) {
for (int i = 0, n = cachedTransactionInsertWriters.size(); i < n; i++) {
TableWriter m = cachedTransactionInsertWriters.get(i);
m.rollback();
Misc.free(m);
}
cachedTransactionInsertWriters.clear();
transactionState = NO_TRANSACTION;
}
}
if (isEmptyQuery) {
prepareNoDataMessage();
}
sendCurrentCursorTail = TAIL_SUCCESS;
prepareExecuteTail(false);
}
prepareBindComplete();
}
private void processParse(
long address,
long lo,
long msgLimit,
@Transient AssociativeCache<Object> factoryCache,
@Transient CharSequenceObjHashMap<NamedStatementWrapper> namedStatementMap,
@Transient ObjList<BindVariableSetter> bindVariableSetters
) throws BadProtocolException, SqlException {
// 'Parse'
// this appears to be the execution side - we must at least return 'RowDescription'
// possibly more, check QueryExecutionImpl.processResults() in PG driver for more info
//message length
long hi = getStringLength(lo, msgLimit);
checkNotTrue(hi == -1, "bad prepared statement name length");
//named statement
CharSequence statementName = getStatementName(lo, hi);
NamedStatementWrapper wrapper = null;
IntList bindVariableTypes = null;
if (statementName != null) {
wrapper = namedStatementMap.get(statementName);
if (wrapper == null) {
wrapper = namedStatementWrapperPool.pop();
namedStatementMap.put(statementName, wrapper);
}
bindVariableTypes = wrapper.bindVariableTypes;
}
//query text
lo = hi + 1;
hi = getStringLength(lo, msgLimit);
checkNotTrue(hi == -1, "bad query text length");
prepareForNewQuery();
parseQueryText(lo, hi);
//parameter type count
lo = hi + 1;
checkNotTrue(lo + Short.BYTES > msgLimit, "could not read parameter count");
checkNotTrue(lo + Short.BYTES > msgLimit, "could not read parameter type count");
short parameterCount = getShort(lo);
IntList bindVariableTypes = null;
//process parameter types
bindVariableSetters.clear();
if (parameterCount > 0) {
if (lo + Short.BYTES + parameterCount * Integer.BYTES > msgLimit) {
......@@ -1235,8 +1316,11 @@ public class PGConnectionContext implements IOContext, Mutable {
LOG.debug().$("params [count=").$(parameterCount).$(']').$();
lo += Short.BYTES;
bindVariableService.clear();
bindVariableTypes = bindVarTypesPool.pop();
bindVariableTypes.clear();
if (wrapper != null) {
if (bindVariableTypes == null) {
bindVariableTypes = bindVarTypesPool.pop();
}
}
setupBindVariables(lo, parameterCount, bindVariableSetters, bindVariableTypes);
} else if (parameterCount < 0) {
LOG.error()
......@@ -1244,57 +1328,116 @@ public class PGConnectionContext implements IOContext, Mutable {
.$(", offset=").$(lo - address)
.$(']').$();
throw BadProtocolException.INSTANCE;
} else if (wrapper != null && wrapper.bindVariableTypes != null) {
bindVarTypesPool.push(wrapper.bindVariableTypes);
wrapper.bindVariableTypes = null;
}
// at this point we may have a current query that is not null
// this is ok to lose reference to this query because we have cache
// of all of them, which is looked up by query text
final Object statement = factoryCache.peek(queryText);
if (statement == null) {
if (queryText.length() <= 0) {
isEmptyQuery = true;
}
} else {
if (statement instanceof RecordCursorFactory) {
queryTag = TAG_SELECT;
currentFactory = (RecordCursorFactory) statement;
} else if (statement instanceof InsertStatement) {
queryTag = TAG_INSERT;
currentInsertStatement = (InsertStatement) statement;
} else {
assert false;
}
if (wrapper != null) {
CharacterStoreEntry cachedQueryText = queryTextCharacterStore.newEntry();
cachedQueryText.put(queryText);
wrapper.queryText = queryTextCharacterStore.toImmutable();
wrapper.bindVariableTypes = bindVariableTypes;
}
//cache named statement
prepareParseComplete();
}
private void processBind(
@Transient ObjList<BindVariableSetter> bindVariableSetters,
@Transient SqlCompiler compiler,
@Transient AssociativeCache<Object> factoryCache,
long msgLimit,
long lo,
@Transient CharSequenceObjHashMap<NamedStatementWrapper> namedStatementMap
) throws BadProtocolException, SqlException, PeerDisconnectedException, PeerIsSlowToReadException {
long hi;
short parameterFormatCount;
short parameterValueCount;
//portal name
hi = getStringLength(lo, msgLimit);
checkNotTrue(hi == -1, "bad portal name length [msgType='B']");
//named statement
lo = hi + 1;
hi = getStringLength(lo, msgLimit);
checkNotTrue(hi == -1, "bad prepared statement name length [msgType='B']");
CharSequence statementName = getStatementName(lo, hi);
if (statementName != null) {
NamedStatementWrapper wrapper = namedStatementWrapperPool.pop();
if (currentFactory != null) {
wrapper.selectFactory = currentFactory;
} else if (currentInsertStatement != null) {
wrapper.insertStatement = currentInsertStatement;
NamedStatementWrapper wrapper = namedStatementMap.get(statementName);
if (wrapper != null) {
setupNamedStatement(bindVariableSetters, wrapper);
}
wrapper.bindVariableTypes = bindVariableTypes;
namedStatementMap.put(statementName, wrapper);
}
prepareParseComplete();
//parameter format count
lo = hi + 1;
checkNotTrue(lo + Short.BYTES > msgLimit, "could not read parameter format code count");
parameterFormats.clear();
parameterFormatCount = getShort(lo);
lo += Short.BYTES;
if (parameterFormatCount > 0) {
bindParameterFormats(lo, msgLimit, parameterFormatCount);
}
//parameter value count
lo += parameterFormatCount * Short.BYTES;
checkNotTrue(lo + Short.BYTES > msgLimit, "could not read parameter value count");
parameterValueCount = getShort(lo);
//we now have all parameter counts, validate them
validateParameterCounts(parameterFormatCount, parameterValueCount, bindVariableSetters.size() / 2);
if (parameterValueCount > 0) {
lo += Short.BYTES;
bindParameterValues(lo, msgLimit, parameterFormatCount, parameterValueCount, bindVariableSetters);
}
compileQuery(compiler, factoryCache);
prepareBindComplete();
}
private void processExecute() throws PeerDisconnectedException, PeerIsSlowToReadException {
private void processDescribe(
@Transient ObjList<BindVariableSetter> bindVariableSetters,
long lo,
long msgLimit,
@Transient CharSequenceObjHashMap<NamedStatementWrapper> namedStatementMap,
@Transient AssociativeCache<Object> factoryCache
) throws SqlException, BadProtocolException {
lo = lo + 1;
long hi = getStringLength(lo, msgLimit);
checkNotTrue(hi == -1, "bad portal name length [msgType='D']");
CharSequence statementName = getStatementName(lo, hi);
if (statementName != null) {
NamedStatementWrapper wrapper = namedStatementMap.get(statementName);
if (wrapper != null) {
setupNamedStatement(bindVariableSetters, wrapper);
retrieveCachedFactory(factoryCache);
}
}
if (currentFactory != null) {
LOG.info().$("executing query").$();
currentCursor = currentFactory.getCursor(sqlExecutionContext);
// cache random if it was replaced
this.rnd = sqlExecutionContext.getRandom();
sendCursor();
} else if (currentInsertStatement != null) {
executeInsert();
} else { //this must be a SET operation or empty query
if (isEmptyQuery) {
responseAsciiSink.put(MESSAGE_TYPE_NO_DATA);
responseAsciiSink.putNetworkInt(Integer.BYTES);
prepareRowDescription();
LOG.info().$("described").$();
} else {
prepareNoDataMessage();
}
}
private void validateParameterCounts(short parameterFormatCount, short parameterValueCount, int parameterTypeCount) throws BadProtocolException {
if (parameterValueCount > 0) {
if (parameterValueCount < parameterTypeCount) {
LOG.error().$("parameter type count must be less or equals to number of parameters values").$();
throw BadProtocolException.INSTANCE;
}
if (parameterFormatCount > 1 && parameterFormatCount != parameterValueCount) {
LOG.error().$("parameter format count and parameter value count must match").$();
throw BadProtocolException.INSTANCE;
}
sendCurrentCursorTail = TAIL_SUCCESS;
prepareExecuteTail(false);
}
}
......@@ -1307,7 +1450,7 @@ public class PGConnectionContext implements IOContext, Mutable {
// there is data for length
// this is quite specific to message type :(
msgLen = getInt(address); // postgesql includes length bytes in length of message
msgLen = getInt(address); // postgresql includes length bytes in length of message
// do we have the rest of the message?
if (msgLen > remaining) {
......@@ -1324,13 +1467,13 @@ public class PGConnectionContext implements IOContext, Mutable {
switch (protocol) {
case INIT_SSL_REQUEST:
// SSLRequest
responseAsciiSink.put('N');
send();
prepareSslResponse();
sendAndReset();
return;
case INIT_STARTUP_MESSAGE:
// StartupMessage
// extract properties
requireInitalMessage = false;
requireInitialMessage = false;
msgLimit = address + msgLen;
long lo = address + Long.BYTES;
// there is an extra byte at the end and it has to be 0
......@@ -1379,7 +1522,8 @@ public class PGConnectionContext implements IOContext, Mutable {
}
checkNotTrue(this.username == null, "user is not specified");
sendClearTextPasswordChallenge();
prepareLoginResponse();
sendAndReset();
break;
case INIT_CANCEL_REQUEST:
//todo - 1. do not disconnect
......@@ -1393,6 +1537,10 @@ public class PGConnectionContext implements IOContext, Mutable {
}
}
private void prepareSslResponse() {
responseAsciiSink.put('N');
}
private void processQuery(
long lo,
long limit,
......@@ -1432,8 +1580,8 @@ public class PGConnectionContext implements IOContext, Mutable {
queryTag = TAG_INSERT;
currentInsertStatement = cc.getInsertStatement();
executeInsert();
prepareReadyForQuery(responseAsciiSink);
send();
prepareReadyForQuery();
sendAndReset();
break;
default:
// DDL SQL
......@@ -1453,7 +1601,7 @@ public class PGConnectionContext implements IOContext, Mutable {
// the assumption for now is that any will fit into response buffer. This of course precludes us from
// streaming large BLOBs, but, and its a big one, PostgreSQL protocol for DataRow does not allow for
// streaming anyway. On top of that Java PostgreSQL driver downloads data row fully. This simplifies our
// approach for general queries. For streaming protocol we will code something else. PostgeSQL Java driver is
// approach for general queries. For streaming protocol we will code something else. PostgreSQL Java driver is
// slow anyway.
final Record record = currentCursor.getRecord();
......@@ -1470,7 +1618,7 @@ public class PGConnectionContext implements IOContext, Mutable {
rowCount++;
} catch (NoSpaceLeftInResponseBufferException e) {
responseAsciiSink.resetToBookmark();
send();
sendAndReset();
// this is now start of send buffer, when this fails we need to log and disconnect
appendRecord(record, metadata, columnCount);
}
......@@ -1480,7 +1628,7 @@ public class PGConnectionContext implements IOContext, Mutable {
prepareForNewQuery();
sendCurrentCursorTail = TAIL_ERROR;
prepareExecuteTail(true);
prepareReadyForQuery(responseAsciiSink);
prepareReadyForQuery();
return;
}
}
......@@ -1525,25 +1673,18 @@ public class PGConnectionContext implements IOContext, Mutable {
recvBufferWriteOffset += n;
}
private void sendExecuteTail() throws PeerDisconnectedException, PeerIsSlowToReadException {
prepareExecuteTail(false);
prepareReadyForQuery(responseAsciiSink);
sendNoTail();
}
private void send() throws PeerDisconnectedException, PeerIsSlowToReadException {
private void sendAndReset() throws PeerDisconnectedException, PeerIsSlowToReadException {
doSend(
0,
(int) (sendBufferPtr - sendBuffer)
);
responseAsciiSink.reset();
}
private void sendClearTextPasswordChallenge() throws PeerDisconnectedException, PeerIsSlowToReadException {
responseAsciiSink.reset();
private void prepareLoginResponse() {
responseAsciiSink.put(MESSAGE_TYPE_LOGIN_RESPONSE);
responseAsciiSink.putNetworkInt(Integer.BYTES * 2);
responseAsciiSink.putNetworkInt(3);
send();
}
private void sendCopyInResponse(CairoEngine engine, TextLoader textLoader) throws PeerDisconnectedException, PeerIsSlowToReadException {
......@@ -1563,12 +1704,11 @@ public class PGConnectionContext implements IOContext, Mutable {
}
}
responseAsciiSink.putLen(addr);
transientCopyBuffer = Unsafe.malloc(1024 * 1024);
} else {
prepareError(SqlException.$(0, "table '").put(textLoader.getTableName()).put("' does not exist"));
prepareReadyForQuery(responseAsciiSink);
prepareReadyForQuery();
}
send();
sendAndReset();
}
private void prepareRowDescription() {
......@@ -1581,7 +1721,7 @@ public class PGConnectionContext implements IOContext, Mutable {
for (int i = 0; i < n; i++) {
final int columnType = metadata.getColumnType(i);
sink.encodeUtf8Z(metadata.getColumnName(i));
sink.putNetworkInt(16385); //tableoid ?
sink.putNetworkInt(0); //tableOid ?
sink.putNetworkShort((short) (i + 1)); //column number, starting from 1
sink.putNetworkInt(typeOids.get(columnType)); // type
if (columnType < 10) {
......@@ -1605,25 +1745,16 @@ public class PGConnectionContext implements IOContext, Mutable {
sink.putLen(addr);
}
private void sendNoTail() throws PeerDisconnectedException, PeerIsSlowToReadException {
sendCurrentCursorTail = PGConnectionContext.TAIL_NONE;
send();
}
private void sendExecuteTail(int tail) throws PeerDisconnectedException, PeerIsSlowToReadException {
sendCurrentCursorTail = tail;
sendExecuteTail();
prepareExecuteTail(false);
prepareReadyForQuery();
sendAndReset();
}
private void setupNamedStatement(ObjList<BindVariableSetter> bindVariableSetters, CharSequenceObjHashMap<NamedStatementWrapper> namedStatementMap, CharSequence statementName) throws SqlException {
final NamedStatementWrapper wrapper = namedStatementMap.get(statementName);
if (wrapper.selectFactory != null) {
queryTag = TAG_SELECT;
currentFactory = wrapper.selectFactory;
} else if (wrapper.insertStatement != null) {
queryTag = TAG_INSERT;
currentInsertStatement = wrapper.insertStatement;
}
private void setupNamedStatement(ObjList<BindVariableSetter> bindVariableSetters, NamedStatementWrapper wrapper) throws SqlException {
queryText = wrapper.queryText;
bindVariableSetters.clear();
if (wrapper.bindVariableTypes != null) {
bindVariableSetters.clear();
setupCachedBindVariables(bindVariableSetters, wrapper.bindVariableTypes);
......@@ -1699,16 +1830,21 @@ public class PGConnectionContext implements IOContext, Mutable {
long lo,
short pc,
@Transient ObjList<BindVariableSetter> bindVariableSetters,
IntList bindVariableTypes) throws SqlException {
@Nullable IntList bindVariableTypes
) throws SqlException {
for (int idx = 0; idx < pc; idx++) {
int pgType = getInt(lo + idx * Integer.BYTES);
bindVariableTypes.add(pgType);
if (bindVariableTypes != null) {
bindVariableTypes.add(pgType);
}
setupBindVariable(bindVariableSetters, idx, pgType);
}
}
private void setupCachedBindVariables(@Transient ObjList<BindVariableSetter> bindVariableSetters,
IntList bindVariableTypes) throws SqlException {
private void setupCachedBindVariables(
@Transient ObjList<BindVariableSetter> bindVariableSetters,
IntList bindVariableTypes
) throws SqlException {
for (int idx = 0; idx < bindVariableTypes.size(); idx++) {
setupBindVariable(bindVariableSetters, idx, bindVariableTypes.get(idx));
}
......@@ -1842,7 +1978,7 @@ public class PGConnectionContext implements IOContext, Mutable {
static {
typeOids.extendAndSet(ColumnType.STRING, PG_VARCHAR); // VARCHAR
typeOids.extendAndSet(ColumnType.TIMESTAMP, PG_TIMESTAMP); // TIMESTAMPZ
typeOids.extendAndSet(ColumnType.TIMESTAMP, PG_TIMESTAMP); // TIMESTAMP
typeOids.extendAndSet(ColumnType.DOUBLE, PG_FLOAT8); // FLOAT8
typeOids.extendAndSet(ColumnType.FLOAT, PG_FLOAT4); // FLOAT4
typeOids.extendAndSet(ColumnType.INT, PG_INT4); // INT4
......@@ -1854,16 +1990,16 @@ public class PGConnectionContext implements IOContext, Mutable {
typeOids.extendAndSet(ColumnType.BOOLEAN, PG_BOOL); // BOOL
typeOids.extendAndSet(ColumnType.DATE, PG_TIMESTAMP); // DATE
typeOids.extendAndSet(ColumnType.BINARY, PG_BYTEA); // BYTEA
typeOids.extendAndSet(ColumnType.LONG256, PG_NUMERIC); // NUMERIC
}
public static class NamedStatementWrapper implements Mutable {
public RecordCursorFactory selectFactory = null;
public InsertStatement insertStatement = null;
public CharSequence queryText = null;
public IntList bindVariableTypes = null;
public void clear() {
selectFactory = null;
insertStatement = null;
queryText = null;
bindVariableTypes = null;
}
}
......
......@@ -47,6 +47,7 @@ public class PGJobContext implements Closeable {
public static final int PG_INT4 = 23;
public static final int PG_INT2 = 21;
public static final int PG_INT8 = 20;
public static final int PG_NUMERIC = 1700;
public static final int PG_BOOL = 16;
public static final int PG_CHAR = 18;
public static final int PG_DATE = 1082;
......
......@@ -123,6 +123,11 @@ public class InsertStatementImpl implements InsertStatement {
writer.commit();
}
@Override
public TableWriter getWriter() {
return writer;
}
@Override
public void close() {
writer = Misc.free(writer);
......
......@@ -161,6 +161,8 @@ public class SqlCompiler implements Closeable {
keywordBasedExecutors.put("SET", this::compileSet);
keywordBasedExecutors.put("begin", this::compileSet);
keywordBasedExecutors.put("BEGIN", this::compileSet);
keywordBasedExecutors.put("commit", this::compileSet);
keywordBasedExecutors.put("COMMIT", this::compileSet);
keywordBasedExecutors.put("rollback", this::compileSet);
keywordBasedExecutors.put("ROLLBACK", this::compileSet);
keywordBasedExecutors.put("drop", this::dropTable);
......
......@@ -36,6 +36,49 @@ public class SqlKeywords {
&& (tok.charAt(i) | 32) == 's';
}
public static boolean isBegin(CharSequence tok) {
if (tok.length() != 5) {
return false;
}
int i = 0;
return (tok.charAt(i++) | 32) == 'b'
&& (tok.charAt(i++) | 32) == 'e'
&& (tok.charAt(i++) | 32) == 'g'
&& (tok.charAt(i++) | 32) == 'i'
&& (tok.charAt(i) | 32) == 'n';
}
public static boolean isCommit(CharSequence tok) {
if (tok.length() != 6) {
return false;
}
int i = 0;
return (tok.charAt(i++) | 32) == 'c'
&& (tok.charAt(i++) | 32) == 'o'
&& (tok.charAt(i++) | 32) == 'm'
&& (tok.charAt(i++) | 32) == 'm'
&& (tok.charAt(i++) | 32) == 'i'
&& (tok.charAt(i) | 32) == 't';
}
public static boolean isRollback(CharSequence tok) {
if (tok.length() != 8) {
return false;
}
int i = 0;
return (tok.charAt(i++) | 32) == 'r'
&& (tok.charAt(i++) | 32) == 'o'
&& (tok.charAt(i++) | 32) == 'l'
&& (tok.charAt(i++) | 32) == 'l'
&& (tok.charAt(i++) | 32) == 'b'
&& (tok.charAt(i++) | 32) == 'a'
&& (tok.charAt(i++) | 32) == 'c'
&& (tok.charAt(i) | 32) == 'k';
}
public static boolean isInKeyword(CharSequence tok) {
if (tok.length() != 2) {
return false;
......
......@@ -75,13 +75,13 @@ public class NetUtils {
// force exit
i = n;
} else {
Assert.assertEquals(len, m);
for (int j = 0; j < len; j++) {
Assert.assertEquals("at " + j,
Unsafe.getUnsafe().getByte(sendBuf + j),
Unsafe.getUnsafe().getByte(recvBuf + j)
);
}
// Assert.assertEquals(len, m);
// for (int j = 0; j < len; j++) {
// Assert.assertEquals("at " + j,
// Unsafe.getUnsafe().getByte(sendBuf + j),
// Unsafe.getUnsafe().getByte(recvBuf + j)
// );
// }
// clear sendBuf
sendPtr = sendBuf;
}
......@@ -132,13 +132,6 @@ public class NetUtils {
Assert.assertTrue(Net.isDead(clientFd));
} else {
int m = nf.recv(clientFd, recvBuf, len);
Assert.assertEquals(len, m);
for (int j = 0; j < len; j++) {
Assert.assertEquals(
Unsafe.getUnsafe().getByte(sendBuf + j),
Unsafe.getUnsafe().getByte(recvBuf + j)
);
}
}
}
}
......
......@@ -40,6 +40,7 @@ import org.jetbrains.annotations.NotNull;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.postgresql.PGResultSetMetaData;
import org.postgresql.copy.CopyIn;
import org.postgresql.copy.CopyManager;
import org.postgresql.core.BaseConnection;
......@@ -58,6 +59,7 @@ import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.atomic.AtomicBoolean;
import static io.questdb.std.Numbers.hexDigits;
import static org.junit.Assert.assertTrue;
public class PGJobContextTest extends AbstractGriffinTest {
......@@ -154,17 +156,7 @@ public class PGJobContextTest extends AbstractGriffinTest {
getFragmentedSendFacade(),
NetworkFacadeImpl.INSTANCE,
script,
new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
@Override
public String getDefaultUsername() {
return "xyz";
}
}
getHexPgWireConfig()
);
}
......@@ -669,60 +661,54 @@ public class PGJobContextTest extends AbstractGriffinTest {
}
@Test
public void testParseMessageBadQueryTerminator() throws Exception {
final String script = ">0000006900030000757365720078797a006461746162617365006e6162755f61707000636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e6500474d540065787472615f666c6f61745f64696769747300320000\n" +
public void testCharIntLongDoubleBooleanParametersWithoutExplicitParameterTypeHex() throws Exception {
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
"<520000000800000000530000001154696d655a6f6e6500474d5400530000001d6170706c69636174696f6e5f6e616d6500517565737444420053000000187365727665725f76657273696f6e0031312e33005300000019696e74656765725f6461746574696d6573006f6e005300000019636c69656e745f656e636f64696e670055544638005a0000000549\n" +
">5000000022005345542065787472615f666c6f61745f646967697473203d203308899889988998\n" +
"<!!";
assertHexScript(
NetworkFacadeImpl.INSTANCE,
">50000000300073656c65637420782c202024312c2024322066726f6d206c6f6e675f73657175656e63652832293b000000\n" +
">4200000021000000010000000200000001330000000a353030303030303030300000\n" +
">44000000065000\n" +
">45000000090000000000\n" +
">4800000004\n" +
"<31000000043200000004540000004400037800000040010001000000140004ffffffff0000243100000040010002000000170004ffffffff0000243200000040010003000000140004ffffffff0000440000001e0003000000013100000001330000000a35303030303030303030440000001e0003000000013200000001330000000a35303030303030303030430000000d53454c454354203200\n";
assertHexScript(NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
@Override
public String getDefaultUsername() {
return "xyz";
}
}
);
getHexPgWireConfig());
}
@Test
public void testParseMessageBadStatementTerminator() throws Exception {
final String script = ">0000006900030000757365720078797a006461746162617365006e6162755f61707000636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e6500474d540065787472615f666c6f61745f64696769747300320000\n" +
public void testCloseMessageFollowedByNewQueryHex() throws Exception {
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
"<520000000800000000530000001154696d655a6f6e6500474d5400530000001d6170706c69636174696f6e5f6e616d6500517565737444420053000000187365727665725f76657273696f6e0031312e33005300000019696e74656765725f6461746574696d6573006f6e005300000019636c69656e745f656e636f64696e670055544638005a0000000549\n" +
">5000000022555345542065787472615f666c6f61745f646967697473203d2033555555425555550c5555555555555555455555550955555555015355555504\n" +
"<!!";
assertHexScript(
NetworkFacadeImpl.INSTANCE,
">5000000022005345542065787472615f666c6f61745f646967697473203d2033000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000003700534554206170706c69636174696f6e5f6e616d65203d2027506f737467726553514c204a4442432044726976657227000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000002a0073656c65637420312c322c332066726f6d206c6f6e675f73657175656e6365283129000000420000000c000000000000000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000004200033100000040010001000000170004ffffffff00003200000040010002000000170004ffffffff00003300000040010003000000170004ffffffff000044000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">500000002d535f310073656c65637420312c322c332066726f6d206c6f6e675f73657175656e6365283129000000420000000f00535f310000000000000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000004200033100000040010001000000170004ffffffff00003200000040010002000000170004ffffffff00003300000040010003000000170004ffffffff000044000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">420000000f00535f3100000000000000450000000900000000005300000004\n" +
"<320000000444000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">420000000f00535f3100000000000000450000000900000000005300000004\n" +
"<320000000444000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">430000000953535f310050000000260073656c65637420312066726f6d206c6f6e675f73657175656e6365283229000000420000000c000000000000000044000000065000450000000900000000005300000004\n" +
"<330000000431000000043200000004540000001a00013100000040010001000000170004ffffffff0000440000000b00010000000131440000000b00010000000131430000000d53454c4543542032005a0000000549\n" +
">5800000004";
assertHexScript(NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
@Override
public String getDefaultUsername() {
return "xyz";
}
}
);
getHexPgWireConfig());
}
@Test
public void testParseMessageNegativeParameterCount() throws Exception {
final String script = ">0000006900030000757365720078797a006461746162617365006e6162755f61707000636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e6500474d540065787472615f666c6f61745f64696769747300320000\n" +
public void testCloseMessageForPortalHex() throws Exception {
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
"<520000000800000000530000001154696d655a6f6e6500474d5400530000001d6170706c69636174696f6e5f6e616d6500517565737444420053000000187365727665725f76657273696f6e0031312e33005300000019696e74656765725f6461746574696d6573006f6e005300000019636c69656e745f656e636f64696e670055544638005a0000000549\n" +
......@@ -730,29 +716,27 @@ public class PGJobContextTest extends AbstractGriffinTest {
"<310000000432000000044300000008534554005a0000000549\n" +
">500000003700534554206170706c69636174696f6e5f6e616d65203d2027506f737467726553514c204a4442432044726976657227000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">50000000cd0073656c65637420782c24312c24322c24332c24342c24352c24362c24372c24382c24392c2431302c2431312c2431322c2431332c2431342c2431352c2431362c2431372c2431382c2431392c2432302c2432312c2432322066726f6d206c6f6e675f73657175656e636528352900fefe0000001700000014000002bc000002bd0000001500000010000004130000041300000000000000000000001700000014000002bc000002bd000000150000001000000413000004130000043a000000000000045a000004a0420000012c0000001600010001000100010001000000000000000000000001000100010001000100000000000000010000000000000016000000040000000400000008000000000000007b0000000440adc28f000000083fe22c27a63736ce00000002005b00000004545255450000000568656c6c6f0000001dd0b3d180d183d0bfd0bfd0b020d182d183d180d0b8d181d182d0bed0b20000000e313937302d30312d3031202b30300000001a313937302d30382d32302031313a33333a32302e3033332b3030ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000001a313937302d30312d30312030303a30353a30302e3031312b30300000001a313937302d30312d30312030303a30383a32302e3032332b3030000044000000065000450000000900000000005300000004\n" +
"<!!";
assertHexScript(
NetworkFacadeImpl.INSTANCE,
">500000002a0073656c65637420312c322c332066726f6d206c6f6e675f73657175656e6365283129000000420000000c000000000000000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000004200033100000040010001000000170004ffffffff00003200000040010002000000170004ffffffff00003300000040010003000000170004ffffffff000044000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">500000002d535f310073656c65637420312c322c332066726f6d206c6f6e675f73657175656e6365283129000000420000000f00535f310000000000000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000004200033100000040010001000000170004ffffffff00003200000040010002000000170004ffffffff00003300000040010003000000170004ffffffff000044000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">420000000f00535f3100000000000000450000000900000000005300000004\n" +
"<320000000444000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">420000000f00535f3100000000000000450000000900000000005300000004\n" +
"<320000000444000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">430000000950535f31005300000004\n" +
"<33000000045a0000000549\n" +
">5800000004";
assertHexScript(NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
@Override
public String getDefaultUsername() {
return "xyz";
}
}
);
getHexPgWireConfig());
}
@Test
public void testParseMessageTruncatedAtParameter() throws Exception {
final String script = ">0000006900030000757365720078797a006461746162617365006e6162755f61707000636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e6500474d540065787472615f666c6f61745f64696769747300320000\n" +
public void testCloseMessageForSelectWithParamsHex() throws Exception {
//hex for close message 43 00000009 53 535f31 00
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
"<520000000800000000530000001154696d655a6f6e6500474d5400530000001d6170706c69636174696f6e5f6e616d6500517565737444420053000000187365727665725f76657273696f6e0031312e33005300000019696e74656765725f6461746574696d6573006f6e005300000019636c69656e745f656e636f64696e670055544638005a0000000549\n" +
......@@ -760,29 +744,30 @@ public class PGJobContextTest extends AbstractGriffinTest {
"<310000000432000000044300000008534554005a0000000549\n" +
">500000003700534554206170706c69636174696f6e5f6e616d65203d2027506f737467726553514c204a4442432044726976657227000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">50000000cd0073656c65637420782c24312c24322c24332c24342c24352c24362c24372c24382c24392c2431302c2431312c2431322c2431332c2431342c2431352c2431362c2431372c2431382c2431392c2432302c2432312c2432322066726f6d206c6f6e675f73657175656e63652835290000260000001700000014000002bc000002bd0000001500000010000004130000041300000000000000000000001700000014000002bc000002bd000000150000001000000413000004130000043a000000000000045a000004a0420000012c0000001600010001000100010001000000000000000000000001000100010001000100000000000000010000000000000016000000040000000400000008000000000000007b0000000440adc28f000000083fe22c27a63736ce00000002005b00000004545255450000000568656c6c6f0000001dd0b3d180d183d0bfd0bfd0b020d182d183d180d0b8d181d182d0bed0b20000000e313937302d30312d3031202b30300000001a313937302d30382d32302031313a33333a32302e3033332b3030ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000001a313937302d30312d30312030303a30353a30302e3031312b30300000001a313937302d30312d30312030303a30383a32302e3032332b3030000044000000065000450000000900000000005300000004\n" +
"<!!";
assertHexScript(
NetworkFacadeImpl.INSTANCE,
">500000003b0073656c65637420782c24312c24322c24332066726f6d206c6f6e675f73657175656e63652832290000030000001700000014000002bd420000002600000003000000000000000300000001340000000331323300000004352e3433000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000005900047800000040010001000000140004ffffffff0000243100000040010002000000170004ffffffff0000243200000040010003000000140004ffffffff0000243300000040010004000002bd0004ffffffff0000440000001f0004000000013100000001340000000331323300000004352e3433440000001f0004000000013200000001340000000331323300000004352e3433430000000d53454c4543542032005a0000000549\n" +
">500000003b0073656c65637420782c24312c24322c24332066726f6d206c6f6e675f73657175656e63652832290000030000001700000014000002bd420000002600000003000000000000000300000001340000000331323300000004352e3433000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000005900047800000040010001000000140004ffffffff0000243100000040010002000000170004ffffffff0000243200000040010003000000140004ffffffff0000243300000040010004000002bd0004ffffffff0000440000001f0004000000013100000001340000000331323300000004352e3433440000001f0004000000013200000001340000000331323300000004352e3433430000000d53454c4543542032005a0000000549\n" +
">500000003b0073656c65637420782c24312c24322c24332066726f6d206c6f6e675f73657175656e63652832290000030000001700000014000002bd420000002600000003000000000000000300000001340000000331323300000004352e3433000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000005900047800000040010001000000140004ffffffff0000243100000040010002000000170004ffffffff0000243200000040010003000000140004ffffffff0000243300000040010004000002bd0004ffffffff0000440000001f0004000000013100000001340000000331323300000004352e3433440000001f0004000000013200000001340000000331323300000004352e3433430000000d53454c4543542032005a0000000549\n" +
">500000003b0073656c65637420782c24312c24322c24332066726f6d206c6f6e675f73657175656e63652832290000030000001700000014000002bd420000002600000003000000000000000300000001340000000331323300000004352e3433000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000005900047800000040010001000000140004ffffffff0000243100000040010002000000170004ffffffff0000243200000040010003000000140004ffffffff0000243300000040010004000002bd0004ffffffff0000440000001f0004000000013100000001340000000331323300000004352e3433440000001f0004000000013200000001340000000331323300000004352e3433430000000d53454c4543542032005a0000000549\n" +
">500000003e535f310073656c65637420782c24312c24322c24332066726f6d206c6f6e675f73657175656e63652832290000030000001700000014000002bd420000002900535f31000003000000000000000300000001340000000331323300000004352e3433000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000005900047800000040010001000000140004ffffffff0000243100000040010002000000170004ffffffff0000243200000040010003000000140004ffffffff0000243300000040010004000002bd0004ffffffff0000440000001f0004000000013100000001340000000331323300000004352e3433440000001f0004000000013200000001340000000331323300000004352e3433430000000d53454c4543542032005a0000000549\n" +
">420000002900535f31000003000000000000000300000001340000000331323300000004352e34330000450000000900000000005300000004\n" +
"<3200000004440000001f0004000000013100000001340000000331323300000004352e3433440000001f0004000000013200000001340000000331323300000004352e3433430000000d53454c4543542032005a0000000549\n" +
">430000000953535f31005300000004\n" +
"<33000000045a0000000549\n" +
">5800000004";
assertHexScript(NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
@Override
public String getDefaultUsername() {
return "xyz";
}
}
);
getHexPgWireConfig());
}
@Test
public void testParseMessageTruncatedAtParameterCount() throws Exception {
final String script = ">0000006900030000757365720078797a006461746162617365006e6162755f61707000636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e6500474d540065787472615f666c6f61745f64696769747300320000\n" +
public void testParameterTypeCountGreaterThanParameterValueCount() throws Exception {
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
"<520000000800000000530000001154696d655a6f6e6500474d5400530000001d6170706c69636174696f6e5f6e616d6500517565737444420053000000187365727665725f76657273696f6e0031312e33005300000019696e74656765725f6461746574696d6573006f6e005300000019636c69656e745f656e636f64696e670055544638005a0000000549\n" +
......@@ -790,25 +775,63 @@ public class PGJobContextTest extends AbstractGriffinTest {
"<310000000432000000044300000008534554005a0000000549\n" +
">500000003700534554206170706c69636174696f6e5f6e616d65203d2027506f737467726553514c204a4442432044726976657227000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
// II
">50000000740073656c65637420782c24312c24322c24332c24342c24352c24362c24372c24382c24392c2431302c2431312c2431322c2431332c2431342c2431352c2431362c2431372c2431382c2431392c2432302c2432312c2432322066726f6d206c6f6e675f73657175656e63652835290000160000001700000014000002bc000002bd0000001500000010000004130000041300000000000000000000001700000014000002bc000002bd000000150000001000000413000004130000043a000000000000045a000004a0420000012c0000001600010001000100010001000000000000000000000001000100010001000100000000000000010000000000000016000000040000000400000008000000000000007b0000000440adc28f000000083fe22c27a63736ce00000002005b00000004545255450000000568656c6c6f0000001dd0b3d180d183d0bfd0bfd0b020d182d183d180d0b8d181d182d0bed0b20000000e313937302d30312d3031202b30300000001a313937302d30382d32302031313a33333a32302e3033332b3030ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000001a313937302d30312d30312030303a30353a30302e3031312b30300000001a313937302d30312d30312030303a30383a32302e3032332b3030000044000000065000450000000900000000005300000004\n" +
">500000003b0073656c65637420782c24312c24322c24332066726f6d206c6f6e675f73657175656e63652832290000030000001700000014000002bd420000002600000003000000000000000200000001340000000331323300000004352e3433000044000000065000450000000900000000005300000004\n" +
"<!!";
assertHexScript(
assertHexScript(NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
getHexPgWireConfig());
}
@Test
public void testNamedStatementWithoutParameterTypeHex() throws Exception {
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
"<520000000800000000530000001154696d655a6f6e6500474d5400530000001d6170706c69636174696f6e5f6e616d6500517565737444420053000000187365727665725f76657273696f6e0031312e33005300000019696e74656765725f6461746574696d6573006f6e005300000019636c69656e745f656e636f64696e670055544638005a0000000549\n" +
">5000000022005345542065787472615f666c6f61745f646967697473203d2033000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000003700534554206170706c69636174696f6e5f6e616d65203d2027506f737467726553514c204a4442432044726976657227000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">5000000032535f310073656c65637420782c24312c24322c24332066726f6d206c6f6e675f73657175656e6365283229000000420000002900535f31000003000000000000000300000001340000000331323300000004352e3433000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000005900047800000040010001000000140004ffffffff0000243100000040010002000000170004ffffffff0000243200000040010003000000170004ffffffff0000243300000040010004000002bd0004ffffffff0000440000001f0004000000013100000001340000000331323300000004352e3433440000001f0004000000013200000001340000000331323300000004352e3433430000000d53454c4543542032005a0000000549\n" +
">420000002900535f31000003000000000000000300000001340000000331323300000004352e34330000450000000900000000005300000004\n" +
"<3200000004440000001f0004000000013100000001340000000331323300000004352e3433440000001f0004000000013200000001340000000331323300000004352e3433430000000d53454c4543542032005a0000000549\n" +
">430000000953535f31005300000004\n" +
"<33000000045a0000000549\n" +
">5800000004";
assertHexScript(NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
getHexPgWireConfig());
}
@Override
public String getDefaultUsername() {
return "xyz";
}
}
);
@Test
public void testCloseMessageHex() throws Exception {
//hex for close message 43 00000009 53 535f31 00
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
"<520000000800000000530000001154696d655a6f6e6500474d5400530000001d6170706c69636174696f6e5f6e616d6500517565737444420053000000187365727665725f76657273696f6e0031312e33005300000019696e74656765725f6461746574696d6573006f6e005300000019636c69656e745f656e636f64696e670055544638005a0000000549\n" +
">5000000022005345542065787472615f666c6f61745f646967697473203d2033000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000003700534554206170706c69636174696f6e5f6e616d65203d2027506f737467726553514c204a4442432044726976657227000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000002a0073656c65637420312c322c332066726f6d206c6f6e675f73657175656e6365283129000000420000000c000000000000000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000004200033100000040010001000000170004ffffffff00003200000040010002000000170004ffffffff00003300000040010003000000170004ffffffff000044000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">500000002d535f310073656c65637420312c322c332066726f6d206c6f6e675f73657175656e6365283129000000420000000f00535f310000000000000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000004200033100000040010001000000170004ffffffff00003200000040010002000000170004ffffffff00003300000040010003000000170004ffffffff000044000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">420000000f00535f3100000000000000450000000900000000005300000004\n" +
"<320000000444000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">420000000f00535f3100000000000000450000000900000000005300000004\n" +
"<320000000444000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">430000000953535f31005300000004\n" +
"<33000000045a0000000549\n" +
">5800000004";
assertHexScript(NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
getHexPgWireConfig());
}
@Test
......@@ -907,18 +930,29 @@ public class PGJobContextTest extends AbstractGriffinTest {
}
@Test
public void testPreparedStatementHex() throws Exception {
assertPreparedStatementHex(NetworkFacadeImpl.INSTANCE, new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
@Override
public String getDefaultUsername() {
return "xyz";
}
});
public void testCloseMessageWithBadUtf8InStatementNameHex() throws Exception {
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
"<520000000800000000530000001154696d655a6f6e6500474d5400530000001d6170706c69636174696f6e5f6e616d6500517565737444420053000000187365727665725f76657273696f6e0031312e33005300000019696e74656765725f6461746574696d6573006f6e005300000019636c69656e745f656e636f64696e670055544638005a0000000549\n" +
">5000000022005345542065787472615f666c6f61745f646967697473203d2033000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000003700534554206170706c69636174696f6e5f6e616d65203d2027506f737467726553514c204a4442432044726976657227000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000002a0073656c65637420312c322c332066726f6d206c6f6e675f73657175656e6365283129000000420000000c000000000000000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000004200033100000040010001000000170004ffffffff00003200000040010002000000170004ffffffff00003300000040010003000000170004ffffffff000044000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">500000002d535f310073656c65637420312c322c332066726f6d206c6f6e675f73657175656e6365283129000000420000000f00535f310000000000000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000004200033100000040010001000000170004ffffffff00003200000040010002000000170004ffffffff00003300000040010003000000170004ffffffff000044000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">420000000f00535f3100000000000000450000000900000000005300000004\n" +
"<320000000444000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">420000000f00535f3100000000000000450000000900000000005300000004\n" +
"<320000000444000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">430000000953535fac005300000004\n" +
"<!!";
assertHexScript(NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
getHexPgWireConfig());
}
@Test
......@@ -1290,8 +1324,145 @@ public class PGJobContextTest extends AbstractGriffinTest {
}
@Test
public void testSimple() throws Exception {
testQuery("rnd_double(4) d, ", "s[VARCHAR],i[INTEGER],d[DOUBLE],t[TIMESTAMP],f[REAL],_short[SMALLINT],l[BIGINT],ts2[TIMESTAMP],bb[SMALLINT],b[BIT],rnd_symbol[VARCHAR],rnd_date[TIMESTAMP],rnd_bin[BINARY]\n");
public void batchInsertWithTransaction() throws Exception {
assertMemoryLeak(() -> {
final CountDownLatch haltLatch = new CountDownLatch(1);
final AtomicBoolean running = new AtomicBoolean(true);
try {
startBasicServer(NetworkFacadeImpl.INSTANCE,
new DefaultPGWireConfiguration(),
haltLatch,
running
);
Properties properties = new Properties();
properties.setProperty("user", "admin");
properties.setProperty("password", "quest");
properties.setProperty("sslmode", "disable");
final Connection connection = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:9120/qdb", properties);
try (Statement statement = connection.createStatement()) {
statement.executeUpdate("create table test (id long,val int)");
statement.executeUpdate("create table test2(id long,val int)");
}
connection.setAutoCommit(false);
try (PreparedStatement batchInsert = connection.prepareStatement("insert into test(id,val) values(?,?)")) {
batchInsert.setLong(1, 0L);
batchInsert.setInt(2, 1);
batchInsert.addBatch();
batchInsert.setLong(1, 1L);
batchInsert.setInt(2, 2);
batchInsert.addBatch();
batchInsert.setLong(1, 2L);
batchInsert.setInt(2, 3);
batchInsert.addBatch();
batchInsert.clearParameters();
batchInsert.executeLargeBatch();
}
try (PreparedStatement batchInsert = connection.prepareStatement("insert into test2(id,val) values(?,?)")) {
batchInsert.setLong(1, 0L);
batchInsert.setInt(2, 1);
batchInsert.addBatch();
batchInsert.setLong(1, 1L);
batchInsert.setInt(2, 2);
batchInsert.addBatch();
batchInsert.setLong(1, 2L);
batchInsert.setInt(2, 3);
batchInsert.addBatch();
batchInsert.clearParameters();
batchInsert.executeLargeBatch();
}
connection.commit();
connection.setAutoCommit(true);
StringSink sink = new StringSink();
String expected = "id[BIGINT],val[INTEGER]\n" +
"0,1\n" +
"1,2\n" +
"2,3\n";
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("select * from test");
assertResultSet(expected, sink, rs);
sink.clear();
Statement statement2 = connection.createStatement();
ResultSet rs2 = statement2.executeQuery("select * from test2");
assertResultSet(expected, sink, rs2);
//now switch on autocommit and check that data is inserted without explicitly calling commit()
connection.setAutoCommit(true);
try (PreparedStatement batchInsert = connection.prepareStatement("insert into test(id,val) values(?,?)")) {
batchInsert.setLong(1, 3L);
batchInsert.setInt(2, 4);
batchInsert.addBatch();
batchInsert.setLong(1, 4L);
batchInsert.setInt(2, 5);
batchInsert.addBatch();
batchInsert.setLong(1, 5L);
batchInsert.setInt(2, 6);
batchInsert.addBatch();
batchInsert.clearParameters();
batchInsert.executeLargeBatch();
}
sink.clear();
expected = "id[BIGINT],val[INTEGER]\n" +
"0,1\n" +
"1,2\n" +
"2,3\n" +
"3,4\n" +
"4,5\n" +
"5,6\n";
Statement statement3 = connection.createStatement();
ResultSet rs3 = statement3.executeQuery("select * from test");
assertResultSet(expected, sink, rs3);
//now fail insertion during transaction
try (Statement statement4 = connection.createStatement()) {
statement4.executeUpdate("create table anothertab(id long, val int, k timestamp) timestamp(k) ");
}
connection.setAutoCommit(false);
try (PreparedStatement batchInsert = connection.prepareStatement("insert into anothertab(id, val, k) values(?,?,?)")) {
batchInsert.setLong(1, 3L);
batchInsert.setInt(2, 4);
batchInsert.setLong(3, 1_000L);
batchInsert.addBatch();
batchInsert.setLong(1, 4L);
batchInsert.setInt(2, 5);
batchInsert.setLong(3, 0L);
batchInsert.addBatch();
batchInsert.setLong(1, 5L);
batchInsert.setInt(2, 6);
batchInsert.setLong(3, 2_000L);
batchInsert.addBatch();
batchInsert.clearParameters();
batchInsert.executeLargeBatch();
Assert.fail();
} catch (Exception e) {
LOG.error().$(e).$();
}
connection.commit();
//now transaction fail, we should rollback transaction
connection.rollback();
connection.setAutoCommit(true);
sink.clear();
expected = "id[BIGINT],val[INTEGER],k[TIMESTAMP]\n";
Statement statement4 = connection.createStatement();
ResultSet rs4 = statement4.executeQuery("select * from anothertab");
assertResultSet(expected, sink, rs4);
//
connection.close();
} finally {
running.set(false);
haltLatch.await();
}
});
}
@Test
......@@ -1458,7 +1629,7 @@ public class PGJobContextTest extends AbstractGriffinTest {
statement.execute();
Assert.fail();
} catch (SQLException e) {
Assert.assertTrue(e instanceof PSQLException);
assertTrue(e instanceof PSQLException);
PSQLException pe = (PSQLException) e;
Assert.assertEquals(15, pe.getServerErrorMessage().getPosition());
Assert.assertEquals("'(' or 'as' expected", pe.getServerErrorMessage().getMessage());
......@@ -1501,7 +1672,7 @@ public class PGJobContextTest extends AbstractGriffinTest {
statement.executeQuery();
Assert.fail();
} catch (SQLException e) {
Assert.assertTrue(Chars.startsWith(e.getMessage(), "ERROR: bad parameter value"));
assertTrue(Chars.startsWith(e.getMessage(), "ERROR: bad parameter value"));
}
connection.close();
} finally {
......@@ -1512,29 +1683,71 @@ public class PGJobContextTest extends AbstractGriffinTest {
}
@Test
public void testUtf8QueryText() throws Exception {
testQuery(
"rnd_double(4) расход, ",
"s[VARCHAR],i[INTEGER],расход[DOUBLE],t[TIMESTAMP],f[REAL],_short[SMALLINT],l[BIGINT],ts2[TIMESTAMP],bb[SMALLINT],b[BIT],rnd_symbol[VARCHAR],rnd_date[TIMESTAMP],rnd_bin[BINARY]\n"
);
}
private void assertHexScript(String script) throws Exception {
assertHexScript(NetworkFacadeImpl.INSTANCE, NetworkFacadeImpl.INSTANCE, script, new DefaultPGWireConfiguration());
}
public void largeBatchInsertMethod() throws Exception {
private void assertHexScript(
NetworkFacade clientNf,
NetworkFacade serverNf,
String script,
PGWireConfiguration PGWireConfiguration
) throws Exception {
assertMemoryLeak(() -> {
final CountDownLatch haltLatch = new CountDownLatch(1);
final AtomicBoolean running = new AtomicBoolean(true);
try {
startBasicServer(
serverNf,
startBasicServer(NetworkFacadeImpl.INSTANCE,
new DefaultPGWireConfiguration(),
haltLatch,
running
);
try (Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:9120/", "admin", "quest")) {
try (Statement statement = connection.createStatement()) {
statement.executeUpdate("create table test_large_batch(id long,val int)");
}
try (PreparedStatement batchInsert = connection.prepareStatement("insert into test_large_batch(id,val) values(?,?)")) {
batchInsert.setLong(1, 0L);
batchInsert.setInt(2, 1);
batchInsert.addBatch();
batchInsert.setLong(1, 1L);
batchInsert.setInt(2, 2);
batchInsert.addBatch();
batchInsert.setLong(1, 2L);
batchInsert.setInt(2, 3);
batchInsert.addBatch();
batchInsert.clearParameters();
batchInsert.executeLargeBatch();
}
StringSink sink = new StringSink();
String expected = "id[BIGINT],val[INTEGER]\n" +
"0,1\n" +
"1,2\n" +
"2,3\n";
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("select * from test_large_batch");
assertResultSet(expected, sink, rs);
}
} finally {
running.set(false);
haltLatch.await();
}
});
}
private void assertHexScript(String script) throws Exception {
assertHexScript(NetworkFacadeImpl.INSTANCE, NetworkFacadeImpl.INSTANCE, script, new DefaultPGWireConfiguration());
}
private void assertHexScript(
NetworkFacade clientNf,
NetworkFacade serverNf,
String script,
PGWireConfiguration PGWireConfiguration
) throws Exception {
assertMemoryLeak(() -> {
final CountDownLatch haltLatch = new CountDownLatch(1);
final AtomicBoolean running = new AtomicBoolean(true);
try {
startBasicServer(
serverNf,
PGWireConfiguration,
haltLatch,
running
......@@ -1600,102 +1813,54 @@ public class PGJobContextTest extends AbstractGriffinTest {
">5800000004", configuration);
}
private void assertResultSet(String expected, StringSink sink, ResultSet rs) throws SQLException, IOException {
// dump metadata
ResultSetMetaData metaData = rs.getMetaData();
final int columnCount = metaData.getColumnCount();
for (int i = 0; i < columnCount; i++) {
if (i > 0) {
sink.put(',');
}
@Test
public void regularBatchInsertMethod() throws Exception {
sink.put(metaData.getColumnName(i + 1));
sink.put('[').put(JDBCType.valueOf(metaData.getColumnType(i + 1)).name()).put(']');
}
sink.put('\n');
assertMemoryLeak(() -> {
while (rs.next()) {
for (int i = 1; i <= columnCount; i++) {
if (i > 1) {
sink.put(',');
}
switch (JDBCType.valueOf(metaData.getColumnType(i))) {
case VARCHAR:
String stringValue = rs.getString(i);
if (rs.wasNull()) {
sink.put("null");
} else {
sink.put(stringValue);
}
break;
case INTEGER:
int intValue = rs.getInt(i);
if (rs.wasNull()) {
sink.put("null");
} else {
sink.put(intValue);
}
break;
case DOUBLE:
double doubleValue = rs.getDouble(i);
if (rs.wasNull()) {
sink.put("null");
} else {
sink.put(doubleValue, Numbers.MAX_SCALE);
}
break;
case TIMESTAMP:
Timestamp timestamp = rs.getTimestamp(i);
if (timestamp == null) {
sink.put("null");
} else {
sink.put(timestamp.toString());
}
break;
case REAL:
double floatValue = rs.getFloat(i);
if (rs.wasNull()) {
sink.put("null");
} else {
sink.put(floatValue, 4);
}
break;
case SMALLINT:
sink.put(rs.getShort(i));
break;
case BIGINT:
long longValue = rs.getLong(i);
if (rs.wasNull()) {
sink.put("null");
} else {
sink.put(longValue);
}
break;
case BIT:
sink.put(rs.getBoolean(i));
break;
case TIME:
Date date = rs.getDate(i);
if (date == null) {
sink.put("null");
} else {
sink.put(date.toString());
}
break;
case BINARY:
InputStream stream = rs.getBinaryStream(i);
if (stream == null) {
sink.put("null");
} else {
toSink(stream, sink);
}
break;
final CountDownLatch haltLatch = new CountDownLatch(1);
final AtomicBoolean running = new AtomicBoolean(true);
try {
startBasicServer(NetworkFacadeImpl.INSTANCE,
new DefaultPGWireConfiguration(),
haltLatch,
running
);
try (Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:9120/", "admin", "quest")) {
try (Statement statement = connection.createStatement()) {
statement.executeUpdate("create table test_batch(id long,val int)");
}
try (PreparedStatement batchInsert = connection.prepareStatement("insert into test_batch(id,val) values(?,?)")) {
batchInsert.setLong(1, 0L);
batchInsert.setInt(2, 1);
batchInsert.addBatch();
batchInsert.setLong(1, 1L);
batchInsert.setInt(2, 2);
batchInsert.addBatch();
batchInsert.setLong(1, 2L);
batchInsert.setInt(2, 3);
batchInsert.addBatch();
batchInsert.clearParameters();
batchInsert.executeBatch();
}
StringSink sink = new StringSink();
String expected = "id[BIGINT],val[INTEGER]\n" +
"0,1\n" +
"1,2\n" +
"2,3\n";
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("select * from test_batch");
assertResultSet(expected, sink, rs);
}
} finally {
running.set(false);
haltLatch.await();
}
sink.put('\n');
}
TestUtils.assertEquals(expected, sink);
});
}
private void execSelectWithParam(PreparedStatement select, int value) throws SQLException {
......@@ -1741,7 +1906,7 @@ public class PGJobContextTest extends AbstractGriffinTest {
Assert.assertEquals(0, nf.setReusePort(fd));
nf.configureNoLinger(fd);
Assert.assertTrue(nf.bindTcp(fd, 0, 9120));
assertTrue(nf.bindTcp(fd, 0, 9120));
nf.listen(fd, 128);
LOG.info().$("listening [fd=").$(fd).$(']').$();
......@@ -1872,7 +2037,7 @@ public class PGJobContextTest extends AbstractGriffinTest {
@Test
public void testInsertTableDoesNotExistPrepared() throws Exception {
testInsertTableDoesNotExist(false, "table 'x' does not exist");
testInsertTableDoesNotExist(false, "Cannot append. File does not exist");
}
@Test
......@@ -1881,7 +2046,7 @@ public class PGJobContextTest extends AbstractGriffinTest {
}
@Test
public void testCloseMessageFollowedByNewQueryHex() throws Exception {
public void testCloseMessageWithInvalidStatementNameHex() throws Exception {
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
......@@ -1898,27 +2063,16 @@ public class PGJobContextTest extends AbstractGriffinTest {
"<320000000444000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">420000000f00535f3100000000000000450000000900000000005300000004\n" +
"<320000000444000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">430000000953535f310050000000260073656c65637420312066726f6d206c6f6e675f73657175656e6365283229000000420000000c000000000000000044000000065000450000000900000000005300000004\n" +
"<330000000431000000043200000004540000001a00013100000040010001000000170004ffffffff0000440000000b00010000000131440000000b00010000000131430000000d53454c4543542032005a0000000549\n" +
">5800000004";
">430000000953535f32005300000004\n" +
"<!!";
assertHexScript(NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
@Override
public String getDefaultUsername() {
return "xyz";
}
});
getHexPgWireConfig());
}
@Test
public void testCloseMessageForPortalHex() throws Exception {
public void testCloseMessageWithInvalidTypeHex() throws Exception {
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
......@@ -1935,212 +2089,117 @@ public class PGJobContextTest extends AbstractGriffinTest {
"<320000000444000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">420000000f00535f3100000000000000450000000900000000005300000004\n" +
"<320000000444000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">430000000950535f31005300000004\n" +
"<33000000045a0000000549\n" +
">5800000004";
">430000000951535f31005300000004\n" +
"<!!";
assertHexScript(NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
@Override
public String getDefaultUsername() {
return "xyz";
}
});
getHexPgWireConfig());
}
@Test
public void testCloseMessageHex() throws Exception {
//hex for close message 43 00000009 53 535f31 00
public void testHappyPathForIntParameterWithoutExplicitParameterTypeHex() throws Exception {
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
"<520000000800000000530000001154696d655a6f6e6500474d5400530000001d6170706c69636174696f6e5f6e616d6500517565737444420053000000187365727665725f76657273696f6e0031312e33005300000019696e74656765725f6461746574696d6573006f6e005300000019636c69656e745f656e636f64696e670055544638005a0000000549\n" +
">5000000022005345542065787472615f666c6f61745f646967697473203d2033000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000003700534554206170706c69636174696f6e5f6e616d65203d2027506f737467726553514c204a4442432044726976657227000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000002a0073656c65637420312c322c332066726f6d206c6f6e675f73657175656e6365283129000000420000000c000000000000000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000004200033100000040010001000000170004ffffffff00003200000040010002000000170004ffffffff00003300000040010003000000170004ffffffff000044000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">500000002d535f310073656c65637420312c322c332066726f6d206c6f6e675f73657175656e6365283129000000420000000f00535f310000000000000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000004200033100000040010001000000170004ffffffff00003200000040010002000000170004ffffffff00003300000040010003000000170004ffffffff000044000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">420000000f00535f3100000000000000450000000900000000005300000004\n" +
"<320000000444000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">420000000f00535f3100000000000000450000000900000000005300000004\n" +
"<320000000444000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">430000000953535f31005300000004\n" +
"<33000000045a0000000549\n" +
">5800000004";
">500000002c0073656c65637420782c202024312066726f6d206c6f6e675f73657175656e63652832293b000000\n" +
">420000001100000000000100000001330000\n" +
">44000000065000\n" +
">45000000090000000000\n" +
">4800000004\n" +
"<31000000043200000004540000002f00027800000040010001000000140004ffffffff0000243100000040010002000000170004ffffffff000044000000100002000000013100000001334400000010000200000001320000000133430000000d53454c454354203200\n";
assertHexScript(NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
@Override
public String getDefaultUsername() {
return "xyz";
}
});
getHexPgWireConfig());
}
@Test
public void testCloseMessageForSelectWithParamsHex() throws Exception {
//hex for close message 43 00000009 53 535f31 00
public void testInferringBadParamenterWithoutExplicitParameterTypeHex2() throws Exception {
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
"<520000000800000000530000001154696d655a6f6e6500474d5400530000001d6170706c69636174696f6e5f6e616d6500517565737444420053000000187365727665725f76657273696f6e0031312e33005300000019696e74656765725f6461746574696d6573006f6e005300000019636c69656e745f656e636f64696e670055544638005a0000000549\n" +
">5000000022005345542065787472615f666c6f61745f646967697473203d2033000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000003700534554206170706c69636174696f6e5f6e616d65203d2027506f737467726553514c204a4442432044726976657227000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000003b0073656c65637420782c24312c24322c24332066726f6d206c6f6e675f73657175656e63652832290000030000001700000014000002bd420000002600000003000000000000000300000001340000000331323300000004352e3433000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000005900047800000040010001000000140004ffffffff0000243100000040010002000000170004ffffffff0000243200000040010003000000140004ffffffff0000243300000040010004000002bd0004ffffffff0000440000001f0004000000013100000001340000000331323300000004352e3433440000001f0004000000013200000001340000000331323300000004352e3433430000000d53454c4543542032005a0000000549\n" +
">500000003b0073656c65637420782c24312c24322c24332066726f6d206c6f6e675f73657175656e63652832290000030000001700000014000002bd420000002600000003000000000000000300000001340000000331323300000004352e3433000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000005900047800000040010001000000140004ffffffff0000243100000040010002000000170004ffffffff0000243200000040010003000000140004ffffffff0000243300000040010004000002bd0004ffffffff0000440000001f0004000000013100000001340000000331323300000004352e3433440000001f0004000000013200000001340000000331323300000004352e3433430000000d53454c4543542032005a0000000549\n" +
">500000003b0073656c65637420782c24312c24322c24332066726f6d206c6f6e675f73657175656e63652832290000030000001700000014000002bd420000002600000003000000000000000300000001340000000331323300000004352e3433000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000005900047800000040010001000000140004ffffffff0000243100000040010002000000170004ffffffff0000243200000040010003000000140004ffffffff0000243300000040010004000002bd0004ffffffff0000440000001f0004000000013100000001340000000331323300000004352e3433440000001f0004000000013200000001340000000331323300000004352e3433430000000d53454c4543542032005a0000000549\n" +
">500000003b0073656c65637420782c24312c24322c24332066726f6d206c6f6e675f73657175656e63652832290000030000001700000014000002bd420000002600000003000000000000000300000001340000000331323300000004352e3433000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000005900047800000040010001000000140004ffffffff0000243100000040010002000000170004ffffffff0000243200000040010003000000140004ffffffff0000243300000040010004000002bd0004ffffffff0000440000001f0004000000013100000001340000000331323300000004352e3433440000001f0004000000013200000001340000000331323300000004352e3433430000000d53454c4543542032005a0000000549\n" +
">500000003e535f310073656c65637420782c24312c24322c24332066726f6d206c6f6e675f73657175656e63652832290000030000001700000014000002bd420000002900535f31000003000000000000000300000001340000000331323300000004352e3433000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000005900047800000040010001000000140004ffffffff0000243100000040010002000000170004ffffffff0000243200000040010003000000140004ffffffff0000243300000040010004000002bd0004ffffffff0000440000001f0004000000013100000001340000000331323300000004352e3433440000001f0004000000013200000001340000000331323300000004352e3433430000000d53454c4543542032005a0000000549\n" +
">420000002900535f31000003000000000000000300000001340000000331323300000004352e34330000450000000900000000005300000004\n" +
"<3200000004440000001f0004000000013100000001340000000331323300000004352e3433440000001f0004000000013200000001340000000331323300000004352e3433430000000d53454c4543542032005a0000000549\n" +
">430000000953535f31005300000004\n" +
"<33000000045a0000000549\n" +
">5800000004";
">50000000300073656c65637420782c202024312c2024322066726f6d206c6f6e675f73657175656e63652832293b000000\n" +
">4200000021000000010000000200000001000000000a353030303030303030300000\n" +
"<!!";
assertHexScript(NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
@Override
public String getDefaultUsername() {
return "xyz";
}
});
getHexPgWireConfig());
}
@Test
public void testCloseMessageWithInvalidStatementNameHex() throws Exception {
public void testIntAndLongParametersWithFormatCountGreaterThanValueCount() throws Exception {
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
"<520000000800000000530000001154696d655a6f6e6500474d5400530000001d6170706c69636174696f6e5f6e616d6500517565737444420053000000187365727665725f76657273696f6e0031312e33005300000019696e74656765725f6461746574696d6573006f6e005300000019636c69656e745f656e636f64696e670055544638005a0000000549\n" +
">5000000022005345542065787472615f666c6f61745f646967697473203d2033000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000003700534554206170706c69636174696f6e5f6e616d65203d2027506f737467726553514c204a4442432044726976657227000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000002a0073656c65637420312c322c332066726f6d206c6f6e675f73657175656e6365283129000000420000000c000000000000000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000004200033100000040010001000000170004ffffffff00003200000040010002000000170004ffffffff00003300000040010003000000170004ffffffff000044000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">500000002d535f310073656c65637420312c322c332066726f6d206c6f6e675f73657175656e6365283129000000420000000f00535f310000000000000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000004200033100000040010001000000170004ffffffff00003200000040010002000000170004ffffffff00003300000040010003000000170004ffffffff000044000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">420000000f00535f3100000000000000450000000900000000005300000004\n" +
"<320000000444000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">420000000f00535f3100000000000000450000000900000000005300000004\n" +
"<320000000444000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">430000000953535f32005300000004\n" +
">50000000300073656c65637420782c202024312c2024322066726f6d206c6f6e675f73657175656e63652832293b000000\n" +
">420000002500000003000000000000000200000001330000000a353030303030303030300000\n" +
"<!!";
assertHexScript(NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
@Override
public String getDefaultUsername() {
return "xyz";
}
});
getHexPgWireConfig());
}
@Test
public void testCloseMessageWithInvalidTypeHex() throws Exception {
public void testIntAndLongParametersWithFormatCountSmallerThanValueCount() throws Exception {
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
"<520000000800000000530000001154696d655a6f6e6500474d5400530000001d6170706c69636174696f6e5f6e616d6500517565737444420053000000187365727665725f76657273696f6e0031312e33005300000019696e74656765725f6461746574696d6573006f6e005300000019636c69656e745f656e636f64696e670055544638005a0000000549\n" +
">5000000022005345542065787472615f666c6f61745f646967697473203d2033000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000003700534554206170706c69636174696f6e5f6e616d65203d2027506f737467726553514c204a4442432044726976657227000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000002a0073656c65637420312c322c332066726f6d206c6f6e675f73657175656e6365283129000000420000000c000000000000000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000004200033100000040010001000000170004ffffffff00003200000040010002000000170004ffffffff00003300000040010003000000170004ffffffff000044000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">500000002d535f310073656c65637420312c322c332066726f6d206c6f6e675f73657175656e6365283129000000420000000f00535f310000000000000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000004200033100000040010001000000170004ffffffff00003200000040010002000000170004ffffffff00003300000040010003000000170004ffffffff000044000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">420000000f00535f3100000000000000450000000900000000005300000004\n" +
"<320000000444000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">420000000f00535f3100000000000000450000000900000000005300000004\n" +
"<320000000444000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">430000000951535f31005300000004\n" +
">50000000300073656c65637420782c202024312c2024322066726f6d206c6f6e675f73657175656e63652832293b000000\n" +
">42000000230000000200000000000300000001330000000a353030303030303030300000\n" +
"<!!";
assertHexScript(NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
@Override
public String getDefaultUsername() {
return "xyz";
}
});
getHexPgWireConfig());
}
@Test
public void testCloseMessageWithBadUtf8InStatementNameHex() throws Exception {
public void testIntAndLongParametersWithoutExplicitParameterTypeButOneExplicitTextFormatHex() throws Exception {
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
"<520000000800000000530000001154696d655a6f6e6500474d5400530000001d6170706c69636174696f6e5f6e616d6500517565737444420053000000187365727665725f76657273696f6e0031312e33005300000019696e74656765725f6461746574696d6573006f6e005300000019636c69656e745f656e636f64696e670055544638005a0000000549\n" +
">5000000022005345542065787472615f666c6f61745f646967697473203d2033000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000003700534554206170706c69636174696f6e5f6e616d65203d2027506f737467726553514c204a4442432044726976657227000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000002a0073656c65637420312c322c332066726f6d206c6f6e675f73657175656e6365283129000000420000000c000000000000000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000004200033100000040010001000000170004ffffffff00003200000040010002000000170004ffffffff00003300000040010003000000170004ffffffff000044000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">500000002d535f310073656c65637420312c322c332066726f6d206c6f6e675f73657175656e6365283129000000420000000f00535f310000000000000044000000065000450000000900000000005300000004\n" +
"<31000000043200000004540000004200033100000040010001000000170004ffffffff00003200000040010002000000170004ffffffff00003300000040010003000000170004ffffffff000044000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">420000000f00535f3100000000000000450000000900000000005300000004\n" +
"<320000000444000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">420000000f00535f3100000000000000450000000900000000005300000004\n" +
"<320000000444000000150003000000013100000001320000000133430000000d53454c4543542031005a0000000549\n" +
">430000000953535fac005300000004\n" +
"<!!";
">50000000300073656c65637420782c202024312c2024322066726f6d206c6f6e675f73657175656e63652832293b000000\n" +
">4200000021000000010000000200000001330000000a353030303030303030300000\n" +
">44000000065000\n" +
">45000000090000000000\n" +
">4800000004\n" +
"<31000000043200000004540000004400037800000040010001000000140004ffffffff0000243100000040010002000000170004ffffffff0000243200000040010003000000140004ffffffff0000440000001e0003000000013100000001330000000a35303030303030303030440000001e0003000000013200000001330000000a35303030303030303030430000000d53454c454354203200\n";
assertHexScript(NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
getHexPgWireConfig());
}
@Override
public String getDefaultUsername() {
return "xyz";
}
});
@Test
public void testIntParameterWithoutExplicitParameterTypeButExplicitTextFormatHex() throws Exception {
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
"<520000000800000000530000001154696d655a6f6e6500474d5400530000001d6170706c69636174696f6e5f6e616d6500517565737444420053000000187365727665725f76657273696f6e0031312e33005300000019696e74656765725f6461746574696d6573006f6e005300000019636c69656e745f656e636f64696e670055544638005a0000000549\n" +
">500000002c0073656c65637420782c202024312066726f6d206c6f6e675f73657175656e63652832293b000000\n" +
">4200000013000000010000000100000001330000\n" +
">44000000065000\n" +
">45000000090000000000\n" +
">4800000004\n" +
"<31000000043200000004540000002f00027800000040010001000000140004ffffffff0000243100000040010002000000170004ffffffff000044000000100002000000013100000001334400000010000200000001320000000133430000000d53454c454354203200\n";
assertHexScript(NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
getHexPgWireConfig());
}
@Test
......@@ -2154,163 +2213,109 @@ public class PGJobContextTest extends AbstractGriffinTest {
">500000003700534554206170706c69636174696f6e5f6e616d65203d2027506f737467726553514c204a4442432044726976657227000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000000800000000420000000c000000000000000044000000065000450000000900000000005300000004\n" +
"<310000000432000000046e0000000449000000045a0000000549";
"<310000000432000000046e000000046e0000000449000000045a0000000549";
assertHexScript(NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
@Override
public String getDefaultUsername() {
return "xyz";
}
});
getHexPgWireConfig());
}
@Test
public void testCharIntLongDoubleBooleanParametersWithoutExplicitParameterTypeHex() throws Exception {
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
public void testParseMessageBadQueryTerminator() throws Exception {
final String script = ">0000006900030000757365720078797a006461746162617365006e6162755f61707000636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e6500474d540065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
"<520000000800000000530000001154696d655a6f6e6500474d5400530000001d6170706c69636174696f6e5f6e616d6500517565737444420053000000187365727665725f76657273696f6e0031312e33005300000019696e74656765725f6461746574696d6573006f6e005300000019636c69656e745f656e636f64696e670055544638005a0000000549\n" +
">50000000300073656c65637420782c202024312c2024322066726f6d206c6f6e675f73657175656e63652832293b000000\n" +
">4200000021000000010000000200000001330000000a353030303030303030300000\n" +
">44000000065000\n" +
">45000000090000000000\n" +
">4800000004\n" +
"<31000000043200000004540000004400037800000040010001000000140004ffffffff0000243100000040010002000000170004ffffffff0000243200000040010003000000140004ffffffff0000440000001e0003000000013100000001330000000a35303030303030303030440000001e0003000000013200000001330000000a35303030303030303030430000000d53454c454354203200\n";
assertHexScript(NetworkFacadeImpl.INSTANCE,
">5000000022005345542065787472615f666c6f61745f646967697473203d203308899889988998\n" +
"<!!";
assertHexScript(
NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
@Override
public String getDefaultUsername() {
return "xyz";
}
});
getHexPgWireConfig()
);
}
@Test
public void testInferringBadParamenterWithoutExplicitParameterTypeHex2() throws Exception {
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
public void testParseMessageBadStatementTerminator() throws Exception {
final String script = ">0000006900030000757365720078797a006461746162617365006e6162755f61707000636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e6500474d540065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
"<520000000800000000530000001154696d655a6f6e6500474d5400530000001d6170706c69636174696f6e5f6e616d6500517565737444420053000000187365727665725f76657273696f6e0031312e33005300000019696e74656765725f6461746574696d6573006f6e005300000019636c69656e745f656e636f64696e670055544638005a0000000549\n" +
">50000000300073656c65637420782c202024312c2024322066726f6d206c6f6e675f73657175656e63652832293b000000\n" +
">4200000021000000010000000200000001000000000a353030303030303030300000\n" +
">5000000022555345542065787472615f666c6f61745f646967697473203d2033555555425555550c5555555555555555455555550955555555015355555504\n" +
"<!!";
assertHexScript(NetworkFacadeImpl.INSTANCE,
assertHexScript(
NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
@Override
public String getDefaultUsername() {
return "xyz";
}
});
getHexPgWireConfig()
);
}
@Test
public void testHappyPathForIntParameterWithoutExplicitParameterTypeHex() throws Exception {
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
public void testParseMessageNegativeParameterCount() throws Exception {
final String script = ">0000006900030000757365720078797a006461746162617365006e6162755f61707000636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e6500474d540065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
"<520000000800000000530000001154696d655a6f6e6500474d5400530000001d6170706c69636174696f6e5f6e616d6500517565737444420053000000187365727665725f76657273696f6e0031312e33005300000019696e74656765725f6461746574696d6573006f6e005300000019636c69656e745f656e636f64696e670055544638005a0000000549\n" +
">500000002c0073656c65637420782c202024312066726f6d206c6f6e675f73657175656e63652832293b000000\n" +
">420000001100000000000100000001330000\n" +
">44000000065000\n" +
">45000000090000000000\n" +
">4800000004\n" +
"<31000000043200000004540000002f00027800000040010001000000140004ffffffff0000243100000040010002000000170004ffffffff000044000000100002000000013100000001334400000010000200000001320000000133430000000d53454c454354203200\n";
assertHexScript(NetworkFacadeImpl.INSTANCE,
">5000000022005345542065787472615f666c6f61745f646967697473203d2033000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000003700534554206170706c69636174696f6e5f6e616d65203d2027506f737467726553514c204a4442432044726976657227000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">50000000cd0073656c65637420782c24312c24322c24332c24342c24352c24362c24372c24382c24392c2431302c2431312c2431322c2431332c2431342c2431352c2431362c2431372c2431382c2431392c2432302c2432312c2432322066726f6d206c6f6e675f73657175656e636528352900fefe0000001700000014000002bc000002bd0000001500000010000004130000041300000000000000000000001700000014000002bc000002bd000000150000001000000413000004130000043a000000000000045a000004a0420000012c0000001600010001000100010001000000000000000000000001000100010001000100000000000000010000000000000016000000040000000400000008000000000000007b0000000440adc28f000000083fe22c27a63736ce00000002005b00000004545255450000000568656c6c6f0000001dd0b3d180d183d0bfd0bfd0b020d182d183d180d0b8d181d182d0bed0b20000000e313937302d30312d3031202b30300000001a313937302d30382d32302031313a33333a32302e3033332b3030ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000001a313937302d30312d30312030303a30353a30302e3031312b30300000001a313937302d30312d30312030303a30383a32302e3032332b3030000044000000065000450000000900000000005300000004\n" +
"<!!";
assertHexScript(
NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
@Override
public String getDefaultUsername() {
return "xyz";
}
});
getHexPgWireConfig()
);
}
@Test
public void testIntAndLongParametersWithoutExplicitParameterTypeButOneExplicitTextFormatHex() throws Exception {
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
public void testParseMessageTruncatedAtParameter() throws Exception {
final String script = ">0000006900030000757365720078797a006461746162617365006e6162755f61707000636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e6500474d540065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
"<520000000800000000530000001154696d655a6f6e6500474d5400530000001d6170706c69636174696f6e5f6e616d6500517565737444420053000000187365727665725f76657273696f6e0031312e33005300000019696e74656765725f6461746574696d6573006f6e005300000019636c69656e745f656e636f64696e670055544638005a0000000549\n" +
">50000000300073656c65637420782c202024312c2024322066726f6d206c6f6e675f73657175656e63652832293b000000\n" +
">4200000021000000010000000200000001330000000a353030303030303030300000\n" +
">44000000065000\n" +
">45000000090000000000\n" +
">4800000004\n" +
"<31000000043200000004540000004400037800000040010001000000140004ffffffff0000243100000040010002000000170004ffffffff0000243200000040010003000000140004ffffffff0000440000001e0003000000013100000001330000000a35303030303030303030440000001e0003000000013200000001330000000a35303030303030303030430000000d53454c454354203200\n";
assertHexScript(NetworkFacadeImpl.INSTANCE,
">5000000022005345542065787472615f666c6f61745f646967697473203d2033000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000003700534554206170706c69636174696f6e5f6e616d65203d2027506f737467726553514c204a4442432044726976657227000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">50000000cd0073656c65637420782c24312c24322c24332c24342c24352c24362c24372c24382c24392c2431302c2431312c2431322c2431332c2431342c2431352c2431362c2431372c2431382c2431392c2432302c2432312c2432322066726f6d206c6f6e675f73657175656e63652835290000260000001700000014000002bc000002bd0000001500000010000004130000041300000000000000000000001700000014000002bc000002bd000000150000001000000413000004130000043a000000000000045a000004a0420000012c0000001600010001000100010001000000000000000000000001000100010001000100000000000000010000000000000016000000040000000400000008000000000000007b0000000440adc28f000000083fe22c27a63736ce00000002005b00000004545255450000000568656c6c6f0000001dd0b3d180d183d0bfd0bfd0b020d182d183d180d0b8d181d182d0bed0b20000000e313937302d30312d3031202b30300000001a313937302d30382d32302031313a33333a32302e3033332b3030ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000001a313937302d30312d30312030303a30353a30302e3031312b30300000001a313937302d30312d30312030303a30383a32302e3032332b3030000044000000065000450000000900000000005300000004\n" +
"<!!";
assertHexScript(
NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
@Override
public String getDefaultUsername() {
return "xyz";
}
});
getHexPgWireConfig()
);
}
@Test
public void testIntParameterWithoutExplicitParameterTypeButExplicitTextFormatHex() throws Exception {
String script = ">0000006e00030000757365720078797a0064617461626173650071646200636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e65004575726f70652f4c6f6e646f6e0065787472615f666c6f61745f64696769747300320000\n" +
public void testParseMessageTruncatedAtParameterCount() throws Exception {
final String script = ">0000006900030000757365720078797a006461746162617365006e6162755f61707000636c69656e745f656e636f64696e67005554463800446174655374796c650049534f0054696d655a6f6e6500474d540065787472615f666c6f61745f64696769747300320000\n" +
"<520000000800000003\n" +
">70000000076f6800\n" +
"<520000000800000000530000001154696d655a6f6e6500474d5400530000001d6170706c69636174696f6e5f6e616d6500517565737444420053000000187365727665725f76657273696f6e0031312e33005300000019696e74656765725f6461746574696d6573006f6e005300000019636c69656e745f656e636f64696e670055544638005a0000000549\n" +
">500000002c0073656c65637420782c202024312066726f6d206c6f6e675f73657175656e63652832293b000000\n" +
">4200000013000000010000000100000001330000\n" +
">44000000065000\n" +
">45000000090000000000\n" +
">4800000004\n" +
"<31000000043200000004540000002f00027800000040010001000000140004ffffffff0000243100000040010002000000170004ffffffff000044000000100002000000013100000001334400000010000200000001320000000133430000000d53454c454354203200\n";
assertHexScript(NetworkFacadeImpl.INSTANCE,
">5000000022005345542065787472615f666c6f61745f646967697473203d2033000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
">500000003700534554206170706c69636174696f6e5f6e616d65203d2027506f737467726553514c204a4442432044726976657227000000420000000c0000000000000000450000000900000000015300000004\n" +
"<310000000432000000044300000008534554005a0000000549\n" +
// II
">50000000740073656c65637420782c24312c24322c24332c24342c24352c24362c24372c24382c24392c2431302c2431312c2431322c2431332c2431342c2431352c2431362c2431372c2431382c2431392c2432302c2432312c2432322066726f6d206c6f6e675f73657175656e63652835290000160000001700000014000002bc000002bd0000001500000010000004130000041300000000000000000000001700000014000002bc000002bd000000150000001000000413000004130000043a000000000000045a000004a0420000012c0000001600010001000100010001000000000000000000000001000100010001000100000000000000010000000000000016000000040000000400000008000000000000007b0000000440adc28f000000083fe22c27a63736ce00000002005b00000004545255450000000568656c6c6f0000001dd0b3d180d183d0bfd0bfd0b020d182d183d180d0b8d181d182d0bed0b20000000e313937302d30312d3031202b30300000001a313937302d30382d32302031313a33333a32302e3033332b3030ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000001a313937302d30312d30312030303a30353a30302e3031312b30300000001a313937302d30312d30312030303a30383a32302e3032332b3030000044000000065000450000000900000000005300000004\n" +
"<!!";
assertHexScript(
NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
getHexPgWireConfig()
);
}
@Override
public String getDefaultUsername() {
return "xyz";
}
});
@Test
public void testPreparedStatementHex() throws Exception {
assertPreparedStatementHex(NetworkFacadeImpl.INSTANCE, getHexPgWireConfig());
}
@Test
......@@ -2333,17 +2338,7 @@ public class PGJobContextTest extends AbstractGriffinTest {
assertHexScript(NetworkFacadeImpl.INSTANCE,
NetworkFacadeImpl.INSTANCE,
script,
new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
@Override
public String getDefaultUsername() {
return "xyz";
}
});
getHexPgWireConfig());
}
......@@ -2391,6 +2386,7 @@ public class PGJobContextTest extends AbstractGriffinTest {
try {
insert.setInt(1, 10);
insert.execute();
Assert.fail();
} catch (SQLException e) {
TestUtils.assertContains(e.getMessage(), expectedError);
}
......@@ -2402,6 +2398,168 @@ public class PGJobContextTest extends AbstractGriffinTest {
});
}
@Test
public void testSimple() throws Exception {
testQuery("rnd_double(4) d, ", "s[VARCHAR],i[INTEGER],d[DOUBLE],t[TIMESTAMP],f[REAL],_short[SMALLINT],l[BIGINT],ts2[TIMESTAMP],bb[SMALLINT],b[BIT],rnd_symbol[VARCHAR],rnd_date[TIMESTAMP],rnd_bin[BINARY],rnd_char[CHAR],rnd_long256[NUMERIC]\n");
}
@Test
public void testUtf8QueryText() throws Exception {
testQuery(
"rnd_double(4) расход, ",
"s[VARCHAR],i[INTEGER],расход[DOUBLE],t[TIMESTAMP],f[REAL],_short[SMALLINT],l[BIGINT],ts2[TIMESTAMP],bb[SMALLINT],b[BIT],rnd_symbol[VARCHAR],rnd_date[TIMESTAMP],rnd_bin[BINARY],rnd_char[CHAR],rnd_long256[NUMERIC]\n"
);
}
/*
We want to ensure that tableoid is set to zero, otherwise squirrelSql will not display the result set.
*/
@Test
public void testThatTableOidIsSetToZero() throws Exception {
TestUtils.assertMemoryLeak(() -> {
final CountDownLatch haltLatch = new CountDownLatch(1);
final AtomicBoolean running = new AtomicBoolean(true);
try {
startBasicServer(
NetworkFacadeImpl.INSTANCE,
new DefaultPGWireConfiguration(),
haltLatch,
running
);
Properties properties = new Properties();
properties.setProperty("user", "admin");
properties.setProperty("password", "quest");
properties.setProperty("sslmode", "disable");
properties.setProperty("binaryTransfer", "false");
final Connection connection = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:9120/qdb", properties);
PreparedStatement statement = connection.prepareStatement("select 1,2,3 from long_sequence(1)");
ResultSet rs = statement.executeQuery();
assertTrue(((PGResultSetMetaData) rs.getMetaData()).getBaseColumnName(1).isEmpty()); // getBaseColumnName returns "" if tableOid is zero
rs.close();
connection.close();
} finally {
running.set(false);
haltLatch.await();
}
});
}
private void assertResultSet(String expected, StringSink sink, ResultSet rs) throws SQLException, IOException {
// dump metadata
ResultSetMetaData metaData = rs.getMetaData();
final int columnCount = metaData.getColumnCount();
for (int i = 0; i < columnCount; i++) {
if (i > 0) {
sink.put(',');
}
sink.put(metaData.getColumnName(i + 1));
sink.put('[').put(JDBCType.valueOf(metaData.getColumnType(i + 1)).name()).put(']');
}
sink.put('\n');
while (rs.next()) {
for (int i = 1; i <= columnCount; i++) {
if (i > 1) {
sink.put(',');
}
switch (JDBCType.valueOf(metaData.getColumnType(i))) {
case VARCHAR:
String stringValue = rs.getString(i);
if (rs.wasNull()) {
sink.put("null");
} else {
sink.put(stringValue);
}
break;
case INTEGER:
int intValue = rs.getInt(i);
if (rs.wasNull()) {
sink.put("null");
} else {
sink.put(intValue);
}
break;
case DOUBLE:
double doubleValue = rs.getDouble(i);
if (rs.wasNull()) {
sink.put("null");
} else {
sink.put(doubleValue, Numbers.MAX_SCALE);
}
break;
case TIMESTAMP:
Timestamp timestamp = rs.getTimestamp(i);
if (timestamp == null) {
sink.put("null");
} else {
sink.put(timestamp.toString());
}
break;
case REAL:
double floatValue = rs.getFloat(i);
if (rs.wasNull()) {
sink.put("null");
} else {
sink.put(floatValue, 4);
}
break;
case SMALLINT:
sink.put(rs.getShort(i));
break;
case BIGINT:
long longValue = rs.getLong(i);
if (rs.wasNull()) {
sink.put("null");
} else {
sink.put(longValue);
}
break;
case NUMERIC:
String long256Value = rs.getString(i);
if (rs.wasNull()) {
sink.put("null");
} else {
sink.put(long256Value);
}
break;
case CHAR:
char charValue = rs.getString(i).charAt(0);
if (rs.wasNull()) {
sink.put("null");
} else {
sink.put(charValue);
}
break;
case BIT:
sink.put(rs.getBoolean(i));
break;
case TIME:
Date date = rs.getDate(i);
if (date == null) {
sink.put("null");
} else {
sink.put(date.toString());
}
break;
case BINARY:
InputStream stream = rs.getBinaryStream(i);
if (stream == null) {
sink.put("null");
} else {
toSink(stream, sink);
}
break;
}
}
sink.put('\n');
}
TestUtils.assertEquals(expected, sink);
}
private void testQuery(String s, String s2) throws Exception {
TestUtils.assertMemoryLeak(() -> {
final CountDownLatch haltLatch = new CountDownLatch(1);
......@@ -2433,70 +2591,75 @@ public class PGJobContextTest extends AbstractGriffinTest {
"rnd_boolean() b, " +
"rnd_symbol(4,4,4,2), " +
"rnd_date(to_date('2015', 'yyyy'), to_date('2016', 'yyyy'), 2)," +
"rnd_bin(10,20,2) " +
"rnd_bin(10,20,2), " +
"rnd_char(), " +
"rnd_long256() " +
"from long_sequence(50)");
final String expected = s2 +
"null,57,0.6254021542412018,1970-01-01 00:00:00.0,0.4620,-1593,3425232,null,121,false,PEHN,2015-03-17 04:25:52.765,00000000 19 c4 95 94 36 53 49 b4 59 7e 3b 08 a1 1e\n" +
"XYSB,142,0.5793466326862211,1970-01-01 00:00:00.01,0.9689,20088,1517490,2015-01-17 20:41:19.480685,100,true,PEHN,2015-06-20 01:10:58.599,00000000 79 5f 8b 81 2b 93 4d 1a 8e 78 b5 b9 11 53 d0 fb\n" +
"00000010 64\n" +
"OZZV,219,0.16381374773748514,1970-01-01 00:00:00.02,0.6589,-12303,9489508,2015-08-13 17:10:19.752521,6,false,null,2015-05-20 01:48:37.418,00000000 2b 4d 5f f6 46 90 c3 b3 59 8e e5 61 2f 64 0e\n" +
"OLYX,30,0.7133910271555843,1970-01-01 00:00:00.03,0.6549,6610,6504428,2015-08-08 00:42:24.545639,123,false,null,2015-01-03 13:53:03.165,null\n" +
"TIQB,42,0.6806873134626418,1970-01-01 00:00:00.04,0.6259,-1605,8814086,2015-07-28 15:08:53.462495,28,true,CPSW,null,00000000 3b a6 dc 3b 7d 2b e3 92 fe 69 38 e1 77 9a\n" +
"LTOV,137,0.7632615004324503,1970-01-01 00:00:00.05,0.8820,9054,null,2015-04-20 05:09:03.580574,106,false,PEHN,2015-01-09 06:57:17.512,null\n" +
"ZIMN,125,null,1970-01-01 00:00:00.06,null,11524,8335261,2015-10-26 02:10:50.688394,111,true,PEHN,2015-08-21 15:46:32.624,null\n" +
"OPJO,168,0.10459352312331183,1970-01-01 00:00:00.07,0.5350,-5920,7080704,2015-07-11 09:15:38.342717,103,false,VTJW,null,null\n" +
"GLUO,145,0.5391626621794673,1970-01-01 00:00:00.08,0.7670,14242,2499922,2015-11-02 09:01:31.312804,84,false,PEHN,2015-11-14 17:37:36.043,null\n" +
"ZVQE,103,0.6729405590773638,1970-01-01 00:00:00.09,null,13727,7875846,2015-12-12 13:16:26.134562,22,true,PEHN,2015-01-20 04:50:34.098,00000000 14 33 80 c9 eb a3 67 7a 1a 79 e4 35 e4 3a dc 5c\n" +
"00000010 65 ff\n" +
"LIGY,199,0.2836347139481469,1970-01-01 00:00:00.1,null,30426,3215562,2015-08-21 14:55:07.055722,11,false,VTJW,null,00000000 ff 70 3a c7 8a b3 14 cd 47 0b 0c 39 12\n" +
"MQNT,43,0.5859332388599638,1970-01-01 00:00:00.11,0.3350,27019,null,null,27,true,PEHN,2015-07-12 12:59:47.665,00000000 26 fb 2e 42 fa f5 6e 8f 80 e3 54 b8 07 b1 32 57\n" +
"00000010 ff 9a ef\n" +
"WWCC,213,0.7665029914376952,1970-01-01 00:00:00.12,0.5799,13640,4121923,2015-08-06 02:27:30.469762,73,false,PEHN,2015-04-30 08:18:10.453,00000000 71 a7 d5 af 11 96 37 08 dd 98 ef 54 88 2a a2 ad\n" +
"00000010 e7 d4\n" +
"VFGP,120,0.8402964708129546,1970-01-01 00:00:00.13,0.7730,7223,7241423,2015-12-18 07:32:18.456025,43,false,VTJW,null,00000000 24 4e 44 a8 0d fe 27 ec 53 13 5d b2 15 e7 b8 35\n" +
"00000010 67\n" +
"RMDG,134,0.11047315214793696,1970-01-01 00:00:00.14,0.04300,21227,7155708,2015-07-03 04:12:45.774281,42,true,CPSW,2015-02-24 12:10:43.199,null\n" +
"WFOQ,255,null,1970-01-01 00:00:00.15,0.1159,31569,6688277,2015-05-19 03:30:45.779999,126,true,PEHN,2015-12-09 09:57:17.078,null\n" +
"MXDK,56,0.9997797234031688,1970-01-01 00:00:00.16,0.5230,-32372,6884132,null,58,false,null,2015-01-20 06:18:18.583,null\n" +
"XMKJ,139,0.8405815493567417,1970-01-01 00:00:00.17,0.3059,25856,null,2015-05-18 03:50:22.731437,2,true,VTJW,2015-06-25 10:45:01.014,00000000 00 7c fb 01 19 ca f2 bf 84 5a 6f 38 35\n" +
"VIHD,null,null,1970-01-01 00:00:00.18,0.5500,22280,9109842,2015-01-25 13:51:38.270583,94,false,CPSW,2015-10-27 02:52:19.935,00000000 2d 16 f3 89 a3 83 64 de d6 fd c4 5b c4 e9\n" +
"WPNX,null,0.9469700813926907,1970-01-01 00:00:00.19,0.4149,-17933,674261,2015-03-04 15:43:15.213686,43,true,HYRX,2015-12-18 21:28:25.325,00000000 b3 4c 0e 8f f1 0c c5 60 b7 d1\n" +
"YPOV,36,0.6741248448728824,1970-01-01 00:00:00.2,0.03099,-5888,1375423,2015-12-10 20:50:35.866614,3,true,null,2015-07-23 20:17:04.236,00000000 d4 ab be 30 fa 8d ac 3d 98 a0 ad 9a 5d\n" +
"NUHN,null,0.6940917925148332,1970-01-01 00:00:00.21,0.3389,-25226,3524748,2015-05-07 04:07:18.152968,39,true,VTJW,2015-04-04 15:23:34.13,00000000 b8 be f8 a1 46 87 28 92 a3 9b e3 cb c2 64 8a b0\n" +
"00000010 35 d8\n" +
"BOSE,240,0.06001827721556019,1970-01-01 00:00:00.22,0.3790,23904,9069339,2015-03-21 03:42:42.643186,84,true,null,null,null\n" +
"INKG,124,0.8615841627702753,1970-01-01 00:00:00.23,0.4040,-30383,7233542,2015-07-21 16:42:47.012148,99,false,null,2015-08-27 17:25:35.308,00000000 87 fc 92 83 fc 88 f3 32 27 70 c8 01 b0 dc c9 3a\n" +
"00000010 5b 7e\n" +
"FUXC,52,0.7430101994511517,1970-01-01 00:00:00.24,null,-14729,1042064,2015-08-21 02:10:58.949674,28,true,CPSW,2015-08-29 20:15:51.835,null\n" +
"UNYQ,71,0.442095410281938,1970-01-01 00:00:00.25,0.5389,-22611,null,2015-12-23 18:41:42.319859,98,true,PEHN,2015-01-26 00:55:50.202,00000000 28 ed 97 99 d8 77 33 3f b2 67 da 98 47 47 bf\n" +
"KBMQ,null,0.28019218825051395,1970-01-01 00:00:00.26,null,12240,null,2015-08-16 01:02:55.766622,21,false,null,2015-05-19 00:47:18.698,00000000 6a de 46 04 d3 81 e7 a2 16 22 35 3b 1c\n" +
"JSOL,243,null,1970-01-01 00:00:00.27,0.06800,-17468,null,null,20,true,null,2015-06-19 10:38:54.483,00000000 3d e0 2d 04 86 e7 ca 29 98 07 69 ca 5b d6 cf 09\n" +
"00000010 69\n" +
"HNSS,150,null,1970-01-01 00:00:00.28,0.1480,14841,5992443,null,25,false,PEHN,null,00000000 14 d6 fc ee 03 22 81 b8 06 c4 06 af\n" +
"PZPB,101,0.061646717786158045,1970-01-01 00:00:00.29,null,12237,9878179,2015-09-03 22:13:18.852465,79,false,VTJW,2015-12-17 15:12:54.958,00000000 12 61 3a 9a ad 98 2e 75 52 ad 62 87 88 45 b9 9d\n" +
"OYNN,25,0.3393509514000247,1970-01-01 00:00:00.3,0.6280,22412,4736378,2015-10-10 12:19:42.528224,106,true,CPSW,2015-07-01 00:23:49.789,00000000 54 13 3f ff b6 7e cd 04 27 66 94 89 db\n" +
"null,117,0.5638404775663161,1970-01-01 00:00:00.31,null,-5604,6353018,null,84,false,null,null,00000000 2b ad 25 07 db 62 44 33 6e 00 8e\n" +
"HVRI,233,0.22407665790705777,1970-01-01 00:00:00.32,0.4250,10469,1715213,null,86,false,null,2015-02-02 05:48:17.373,null\n" +
"OYTO,96,0.7407581616916364,1970-01-01 00:00:00.33,0.5279,-12239,3499620,2015-02-07 22:35:03.212268,17,false,PEHN,2015-03-29 12:55:11.682,null\n" +
"LFCY,63,0.7217315729790722,1970-01-01 00:00:00.34,null,23344,9523982,null,123,false,CPSW,2015-05-18 04:35:27.228,00000000 05 e5 c0 4e cc d6 e3 7b 34 cd 15 35 bb a4\n" +
"GHLX,148,0.3057937704964272,1970-01-01 00:00:00.35,0.6359,-31457,2322337,2015-10-22 12:06:05.544701,91,true,HYRX,2015-05-21 09:33:18.158,00000000 57 1d 91 72 30 04 b7 02 cb 03\n" +
"YTSZ,123,null,1970-01-01 00:00:00.36,0.5189,22534,4446236,2015-07-27 07:23:37.233711,53,false,CPSW,2015-01-13 04:37:10.036,null\n" +
"SWLU,251,null,1970-01-01 00:00:00.37,0.1790,7734,4082475,2015-10-21 18:24:34.400345,69,false,PEHN,2015-04-01 14:33:42.005,null\n" +
"TQJL,245,null,1970-01-01 00:00:00.38,0.8650,9516,929340,2015-05-28 04:18:18.640567,69,false,VTJW,2015-06-12 20:12:28.881,00000000 6c 3e 51 d7 eb b1 07 71 32 1f af 40 4e 8c 47\n" +
"REIJ,94,null,1970-01-01 00:00:00.39,0.1299,-29924,null,2015-03-20 22:14:46.204718,113,true,HYRX,2015-12-19 13:58:41.819,null\n" +
"HDHQ,94,0.7234181773407536,1970-01-01 00:00:00.4,0.7300,19970,654131,2015-01-10 22:56:08.48045,84,true,null,2015-03-05 17:14:48.275,00000000 4f 56 6b 65 a4 53 38 e9 cd c1 a7 ee 86 75 ad a5\n" +
"00000010 2d 49\n" +
"UMEU,40,0.008444033230580739,1970-01-01 00:00:00.41,0.8050,-11623,4599862,2015-11-20 04:02:44.335947,76,false,PEHN,2015-05-17 17:33:20.922,null\n" +
"YJIH,184,null,1970-01-01 00:00:00.42,0.3829,17614,3101671,2015-01-28 12:05:46.683001,105,true,null,2015-12-07 19:24:36.838,00000000 ec 69 cd 73 bb 9b c5 95 db 61 91 ce\n" +
"CYXG,27,0.2917796053045747,1970-01-01 00:00:00.43,0.9530,3944,249165,null,67,true,null,2015-03-02 08:19:44.566,00000000 01 48 15 3e 0c 7f 3f 8f e4 b5 ab 34 21 29\n" +
"MRTG,143,0.02632531361499113,1970-01-01 00:00:00.44,0.9430,-27320,1667842,2015-01-24 19:56:15.973109,11,false,null,2015-01-24 07:15:02.772,null\n" +
"DONP,246,0.654226248740447,1970-01-01 00:00:00.45,0.5559,27477,4160018,2015-12-14 03:40:05.911839,20,true,PEHN,2015-10-29 14:35:10.167,00000000 07 92 01 f5 6a a1 31 cd cb c2 a2 b4 8e 99\n" +
"IQXS,232,0.23075700218038853,1970-01-01 00:00:00.46,0.04899,-18113,4005228,2015-06-11 13:00:07.248188,8,true,CPSW,2015-08-16 11:09:24.311,00000000 fa 1f 92 24 b1 b8 67 65 08 b7 f8 41 00\n" +
"null,178,null,1970-01-01 00:00:00.47,0.9029,-14626,2934570,2015-04-04 08:51:54.068154,88,true,null,2015-07-01 04:32:23.083,00000000 84 36 25 63 2b 63 61 43 1c 47 7d b6 46 ba bb 98\n" +
"00000010 ca 08 be a4\n" +
"HUWZ,94,0.110401374979613,1970-01-01 00:00:00.48,0.4199,-3736,5687514,2015-01-02 17:18:05.627633,74,false,null,2015-03-29 06:39:11.642,null\n" +
"SRED,66,0.11274667140915928,1970-01-01 00:00:00.49,0.05999,-10543,3669377,2015-10-22 02:53:02.381351,77,true,PEHN,null,00000000 7c 3f d6 88 3a 93 ef 24 a5 e2 bc\n";
"null,57,0.6254021542412018,1970-01-01 00:00:00.0,0.4620,-1593,3425232,null,121,false,PEHN,2015-03-17 04:25:52.765,00000000 19 c4 95 94 36 53 49 b4 59 7e 3b 08 a1 1e,D,0x5f20a35e80e154f458dfd08eeb9cc39ecec82869edec121bc2593f82b430328d\n" +
"OUOJ,77,null,1970-01-01 00:00:00.01,0.6759,-7374,7777791,2015-06-19 08:47:45.603182,53,true,null,2015-11-10 09:50:33.215,00000000 8b 81 2b 93 4d 1a 8e 78 b5 b9 11 53 d0 fb 64 bb\n" +
"00000010 1a d4 f0,V,0xbedf29efb28cdcb1b75dccbdf1f8b84b9b27eba5e9cfa1e29660300cea7db540\n" +
"ICCX,205,0.8837421918800907,1970-01-01 00:00:00.02,0.05400,6093,4552960,2015-07-17 00:50:59.787742,33,false,VTJW,2015-07-15 01:06:11.226,00000000 e5 61 2f 64 0e 2c 7f d7 6f b8 c9 ae 28 c7 84 47,U,0x8b4e4831499fc2a526567f4430b46b7f78c594c496995885aa1896d0ad3419d2\n" +
"GSHO,31,0.34947269997137365,1970-01-01 00:00:00.03,0.1979,10795,6406207,2015-05-22 14:59:41.673422,56,false,null,null,00000000 49 1c f2 3c ed 39 ac a8 3b a6,S,0x7eb6d80649d1dfe38e4a7f661df6c32b2f171b3f06f6387d2fd2b4a60ba2ba3b\n" +
"HZEP,180,0.06944480046327317,1970-01-01 00:00:00.04,0.4300,21347,null,2015-02-07 10:02:13.600956,41,false,HYRX,null,00000000 ea c3 c9 73 93 46 fe c2 d3 68 79 8b 43 1d 57 34,F,0x38e4be9e19321b57832dd27952d949d8691dd4412a2d398d4fc01e2b9fd11623\n" +
"HWVD,38,0.48524046868499715,1970-01-01 00:00:00.05,0.6800,25579,5575751,2015-10-19 12:38:49.360294,15,false,VTJW,2015-02-06 22:58:50.333,null,Q,0x85134468025aaeb0a2f8bbebb989ba609bb0f21ac9e427283eef3f158e084362\n" +
"PGLU,97,0.029227696942726644,1970-01-01 00:00:00.06,0.1720,-18912,8340272,2015-05-24 22:09:55.175991,111,false,VTJW,2015-11-08 21:57:22.812,00000000 d9 6f 04 ab 27 47 8f 23 3f ae 7c 9f 77 04 e9 0c\n" +
"00000010 ea 4e ea 8b,K,0x55d3686d5da27e14255a91b0e28abeb36c3493fcb2d0272d6046e5d137dd8f0f\n" +
"WIFF,104,0.892454783921197,1970-01-01 00:00:00.07,0.09300,28218,4009057,2015-02-18 07:26:10.141055,89,false,HYRX,null,00000000 29 26 c5 aa da 18 ce 5f b2 8b 5c 54 90 25 c2 20\n" +
"00000010 ff,R,0x55b0586d1c02dfb399904624c49b6d8a7d85ee2916b209c779406ab1f85e333a\n" +
"CLTJ,115,0.2093569947644236,1970-01-01 00:00:00.08,0.5460,-8207,2378718,2015-04-21 12:25:43.291916,31,false,PEHN,null,00000000 a5 db a1 76 1c 1c 26 fb 2e 42 fa,F,0x483c83d88ac674e3894499a1a1680580cfedff23a67d918fb49b3c24e456ad6e\n" +
"HFLP,79,0.9130151105125102,1970-01-01 00:00:00.09,null,14667,2513248,2015-08-31 13:16:12.318782,3,false,null,2015-02-08 12:28:36.066,null,U,0x79423d4d320d2649767a4feda060d4fb6923c0c7d965969da1b1140a2be25241\n" +
"GLNY,138,0.7165847318191405,1970-01-01 00:00:00.1,0.7530,-2666,9337379,2015-03-25 09:21:52.776576,111,false,HYRX,2015-01-24 15:23:13.092,00000000 62 e1 4e d6 b2 57 5b e3 71 3d 20 e2 37 f2 64 43,Y,0xaac42ccbc493cf44aa6a0a1d4cdf40dd6ae4fd257e4412a07f19777ec1368055\n" +
"VTNP,237,0.29242748475227853,1970-01-01 00:00:00.11,0.7530,-26861,2354132,2015-02-10 18:27:11.140675,56,true,null,2015-02-25 00:45:15.363,00000000 28 b6 a9 17 ec 0e 01 c4 eb 9f 13 8f bb 2a 4b,O,0x926cdd99e63abb35650d1fb462d014df59070392ef6aa389932e4b508e35428f\n" +
"WFOQ,255,null,1970-01-01 00:00:00.12,0.1159,31569,6688277,2015-05-19 03:30:45.779999,126,true,PEHN,2015-12-09 09:57:17.078,null,E,0x4f38804270a4a64349b5760a687d8cf838cbb9ae96e9ecdc745ed9faeb513ad3\n" +
"EJCT,195,0.13312214396754163,1970-01-01 00:00:00.13,0.9440,-3013,null,2015-11-03 14:54:47.524015,114,true,PEHN,2015-08-28 07:41:29.952,00000000 fb 9d 63 ca 94 00 6b dd 18 fe 71 76 bc 45 24 cd\n" +
"00000010 13 00 7c,R,0x3cfe50b9cabaf1f29e0dcffb7520ebcac48ad6b8f6962219b27b0ac7fbdee201\n" +
"JYYF,249,0.2000682450929353,1970-01-01 00:00:00.14,0.6019,5869,2079217,2015-07-10 18:16:38.882991,44,true,HYRX,null,00000000 b7 6c 4b fb 2d 16 f3 89 a3 83 64 de d6 fd c4 5b\n" +
"00000010 c4 e9 19 47,P,0x85e70b46349799fe49f783d5343dd7bc3d3fe1302cd3371137fccdabf181b5ad\n" +
"TZOD,null,0.36078878996232167,1970-01-01 00:00:00.15,0.6010,-23125,5083310,null,11,false,VTJW,2015-09-19 18:14:57.59,00000000 c5 60 b7 d1 5a 0c e9 db 51 13 4d 59 20 c9 37 a1\n" +
"00000010 00,E,0xcff85f9258847e03a6f2e2a772cd2f3751d822a67dff3d2375166223a6181642\n" +
"PBMB,76,0.23567419576658333,1970-01-01 00:00:00.16,0.5709,26284,null,2015-05-21 13:14:56.349036,45,true,null,2015-09-11 09:34:39.05,00000000 97 cb f6 2c 23 45 a3 76 60 15,M,0x3c3a3b7947ce8369926cbcb16e9a2f11cfab70f2d175d0d9aeb989be79cd2b8c\n" +
"TKRI,201,0.2625424312419562,1970-01-01 00:00:00.17,0.9150,-5486,9917162,2015-05-03 03:59:04.256719,66,false,VTJW,2015-01-15 03:22:01.033,00000000 a1 f5 4b ea 01 c9 63 b4 fc 92 60 1f df 41 ec 2c,O,0x4e3e15ad49e0a859312981a73c9dfce79022a75a739ee488eefa2920026dba88\n" +
"NKGQ,174,0.4039042639581232,1970-01-01 00:00:00.18,0.4379,20687,7315329,2015-07-25 04:52:27.724869,20,false,PEHN,2015-06-10 22:28:57.01,00000000 92 83 fc 88 f3 32 27 70 c8 01 b0,T,0x579b14c2725d7a7e5dfbd8e23498715b8d9ee30e7bcbf83a6d1b1c80f012a4c9\n" +
"FUXC,52,0.7430101994511517,1970-01-01 00:00:00.19,null,-14729,1042064,2015-08-21 02:10:58.949674,28,true,CPSW,2015-08-29 20:15:51.835,null,X,0x41457ebc5a02a2b542cbd49414e022a06f4aa2dc48a9a4d99288224be334b250\n" +
"TGNJ,159,0.9562577128401444,1970-01-01 00:00:00.2,0.2509,795,5069730,2015-07-01 01:36:57.101749,71,true,PEHN,2015-09-12 05:41:59.999,00000000 33 3f b2 67 da 98 47 47 bf 4f ea 5f 48 ed,M,0x4ba20a8e0cf7c53c9f527485c4aac4a2826f47baacd58b28700a67f6119c63bb\n" +
"HCNP,173,0.18684267640195917,1970-01-01 00:00:00.21,0.6880,-14882,8416858,2015-06-16 19:31:59.812848,25,false,HYRX,2015-09-30 17:28:24.113,00000000 1d 5c c1 5d 2d 44 ea 00 81 c4 19 a1 ec 74 f8 10\n" +
"00000010 fc 6e 23,D,0x3d64559865f84c86488be951819f43042f036147c78e0b2d127ca5db2f41c5e0\n" +
"EZBR,243,0.8203418140538824,1970-01-01 00:00:00.22,0.2210,-8447,4677168,2015-03-24 03:32:39.832378,78,false,CPSW,2015-02-16 04:04:19.082,00000000 42 67 78 47 b3 80 69 b9 14 d6 fc ee 03 22 81 b8,Q,0x721304ffe1c934386466208d506905af40c7e3bce4b28406783a3945ab682cc4\n" +
"ZPBH,131,0.1999576586778039,1970-01-01 00:00:00.23,0.4790,-18951,874555,2015-12-22 19:13:55.404123,52,false,null,2015-10-03 05:16:17.891,null,Z,0xa944baa809a3f2addd4121c47cb1139add4f1a5641c91e3ab81f4f0ca152ec61\n" +
"VLTP,196,0.4104855595304533,1970-01-01 00:00:00.24,0.9179,-12269,142107,2015-10-10 18:27:43.423774,92,false,PEHN,2015-02-06 18:42:24.631,null,H,0x5293ce3394424e6a5ae63bdf09a84e32bac4484bdeec40e887ec84d015101766\n" +
"RUMM,185,null,1970-01-01 00:00:00.25,0.8379,-27649,3639049,2015-05-06 00:51:57.375784,89,true,PEHN,null,null,W,0x3166ed3bbffb858312f19057d95341886360c99923d254f38f22547ae9661423\n" +
"null,71,0.7409092302023607,1970-01-01 00:00:00.26,0.7419,-18837,4161180,2015-04-22 10:19:19.162814,37,true,HYRX,2015-09-23 03:14:56.664,00000000 8e 93 bd 27 42 f8 25 2a 42 71 a3 7a 58 e5,D,0x689a15d8906770fcaefe0266b9f63bd6698c574248e9011c6cc84d9a6d41e0b8\n" +
"NGZT,214,0.18170646835643245,1970-01-01 00:00:00.27,0.8410,21764,3231872,null,79,false,HYRX,2015-05-20 07:51:29.675,00000000 ab ab ac 21 61 99 be 2d f5 30 78 6d 5a 3b,H,0x5b8def4e7a017e884a3c2c504403708b49fb8d5fe0ff283cbac6499e71ce5b30\n" +
"EYYP,13,null,1970-01-01 00:00:00.28,0.5339,19136,4658108,2015-08-20 05:26:04.061614,5,false,CPSW,2015-03-23 23:43:37.634,00000000 c8 66 0c 40 71 ea 20 7e 43 97 27 1f 5c d9 ee 04\n" +
"00000010 5b 9c,C,0x6e6ed811e25486953f35987a50016bbf481e9f55c33ac48c6a22b0bd6f7b0bf2\n" +
"GMPL,50,0.7902682918274309,1970-01-01 00:00:00.29,0.8740,-27807,5693029,2015-07-14 21:06:07.975747,37,true,CPSW,2015-09-01 04:00:29.049,00000000 3b 4b b7 e2 7f ab 6e 23 03 dd c7 d6,U,0x72c607b1992ff2f8802e839b77a4a2d34b8b967c412e7c895b509b55d1c38d29\n" +
"BCZI,207,0.10863061577000221,1970-01-01 00:00:00.3,0.1289,3999,121232,null,88,true,CPSW,2015-05-10 21:10:20.041,00000000 97 0b f5 ef 3b be 85 7c 11 f7 34,K,0x33be4c04695f74d776ac6df71a221f518f3c64248fb5943ea55ab4e6916f3f6c\n" +
"DXUU,139,null,1970-01-01 00:00:00.31,0.2619,-15289,341060,2015-01-06 07:48:24.624773,110,false,null,2015-07-08 18:37:16.872,00000000 71 cf 5a 8f 21 06 b2 3f 0e 41 93 89 27 ca 10 2f\n" +
"00000010 60 ce,N,0x1c05d81633694e02795ebacfceb0c7dd7ec9b7e9c634bc791283140ab775531c\n" +
"FMDV,197,0.2522102209201954,1970-01-01 00:00:00.32,0.9929,-26026,5396438,null,83,true,CPSW,null,00000000 86 75 ad a5 2d 49 48 68 36 f0 35,K,0x308a7a4966e65a0160b00229634848957fa67d6a419e1721b1520f66caa74945\n" +
"SQCN,62,0.11500943478849246,1970-01-01 00:00:00.33,0.5950,1011,4631412,null,56,false,VTJW,null,null,W,0x66906dc1f1adbc206a8bf627c859714a6b841d6c6c8e44ce147261f8689d9250\n" +
"QSCM,130,0.8671405978559277,1970-01-01 00:00:00.34,0.4280,22899,403193,null,21,true,PEHN,2015-11-30 21:04:32.865,00000000 a0 ba a5 d1 63 ca 32 e5 0d 68 52 c6 94 c3 18 c9\n" +
"00000010 7c,I,0x3dcc3621f3734c485bb81c28ec2ddb0163def06fb4e695dc2bfa47b82318ff9f\n" +
"UUZI,196,0.9277429447320458,1970-01-01 00:00:00.35,0.625,24355,5761736,null,116,false,null,2015-02-04 07:15:26.997,null,B,0xb0a5224248b093a067eee4529cce26c37429f999bffc9548aa3df14bfed42969\n" +
"DEQN,41,0.9028381160965113,1970-01-01 00:00:00.36,0.1199,29066,2545404,2015-04-07 21:58:14.714791,125,false,PEHN,2015-02-06 23:29:49.836,00000000 ec 4b 97 27 df cd 7a 14 07 92 01,I,0x55016acb254b58cd3ce05caab6551831683728ff2f725aa1ba623366c2d08e6a\n" +
"null,164,0.7652775387729266,1970-01-01 00:00:00.37,0.3120,-8563,7684501,2015-02-01 12:38:28.322282,0,true,HYRX,2015-07-16 20:11:51.34,null,F,0x97af9db84b80545ecdee65143cbc92f89efea4d0456d90f29dd9339572281042\n" +
"QJPL,160,0.1740035812230043,1970-01-01 00:00:00.38,0.7630,5991,2099269,2015-02-25 15:49:06.472674,65,true,VTJW,2015-04-23 11:15:13.065,00000000 de 58 45 d0 1b 58 be 33 92 cd 5c 9d,E,0xa85a5fc20776e82b36c1cdbfe34eb2636eec4ffc0b44f925b09ac4f09cb27f36\n" +
"BKUN,208,0.4452148524967028,1970-01-01 00:00:00.39,0.5820,17928,6383721,2015-10-23 07:12:20.730424,7,false,null,2015-01-02 17:04:58.959,00000000 5e 37 e4 68 2a 96 06 46 b6 aa,F,0xe1d2020be2cb7be9c5b68f9ea1bd30c789e6d0729d44b64390678b574ed0f592\n" +
"REDS,4,0.03804995327454719,1970-01-01 00:00:00.4,0.1030,2358,1897491,2015-07-21 16:34:14.571565,75,false,CPSW,2015-07-30 16:04:46.726,00000000 d6 88 3a 93 ef 24 a5 e2 bc 86,P,0x892458b34e8769928647166465305ef1dd668040845a10a38ea5fba6cf9bfc92\n" +
"MPVR,null,null,1970-01-01 00:00:00.41,0.5920,8754,5828044,2015-10-05 21:11:10.600851,116,false,CPSW,null,null,H,0x9d1e67c6be2f24b2a4e2cc6a628c94395924dadabaed7ee459b2a61b0fcb74c5\n" +
"KKNZ,186,0.8223388398922372,1970-01-01 00:00:00.42,0.7200,-6179,8728907,null,80,true,VTJW,2015-09-11 03:49:12.244,00000000 16 b2 d8 83 f5 95 7c 95 fd 52 bb 50 c9,B,0x55724661cfcc811f4482e1a2ba8efaef6e4aef0394801c40941d89f24081f64d\n" +
"BICL,182,0.7215695095610233,1970-01-01 00:00:00.43,0.2269,-22899,6401660,2015-08-23 18:31:29.931618,78,true,null,null,null,T,0xbbb751ee10f060d1c2fbeb73044504aea55a8e283bcf857b539d8cd889fa9c91\n" +
"SWPF,null,0.48770772310128674,1970-01-01 00:00:00.44,0.9139,-17929,8377336,2015-12-13 23:04:20.465454,28,false,HYRX,2015-10-31 13:37:01.327,00000000 b2 31 9c 69 be 74 9a ad cc cf b8 e4 d1 7a 4f,I,0xbe91d734443388a2a631d716b575c819c9224a25e3f6e6fa6cd78093d5e7ea16\n" +
"BHEV,80,0.8917678500174907,1970-01-01 00:00:00.45,0.2370,29284,9577513,2015-10-20 07:38:23.889249,27,false,HYRX,2015-12-15 13:32:56.797,00000000 92 83 24 53 60 4d 04 c2 f0 7a 07 d4 a3 d1 5f 0d\n" +
"00000010 fe 63 10 0d,V,0x225fddd0f4325a9d8634e1cb317338a0d3cb7f61737f167dc902b6f6d779c753\n" +
"DPCH,62,0.6684502332750604,1970-01-01 00:00:00.46,0.8790,-22600,9266553,null,89,true,VTJW,2015-05-25 19:42:17.955,00000000 35 1b b9 0f 97 f5 77 7e a3 2d ce fe eb cd 47 06\n" +
"00000010 53 61 97,S,0x89d6a43b23f83695b236ae5ffab54622ce1f4dac846490a8b88f0468c0cbfa33\n" +
"MKNJ,61,0.2682009935575007,1970-01-01 00:00:00.47,0.8130,-1322,null,2015-11-04 08:11:39.996132,4,false,CPSW,2015-07-29 22:51:03.349,00000000 82 08 fb e7 94 3a 32 5d 8a 66 0b e4 85 f1 13 06\n" +
"00000010 f2 27,V,0x9890d4aea149f0498bdef1c6ba16dd8cbd01cf83632884ae8b7083f888554b0c\n" +
"GSQI,158,0.8047954890194065,1970-01-01 00:00:00.48,0.3470,23139,1252385,2015-04-22 00:10:12.067311,32,true,null,2015-01-09 06:06:32.213,00000000 38 a7 85 46 1a 27 5b 4d 0f 33 f4 70,V,0xc0e6e110b909e13a812425a38162be0bb65e29ed529d4dba868a7075f3b34357\n" +
"BPTU,205,0.430214712409255,1970-01-01 00:00:00.49,0.9049,31266,8271557,2015-01-07 05:53:03.838005,14,true,VTJW,2015-10-30 05:33:15.819,00000000 24 0b c5 1a 5a 8d 85 50 39 42 9e 8a 86 17 89 6b,S,0x4e272e9dfde7bb12618178f7feba5021382a8c47a28fefa475d743cf0c2c4bcd\n";
StringSink sink = new StringSink();
......@@ -2509,4 +2672,19 @@ public class PGJobContextTest extends AbstractGriffinTest {
}
});
}
@NotNull
private DefaultPGWireConfiguration getHexPgWireConfig() {
return new DefaultPGWireConfiguration() {
@Override
public String getDefaultPassword() {
return "oh";
}
@Override
public String getDefaultUsername() {
return "xyz";
}
};
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册