Skip to content
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
Expand Up @@ -33,21 +33,19 @@
import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.read.common.Field;
import org.apache.tsfile.read.common.RowRecord;
import org.apache.tsfile.utils.Binary;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.sql.Blob;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import static org.apache.iotdb.db.it.utils.TestUtils.prepareTableData;
import static org.junit.Assert.assertArrayEquals;
import static org.apache.iotdb.jdbc.IoTDBJDBCResultSet.OBJECT_ERR_MSG;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -104,10 +102,20 @@ public void jdbcTest() {
int cnt = 0;
while (resultSet.next()) {
cnt++;
Blob blob = resultSet.getBlob(3);
byte[] bytes = resultSet.getBytes("o1");
assertArrayEquals(blob.getBytes(1, (int) blob.length()), bytes);
assertTrue(new String(bytes).endsWith(String.format("%d.bin", cnt)));
try {
resultSet.getBlob(3);
fail();
} catch (SQLException e) {
assertEquals(OBJECT_ERR_MSG, e.getMessage());
}

try {
resultSet.getBytes("o1");
fail();
} catch (SQLException e) {
assertEquals(OBJECT_ERR_MSG, e.getMessage());
}

String s = resultSet.getString(3);
assertEquals("(Object) 5 B", s);
}
Expand Down Expand Up @@ -150,13 +158,15 @@ public void sessionTest() {
String s = field.getStringValue();
assertEquals("(Object) 5 B", s);
Object blob = field.getObjectValue(TSDataType.OBJECT);
assertTrue(blob instanceof Binary);
assertTrue(
new String(((Binary) blob).getValues()).endsWith(String.format("%d.bin", cnt)));

Binary binary = field.getBinaryV();
assertArrayEquals(binary.getValues(), ((Binary) blob).getValues());
assertTrue(new String(binary.getValues()).endsWith(String.format("%d.bin", cnt)));
assertTrue(blob instanceof String);
assertEquals("(Object) 5 B", blob);

try {
field.getBinaryV();
fail();
} catch (UnsupportedOperationException e) {
assertEquals("OBJECT Type only support getStringValue", e.getMessage());
}
}
assertEquals(4, cnt);
}
Expand All @@ -174,8 +184,12 @@ public void sessionTest() {
assertEquals("(Object) 5 B", o);
String s = iterator.getString("o1");
assertEquals("(Object) 5 B", s);
Binary blob = iterator.getBlob(3);
assertTrue(new String(blob.getValues()).endsWith(String.format("%d.bin", cnt)));
try {
iterator.getBlob(3);
fail();
} catch (StatementExecutionException e) {
assertEquals("OBJECT Type only support getString", e.getMessage());
}
}
assertEquals(4, cnt);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

import org.apache.tsfile.utils.Binary;

import java.io.File;
import java.time.LocalDate;
import java.util.Optional;

