Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDataType generic restriction #295

Merged
merged 8 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
org.slf4j.simpleLogger.defaultLogLevel=TRACE
org.slf4j.simpleLogger.log.com.github.housepower.jdbc.connect.NativeClient=TRACE
org.slf4j.simpleLogger.log.com.github.housepower.connect.NativeClient=TRACE
org.slf4j.simpleLogger.showDateTime=true
org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss
org.slf4j.simpleLogger.showThreadName=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* limitations under the License.
*/

package com.github.housepower.jdbc.annotation;
package com.github.housepower.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* limitations under the License.
*/

package com.github.housepower.jdbc.buffer;
package com.github.housepower.buffer;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* limitations under the License.
*/

package com.github.housepower.jdbc.buffer;
package com.github.housepower.buffer;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* limitations under the License.
*/

package com.github.housepower.jdbc.buffer;
package com.github.housepower.buffer;

import java.io.IOException;
import java.nio.ByteBuffer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* limitations under the License.
*/

package com.github.housepower.jdbc.buffer;
package com.github.housepower.buffer;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
* limitations under the License.
*/

package com.github.housepower.jdbc.buffer;
package com.github.housepower.buffer;

import com.github.housepower.jdbc.misc.ClickHouseCityHash;
import com.github.housepower.misc.ClickHouseCityHash;

import net.jpountz.lz4.LZ4Compressor;
import net.jpountz.lz4.LZ4Factory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
* limitations under the License.
*/

package com.github.housepower.jdbc.buffer;
package com.github.housepower.buffer;

import com.github.housepower.jdbc.settings.ClickHouseDefines;
import com.github.housepower.settings.ClickHouseDefines;

import java.io.EOFException;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* limitations under the License.
*/

package com.github.housepower.jdbc.buffer;
package com.github.housepower.buffer;

import java.io.IOException;
import java.io.OutputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
* limitations under the License.
*/

package com.github.housepower.jdbc.connect;

import com.github.housepower.jdbc.buffer.SocketBuffedReader;
import com.github.housepower.jdbc.buffer.SocketBuffedWriter;
import com.github.housepower.jdbc.data.Block;
import com.github.housepower.jdbc.misc.Validate;
import com.github.housepower.jdbc.protocol.*;
import com.github.housepower.jdbc.serde.BinaryDeserializer;
import com.github.housepower.jdbc.serde.BinarySerializer;
import com.github.housepower.jdbc.settings.ClickHouseConfig;
import com.github.housepower.jdbc.settings.ClickHouseDefines;
import com.github.housepower.jdbc.settings.SettingKey;
import com.github.housepower.jdbc.log.Logger;
import com.github.housepower.jdbc.log.LoggerFactory;
import com.github.housepower.jdbc.stream.QueryResult;
import com.github.housepower.jdbc.stream.ClickHouseQueryResult;
package com.github.housepower.client;

import com.github.housepower.buffer.SocketBuffedReader;
import com.github.housepower.buffer.SocketBuffedWriter;
import com.github.housepower.data.Block;
import com.github.housepower.misc.Validate;
import com.github.housepower.protocol.*;
import com.github.housepower.serde.BinaryDeserializer;
import com.github.housepower.serde.BinarySerializer;
import com.github.housepower.settings.ClickHouseConfig;
import com.github.housepower.settings.ClickHouseDefines;
import com.github.housepower.settings.SettingKey;
import com.github.housepower.log.Logger;
import com.github.housepower.log.LoggerFactory;
import com.github.housepower.stream.QueryResult;
import com.github.housepower.stream.ClickHouseQueryResult;

