use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class DataTypeIT method primitiveTypeSamples.
@DataProvider
public static Object[][] primitiveTypeSamples() {
InetAddress address;
try {
address = InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 });
} catch (UnknownHostException uhae) {
throw new AssertionError("Could not get address from 127.0.0.1", uhae);
}
Object[][] samples = new Object[][] { new Object[] { DataTypes.ASCII, "ascii" }, new Object[] { DataTypes.BIGINT, Long.MAX_VALUE }, new Object[] { DataTypes.BIGINT, null, 0L }, new Object[] { DataTypes.BLOB, Bytes.fromHexString("0xCAFE") }, new Object[] { DataTypes.BOOLEAN, Boolean.TRUE }, new Object[] { DataTypes.BOOLEAN, null, false }, new Object[] { DataTypes.DECIMAL, new BigDecimal("12.3E+7") }, new Object[] { DataTypes.DOUBLE, Double.MAX_VALUE }, new Object[] { DataTypes.DOUBLE, null, 0.0 }, new Object[] { DataTypes.FLOAT, Float.MAX_VALUE }, new Object[] { DataTypes.FLOAT, null, 0.0f }, new Object[] { DataTypes.INET, address }, new Object[] { DataTypes.TINYINT, Byte.MAX_VALUE }, new Object[] { DataTypes.TINYINT, null, (byte) 0 }, new Object[] { DataTypes.SMALLINT, Short.MAX_VALUE }, new Object[] { DataTypes.SMALLINT, null, (short) 0 }, new Object[] { DataTypes.INT, Integer.MAX_VALUE }, new Object[] { DataTypes.INT, null, 0 }, new Object[] { DataTypes.DURATION, CqlDuration.from("PT30H20M") }, new Object[] { DataTypes.TEXT, "text" }, new Object[] { DataTypes.TIMESTAMP, Instant.ofEpochMilli(872835240000L) }, new Object[] { DataTypes.DATE, LocalDate.ofEpochDay(16071) }, new Object[] { DataTypes.TIME, LocalTime.ofNanoOfDay(54012123450000L) }, new Object[] { DataTypes.TIMEUUID, UUID.fromString("FE2B4360-28C6-11E2-81C1-0800200C9A66") }, new Object[] { DataTypes.UUID, UUID.fromString("067e6162-3b6f-4ae2-a171-2470b63dff00") }, new Object[] { DataTypes.VARINT, new BigInteger(Integer.toString(Integer.MAX_VALUE) + "000") } };
Version version = CCM_RULE.getCassandraVersion();
// Filter types if they aren't supported by cassandra version in use.
return Arrays.stream(samples).filter(o -> {
DataType dataType = (DataType) o[0];
if (dataType == DataTypes.DURATION) {
return version.compareTo(Version.parse("3.10")) >= 0;
} else if (dataType == DataTypes.TINYINT || dataType == DataTypes.SMALLINT || dataType == DataTypes.DATE || dataType == DataTypes.TIME) {
return version.compareTo(Version.V2_2_0) >= 0;
}
return true;
}).toArray(Object[][]::new);
}
use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class DataTypeIT method createTable.
@BeforeClass
public static void createTable() {
// Create a table with all types being tested with.
// This is a bit more lenient than creating a table for each sample, which would put a lot of
// burden on C* and
// the filesystem.
int counter = 0;
List<String> columnData = new ArrayList<>();
for (Object[] sample : typeSamples()) {
DataType dataType = (DataType) sample[0];
if (!typeToColumnName.containsKey(dataType)) {
int columnIndex = ++counter;
String columnName = "column_" + columnIndex;
typeToColumnName.put(dataType, columnName);
columnData.add(String.format("%s %s", columnName, typeFor(dataType)));
}
}
SESSION_RULE.session().execute(SimpleStatement.builder(String.format("CREATE TABLE IF NOT EXISTS %s (k int primary key, %s)", tableName, String.join(",", columnData))).setExecutionProfile(SESSION_RULE.slowProfile()).build());
}
use of com.datastax.oss.driver.api.core.type.DataType in project java-driver by datastax.
the class DefaultCreateDseAggregate method asCql.
@NonNull
@Override
public String asCql() {
StringBuilder builder = new StringBuilder();
builder.append("CREATE ");
if (orReplace) {
builder.append("OR REPLACE ");
}
builder.append("AGGREGATE ");
if (ifNotExists) {
builder.append("IF NOT EXISTS ");
}
CqlHelper.qualify(keyspace, functionName, builder);
builder.append(" (");
boolean first = true;
for (DataType param : parameters) {
if (first) {
first = false;
} else {
builder.append(',');
}
builder.append(param.asCql(false, true));
}
builder.append(')');
if (sFunc != null) {
builder.append(" SFUNC ");
builder.append(sFunc.asCql(true));
}
if (sType != null) {
builder.append(" STYPE ");
builder.append(sType.asCql(false, true));
}
if (finalFunc != null) {
builder.append(" FINALFUNC ");
builder.append(finalFunc.asCql(true));
}
if (term != null) {
builder.append(" INITCOND ");
term.appendTo(builder);
}
// deterministic
if (deterministic) {
builder.append(" DETERMINISTIC");
}
return builder.toString();
}
Aggregations