use of com.scalar.db.io.DataType in project scalardb by scalar-labs.
the class KeyBytesEncoderTest method encode_TripleKeysGiven_ShouldEncodeProperlyWithPreservingSortOrder.
@Test
public void encode_TripleKeysGiven_ShouldEncodeProperlyWithPreservingSortOrder() {
RANDOM.setSeed(seed);
runTest(() -> {
for (DataType col1Type : KEY_TYPES) {
// the BLOB type is supported only for the last key
if (col1Type == DataType.BLOB) {
continue;
}
for (DataType col2Type : KEY_TYPES) {
// the BLOB type is supported only for the last key
if (col2Type == DataType.BLOB) {
continue;
}
for (DataType col3Type : KEY_TYPES) {
for (Order col1Order : ORDERS) {
for (Order col2Order : ORDERS) {
for (Order col3Order : ORDERS) {
encode_TripleKeysGiven_ShouldEncodeProperlyWithPreservingSortOrder(col1Type, col2Type, col3Type, col1Order, col2Order, col3Order);
}
}
}
}
}
}
});
}
use of com.scalar.db.io.DataType in project scalardb by scalar-labs.
the class JdbcAdmin method getTableMetadata.
@Override
public TableMetadata getTableMetadata(String namespace, String table) throws ExecutionException {
TableMetadata.Builder builder = TableMetadata.newBuilder();
boolean tableExists = false;
try (Connection connection = dataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(getSelectColumnsStatement())) {
preparedStatement.setString(1, getFullTableName(namespace, table));
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
tableExists = true;
String columnName = resultSet.getString(METADATA_COL_COLUMN_NAME);
DataType dataType = DataType.valueOf(resultSet.getString(METADATA_COL_DATA_TYPE));
builder.addColumn(columnName, dataType);
boolean indexed = resultSet.getBoolean(METADATA_COL_INDEXED);
if (indexed) {
builder.addSecondaryIndex(columnName);
}
String keyType = resultSet.getString(METADATA_COL_KEY_TYPE);
if (keyType == null) {
continue;
}
switch(KeyType.valueOf(keyType)) {
case PARTITION:
builder.addPartitionKey(columnName);
break;
case CLUSTERING:
Scan.Ordering.Order clusteringOrder = Scan.Ordering.Order.valueOf(resultSet.getString(METADATA_COL_CLUSTERING_ORDER));
builder.addClusteringKey(columnName, clusteringOrder);
break;
default:
throw new AssertionError("invalid key type: " + keyType);
}
}
}
} catch (SQLException e) {
throw new ExecutionException("getting a table metadata failed", e);
}
if (!tableExists) {
return null;
}
return builder.build();
}
use of com.scalar.db.io.DataType in project scalardb by scalar-labs.
the class JdbcAdmin method getVendorDbColumnType.
/**
* Get the vendor DB data type that is equivalent to the Scalar DB data type
*
* @param metadata a table metadata
* @param columnName a column name
* @return a vendor DB data type
*/
@SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
private String getVendorDbColumnType(TableMetadata metadata, String columnName) {
HashSet<String> keysAndIndexes = Sets.newHashSet(Iterables.concat(metadata.getPartitionKeyNames(), metadata.getClusteringKeyNames(), metadata.getSecondaryIndexNames()));
DataType scalarDbColumnType = metadata.getColumnDataType(columnName);
if (keysAndIndexes.contains(columnName)) {
return DATA_TYPE_MAPPING_FOR_KEY.get(rdbEngine).getOrDefault(scalarDbColumnType, DATA_TYPE_MAPPING.get(rdbEngine).get(scalarDbColumnType));
} else {
return DATA_TYPE_MAPPING.get(rdbEngine).get(scalarDbColumnType);
}
}
use of com.scalar.db.io.DataType in project scalardb by scalar-labs.
the class ResultInterpreter method convert.
private Column<?> convert(String name, ResultSet resultSet) throws SQLException {
Column<?> ret;
DataType dataType = metadata.getColumnDataType(name);
switch(dataType) {
case BOOLEAN:
ret = BooleanColumn.of(name, resultSet.getBoolean(name));
if (resultSet.wasNull()) {
ret = BooleanColumn.ofNull(name);
}
break;
case INT:
ret = IntColumn.of(name, resultSet.getInt(name));
if (resultSet.wasNull()) {
ret = IntColumn.ofNull(name);
}
break;
case BIGINT:
ret = BigIntColumn.of(name, resultSet.getLong(name));
if (resultSet.wasNull()) {
ret = BigIntColumn.ofNull(name);
}
break;
case FLOAT:
// To handle Float.MAX_VALUE in MySQL, we need to get the value as double, then cast it to
// float
ret = FloatColumn.of(name, (float) resultSet.getDouble(name));
if (resultSet.wasNull()) {
ret = FloatColumn.ofNull(name);
}
break;
case DOUBLE:
ret = DoubleColumn.of(name, resultSet.getDouble(name));
if (resultSet.wasNull()) {
ret = DoubleColumn.ofNull(name);
}
break;
case TEXT:
ret = TextColumn.of(name, resultSet.getString(name));
if (resultSet.wasNull()) {
ret = TextColumn.ofNull(name);
}
break;
case BLOB:
ret = BlobColumn.of(name, resultSet.getBytes(name));
if (resultSet.wasNull()) {
ret = BlobColumn.ofNull(name);
}
break;
default:
throw new AssertionError();
}
return ret;
}
use of com.scalar.db.io.DataType in project scalardb by scalar-labs.
the class DistributedStorageMultipleClusteringKeyScanIntegrationTestBase method dropTables.
private void dropTables() throws java.util.concurrent.ExecutionException, InterruptedException {
List<Callable<Void>> testCallables = new ArrayList<>();
for (DataType firstClusteringKeyType : clusteringKeyTypes.keySet()) {
Callable<Void> testCallable = () -> {
for (DataType secondClusteringKeyType : clusteringKeyTypes.get(firstClusteringKeyType)) {
for (Order firstClusteringOrder : Order.values()) {
for (Order secondClusteringOrder : Order.values()) {
admin.dropTable(getNamespaceName(firstClusteringKeyType), getTableName(firstClusteringKeyType, firstClusteringOrder, secondClusteringKeyType, secondClusteringOrder));
}
}
}
admin.dropNamespace(getNamespaceName(firstClusteringKeyType));
return null;
};
testCallables.add(testCallable);
}
// We firstly execute the callables without the last one. And then we execute the last one. This
// is because the last table deletion deletes the metadata table, and this process can't be
// handled in multiple threads/processes at the same time.
executeInParallel(testCallables.subList(0, testCallables.size() - 1));
executeInParallel(testCallables.subList(testCallables.size() - 1, testCallables.size()));
}
Aggregations