import java.io.IOException;
import java.net.InetSocketAddress;
Expand Down Expand Up @@ -80,7 +80,7 @@ public SocketAddress address() {

public boolean ping(Duration soTimeout, NativeContext.ServerContext info) {
try {
sendRequest(new PingRequest());
sendRequest(PingRequest.INSTANCE);
while (true) {
Response response = receiveResponse(soTimeout, info);

Expand Down Expand Up @@ -149,7 +149,7 @@ public void disconnect() throws SQLException {
LOG.info("socket already closed, ignore");
return;
}
LOG.debug("flush and close socket");
LOG.trace("flush and close socket");
serializer.flushToTarget(true);
socket.close();
} catch (IOException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
* limitations under the License.
*/

package com.github.housepower.jdbc.connect;
package com.github.housepower.client;

import com.github.housepower.jdbc.protocol.QueryRequest.ClientContext;
import com.github.housepower.jdbc.settings.ClickHouseConfig;
import com.github.housepower.protocol.QueryRequest.ClientContext;
import com.github.housepower.settings.ClickHouseConfig;

import java.time.ZoneId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* limitations under the License.
*/

package com.github.housepower.jdbc.connect;
package com.github.housepower.client;

public enum SessionState {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
* limitations under the License.
*/

package com.github.housepower.jdbc.data;
package com.github.housepower.data;

public abstract class AbstractColumn implements IColumn {

protected final String name;
protected final IDataType type;
protected final IDataType<?, ?> type;

// Note: values is only for reading
protected Object[] values;
protected ColumnWriterBuffer buffer;

public AbstractColumn(String name, IDataType type, Object[] values) {
public AbstractColumn(String name, IDataType<?, ?> type, Object[] values) {
this.name = name;
this.type = type;
this.values = values;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
* limitations under the License.
*/

package com.github.housepower.jdbc.data;
package com.github.housepower.data;

import com.github.housepower.jdbc.connect.NativeContext;
import com.github.housepower.jdbc.data.BlockSettings.Setting;
import com.github.housepower.jdbc.misc.Validate;
import com.github.housepower.jdbc.serde.BinaryDeserializer;
import com.github.housepower.jdbc.serde.BinarySerializer;
import com.github.housepower.client.NativeContext;
import com.github.housepower.data.BlockSettings.Setting;
import com.github.housepower.misc.Validate;
import com.github.housepower.serde.BinaryDeserializer;
import com.github.housepower.serde.BinarySerializer;

import java.io.IOException;
import java.sql.SQLException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
* limitations under the License.
*/

package com.github.housepower.jdbc.data;
package com.github.housepower.data;

import com.github.housepower.jdbc.serde.BinaryDeserializer;
import com.github.housepower.jdbc.serde.BinarySerializer;
import com.github.housepower.serde.BinaryDeserializer;
import com.github.housepower.serde.BinarySerializer;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
* limitations under the License.
*/

package com.github.housepower.jdbc.data;
package com.github.housepower.data;

import com.github.housepower.jdbc.serde.BinarySerializer;
import com.github.housepower.serde.BinarySerializer;

import java.io.IOException;
import java.sql.SQLException;

public class Column extends AbstractColumn {

public Column(String name, IDataType type, Object[] values) {
public Column(String name, IDataType<?, ?> type, Object[] values) {
super(name, type, values);
this.values = values;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
* limitations under the License.
*/

package com.github.housepower.jdbc.data;
package com.github.housepower.data;

import com.github.housepower.jdbc.ClickHouseArray;
import com.github.housepower.jdbc.data.type.complex.DataTypeArray;
import com.github.housepower.jdbc.serde.BinarySerializer;
import com.github.housepower.data.type.complex.DataTypeArray;
import com.github.housepower.serde.BinarySerializer;

import java.io.IOException;
import java.sql.SQLException;
Expand All @@ -37,7 +37,7 @@ public ColumnArray(String name, DataTypeArray type, Object[] values) {

@Override
public void write(Object object) throws IOException, SQLException {
Object[] arr = (Object[]) ((ClickHouseArray) object).getArray();
Object[] arr = ((ClickHouseArray) object).getArray();

offsets.add(offsets.isEmpty() ? arr.length : offsets.get((offsets.size() - 1)) + arr.length);
for (Object field : arr) {
Expand All @@ -60,7 +60,7 @@ public void flushToSerializer(BinarySerializer serializer, boolean immediate) th
}
}

public void flushOffsets(BinarySerializer serializer) throws IOException, SQLException {
public void flushOffsets(BinarySerializer serializer) throws IOException {
for (long offsetList : offsets) {
serializer.writeLong(offsetList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
* limitations under the License.
*/

package com.github.housepower.jdbc.data;
package com.github.housepower.data;

import com.github.housepower.jdbc.data.type.complex.DataTypeArray;
import com.github.housepower.jdbc.data.type.complex.DataTypeNullable;
import com.github.housepower.jdbc.data.type.complex.DataTypeTuple;
import com.github.housepower.data.type.complex.DataTypeArray;
import com.github.housepower.data.type.complex.DataTypeNullable;
import com.github.housepower.data.type.complex.DataTypeTuple;

import java.sql.Types;

public class ColumnFactory {

public static IColumn createColumn(String name, IDataType type, Object[] values) {
public static IColumn createColumn(String name, IDataType<?, ?> type, Object[] values) {
if (type.sqlTypeId() == Types.ARRAY) {
return new ColumnArray(name, (DataTypeArray) type, values);
} else if (type.nullable()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
* limitations under the License.
*/

package com.github.housepower.jdbc.data;
package com.github.housepower.data;

import com.github.housepower.jdbc.data.type.complex.DataTypeNullable;
import com.github.housepower.jdbc.serde.BinarySerializer;
import com.github.housepower.data.type.complex.DataTypeNullable;
import com.github.housepower.serde.BinarySerializer;

import javax.annotation.Nullable;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
Expand All @@ -35,13 +36,18 @@ public ColumnNullable(String name, DataTypeNullable type, Object[] values) {
}

@Override
public void write(Object object) throws IOException, SQLException {
nullableSign.add(object == null ? (byte) 1 : 0);
data.write(object == null ? type.defaultValue() : object);
public void write(@Nullable Object object) throws IOException, SQLException {
if (object == null) {
nullableSign.add((byte) 1);
data.write(type.defaultValue()); // write whatever for padding
} else {
nullableSign.add((byte) 0);
data.write(object);
}
}

@Override
public void flushToSerializer(BinarySerializer serializer, boolean immediate) throws IOException, SQLException {
public void flushToSerializer(BinarySerializer serializer, boolean immediate) throws IOException {
if (isExported()) {
serializer.writeUTF8StringBinary(name);
serializer.writeUTF8StringBinary(type.name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
* limitations under the License.
*/

package com.github.housepower.jdbc.data;
package com.github.housepower.data;

import com.github.housepower.jdbc.ClickHouseStruct;
import com.github.housepower.jdbc.data.type.complex.DataTypeTuple;
import com.github.housepower.jdbc.serde.BinarySerializer;
import com.github.housepower.data.type.complex.DataTypeTuple;
import com.github.housepower.serde.BinarySerializer;

import java.io.IOException;
import java.sql.SQLException;
Expand All @@ -29,7 +29,7 @@ public class ColumnTuple extends AbstractColumn {
public ColumnTuple(String name, DataTypeTuple type, Object[] values) {
super(name, type, values);

IDataType[] types = type.getNestedTypes();
IDataType<?, ?>[] types = type.getNestedTypes();
columnDataArray = new IColumn[types.length];
for (int i = 0; i < types.length; i++) {
columnDataArray[i] = ColumnFactory.createColumn(null, types[i], null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
* limitations under the License.
*/

package com.github.housepower.jdbc.data;
package com.github.housepower.data;

import com.github.housepower.jdbc.buffer.ByteArrayWriter;
import com.github.housepower.jdbc.serde.BinarySerializer;
import com.github.housepower.jdbc.settings.ClickHouseDefines;
import com.github.housepower.buffer.ByteArrayWriter;
import com.github.housepower.serde.BinarySerializer;
import com.github.housepower.settings.ClickHouseDefines;

import java.io.IOException;
import java.nio.Buffer;
Expand Down
Loading