introduce type map for user validations

This commit is contained in:
Jonathan Shook 2020-04-20 02:02:11 -05:00
parent ebabd628a1
commit 9be09ecde1
2 changed files with 60 additions and 1 deletions

View File

@ -1,12 +1,21 @@
package io.nosqlbench.activitytype.cql.core;
import com.datastax.driver.core.LocalDate;
import com.datastax.driver.core.TupleValue;
import com.datastax.driver.core.UDTValue;
import io.nosqlbench.engine.api.activityapi.core.ActionDispenser;
import io.nosqlbench.engine.api.activityapi.core.ActivityType;
import io.nosqlbench.engine.api.activityimpl.ActivityDef;
import io.nosqlbench.nb.api.annotations.Service;
import java.util.Optional;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.InetAddress;
import java.nio.ByteBuffer;
import java.time.Instant;
import java.time.LocalTime;
import java.util.*;
@Service(ActivityType.class)
public class CqlActivityType implements ActivityType<CqlActivity> {
@ -43,4 +52,36 @@ public class CqlActivityType implements ActivityType<CqlActivity> {
return new CqlActionDispenser(activity);
}
@Override
public Map<String, Class<?>> getTypeMap() {
Map<String,Class<?>> typemap = new LinkedHashMap<>();
typemap.put("ascii",String.class);
typemap.put("bigint",long.class);
typemap.put("blob", ByteBuffer.class);
typemap.put("boolean",boolean.class);
typemap.put("counter",long.class);
typemap.put("date", LocalDate.class);
typemap.put("decimal", BigDecimal.class);
typemap.put("double",double.class);
// typemap.put("duration",CqlDuration.class);
typemap.put("float",float.class);
typemap.put("inet", InetAddress.class);
typemap.put("int",int.class);
typemap.put("list", List.class);
typemap.put("map",Map.class);
typemap.put("set", Set.class);
typemap.put("smallint",short.class);
typemap.put("text",String.class);
typemap.put("time", LocalTime.class);
typemap.put("timestamp", Instant.class);
typemap.put("tinyint",byte.class);
typemap.put("tuple", TupleValue.class);
typemap.put("<udt>", UDTValue.class);
typemap.put("uuid",UUID.class);
typemap.put("timeuuid",UUID.class);
typemap.put("varchar",String.class);
typemap.put("varint", BigInteger.class);
return typemap;
}
}

View File

@ -138,5 +138,23 @@ public interface ActivityType<A extends Activity> extends Named {
return new CoreMotorDispenser<T> (activity, inputDispenser, actionDispenser, outputDispenser);
}
/**
* An ActivityType can describe the canonical named types as known within that driver implementation,
* and the Java compatible types which can be assigned to them. This map is consulted when users need to select
* the name from within that driver in order to see the compatible functions which may produce a valid type for
* it. For example, a CQL users may want to know what java type (and thus what binding functions) can support
* the CQL timeuuid type.
*
* Conversely, a user may want to know what types are supported by the java.util.{@link java.util.UUID} class
* in CQL. In that case, this map will also be consulted, and multiple keys will match.
* When there are multiple answers in this way, but the driver has its own default about which one to use
* when the user's intent is ambiguous, the map should be be ordered as in {@link java.util.LinkedHashMap},
* and the preferred form should be listed first.
*
* @return a type map indicating co-compatible associations of driver-specific type names and Java types
*/
default Map<String,Class<?>> getTypeMap() {
return Map.of();
}
}