public interface Record {
/**
Expand Down Expand Up @@ -83,7 +85,7 @@ public interface Record {
* Returns the Binary value at the specified column in this row.
*
* <p>Users need to ensure that the data type of the specified column is {@code TSDataType.TEXT},
* {@code TSDataType.STRING} or {@code TSDataType.BLOB} or {@code TSDataType.OBJECT}.
* {@code TSDataType.STRING} or {@code TSDataType.BLOB}.
*
* @param columnIndex index of the specified column
* @return the Binary value at the specified column in this row
Expand Down Expand Up @@ -113,6 +115,15 @@ public interface Record {

Object getObject(int columnIndex);

/**
* Returns the OBJECT value's real file path in current node at the specified column in this row.
*
* @param columnIndex index of the specified column
* @return Optional.empty() if current node doesn't have the real file storing the object content,
* otherwise the File referring to the OBJECT value's real file path
*/
Optional<File> getObjectFile(int columnIndex);

/**
* Returns the Binary representation of an object stored at the specified column in this row.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,26 @@ public LocalDate getDate(String columnName) throws StatementExecutionException {
}

public Binary getBlob(int columnIndex) throws StatementExecutionException {
final TSDataType dataType = ioTDBRpcDataSet.getDataType(columnIndex);
if (dataType == null) {
return null;
}

if (dataType.equals(TSDataType.OBJECT)) {
throw new StatementExecutionException("OBJECT Type only support getString");
}
return ioTDBRpcDataSet.getBinary(columnIndex);
}

public Binary getBlob(String columnName) throws StatementExecutionException {
final TSDataType dataType = ioTDBRpcDataSet.getDataType(columnName);
if (dataType == null) {
return null;
}

if (dataType.equals(TSDataType.OBJECT)) {
throw new StatementExecutionException("OBJECT Type only support getString");
}
return ioTDBRpcDataSet.getBinary(columnName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@

public class IoTDBJDBCResultSet implements ResultSet {

public static final String OBJECT_ERR_MSG = "OBJECT Type only support getString";

private static final Logger LOGGER = LoggerFactory.getLogger(IoTDBJDBCResultSet.class);

protected IoTDBStatement statement;
Expand Down Expand Up @@ -301,6 +303,15 @@ public InputStream getBinaryStream(String arg0) throws SQLException {
@Override
public Blob getBlob(int arg0) throws SQLException {
try {
final TSDataType dataType = ioTDBRpcDataSet.getDataType(arg0);
if (dataType == null) {
return null;
}

if (dataType.equals(TSDataType.OBJECT)) {
throw new SQLException(OBJECT_ERR_MSG);
}

Binary binary = ioTDBRpcDataSet.getBinary(arg0);
if (ObjectUtils.isNotEmpty(binary)) {
return new SerialBlob(binary.getValues());
Expand All @@ -314,6 +325,15 @@ public Blob getBlob(int arg0) throws SQLException {
@Override
public Blob getBlob(String arg0) throws SQLException {
try {
final TSDataType dataType = ioTDBRpcDataSet.getDataType(arg0);
if (dataType == null) {
return null;
}

if (dataType.equals(TSDataType.OBJECT)) {
throw new SQLException(OBJECT_ERR_MSG);
}

Binary binary = ioTDBRpcDataSet.getBinary(arg0);
if (ObjectUtils.isNotEmpty(binary)) {
return new SerialBlob(binary.getValues());
Expand Down Expand Up @@ -360,7 +380,9 @@ public byte[] getBytes(int columnIndex) throws SQLException {
return null;
}

if (dataType.equals(TSDataType.BLOB) || dataType.equals(TSDataType.OBJECT)) {
if (dataType.equals(TSDataType.OBJECT)) {
throw new SQLException(OBJECT_ERR_MSG);
} else if (dataType.equals(TSDataType.BLOB)) {
Binary binary = ioTDBRpcDataSet.getBinary(columnIndex);
return binary == null ? null : binary.getValues();
} else {
Expand All @@ -379,8 +401,9 @@ public byte[] getBytes(String columnName) throws SQLException {
if (dataType == null) {
return null;
}

if (dataType.equals(TSDataType.BLOB) || dataType.equals(TSDataType.OBJECT)) {
if (dataType.equals(TSDataType.OBJECT)) {
throw new SQLException(OBJECT_ERR_MSG);
} else if (dataType.equals(TSDataType.BLOB)) {
Binary binary = ioTDBRpcDataSet.getBinary(columnName);
return binary == null ? null : binary.getValues();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@
import org.apache.tsfile.utils.BytesUtils;
import org.apache.tsfile.utils.DateUtils;

import java.io.File;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import static org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.RecordIterator.OBJECT_ERR_MSG;
import static org.apache.iotdb.udf.api.type.Type.OBJECT;

/** Parts of partition. */
Expand Down Expand Up @@ -170,6 +173,14 @@ public boolean getBoolean(int columnIndex) {

@Override
public Binary getBinary(int columnIndex) {
Type type = dataTypes.get(columnIndex);
if (type == OBJECT) {
throw new UnsupportedOperationException(OBJECT_ERR_MSG);
}
return getBinarySafely(columnIndex);
}

public Binary getBinarySafely(int columnIndex) {
return originalColumns[columnIndex].getBinary(offset);
}

Expand All @@ -193,15 +204,24 @@ public LocalDate getLocalDate(int columnIndex) {

@Override
public Object getObject(int columnIndex) {
Type type = dataTypes.get(columnIndex);
if (type == OBJECT) {
throw new UnsupportedOperationException(OBJECT_ERR_MSG);
}
return originalColumns[columnIndex].getObject(offset);
}

@Override
public Binary readObject(int columnIndex, long offset, int length) {
public Optional<File> getObjectFile(int columnIndex) {
if (getDataType(columnIndex) != Type.OBJECT) {
throw new UnsupportedOperationException("current column is not object column");
}
Binary binary = getBinary(columnIndex);
return ObjectTypeUtils.getObjectPathFromBinary(getBinarySafely(columnIndex));
}

@Override
public Binary readObject(int columnIndex, long offset, int length) {
Binary binary = getBinarySafely(columnIndex);
return new Binary(ObjectTypeUtils.readObjectContent(binary, offset, length, true).array());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@
import org.apache.tsfile.utils.BytesUtils;
import org.apache.tsfile.utils.DateUtils;

import java.io.File;
import java.time.LocalDate;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;

import static org.apache.tsfile.read.common.type.BlobType.BLOB;

public class RecordIterator implements Iterator<Record> {

public static final String OBJECT_ERR_MSG =
"OBJECT Type only support getString, getObjectFile, objectLength and readObject";

private final List<Column> childrenColumns;
private final List<org.apache.tsfile.read.common.type.Type> dataTypes;
private final int positionCount;
Expand Down Expand Up @@ -113,6 +118,14 @@ public boolean getBoolean(int columnIndex) {

@Override
public Binary getBinary(int columnIndex) {
org.apache.tsfile.read.common.type.Type type = dataTypes.get(columnIndex);
if (type == ObjectType.OBJECT) {
throw new UnsupportedOperationException(OBJECT_ERR_MSG);
}
return getBinarySafely(columnIndex);
}

private Binary getBinarySafely(int columnIndex) {
return childrenColumns.get(columnIndex).getBinary(index);
}

Expand All @@ -136,15 +149,24 @@ public LocalDate getLocalDate(int columnIndex) {

@Override
public Object getObject(int columnIndex) {
org.apache.tsfile.read.common.type.Type type = dataTypes.get(columnIndex);
if (type == ObjectType.OBJECT) {
throw new UnsupportedOperationException(OBJECT_ERR_MSG);
}
return childrenColumns.get(columnIndex).getObject(index);
}

@Override
public Binary readObject(int columnIndex, long offset, int length) {
public Optional<File> getObjectFile(int columnIndex) {
if (getDataType(columnIndex) != Type.OBJECT) {
throw new UnsupportedOperationException("current column is not object column");
}
Binary binary = getBinary(columnIndex);
return ObjectTypeUtils.getObjectPathFromBinary(getBinarySafely(columnIndex));
}

@Override
public Binary readObject(int columnIndex, long offset, int length) {
Binary binary = getBinarySafely(columnIndex);
return new Binary(ObjectTypeUtils.readObjectContent(binary, offset, length, true).array());
}

Expand Down
Loading
Loading