use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class SymbolPrinterTest method prepare.
@Before
public void prepare() throws Exception {
DocTableInfo tableInfo = TestingTableInfo.builder(new TableIdent(DocSchemaInfo.NAME, TABLE_NAME), null).add("foo", DataTypes.STRING).add("bar", DataTypes.LONG).add("CraZy", DataTypes.IP).add("select", DataTypes.BYTE).add("idx", DataTypes.INTEGER).add("s_arr", new ArrayType(DataTypes.STRING)).build();
Map<QualifiedName, AnalyzedRelation> sources = ImmutableMap.<QualifiedName, AnalyzedRelation>builder().put(QualifiedName.of(TABLE_NAME), new TableRelation(tableInfo)).build();
sqlExpressions = new SqlExpressions(sources);
printer = new SymbolPrinter(sqlExpressions.functions());
}
use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class ValueNormalizer method normalizeObjectValue.
@SuppressWarnings("unchecked")
private void normalizeObjectValue(Map<String, Object> value, Reference info) {
for (Map.Entry<String, Object> entry : value.entrySet()) {
AnalyzedColumnDefinition.validateName(entry.getKey());
ColumnIdent nestedIdent = ColumnIdent.getChild(info.ident().columnIdent(), entry.getKey());
TableInfo tableInfo = schemas.getTableInfo(info.ident().tableIdent());
Reference nestedInfo = tableInfo.getReference(nestedIdent);
if (nestedInfo == null) {
if (info.columnPolicy() == ColumnPolicy.IGNORED) {
continue;
}
DynamicReference dynamicReference = null;
if (tableInfo instanceof DocTableInfo) {
dynamicReference = ((DocTableInfo) tableInfo).getDynamic(nestedIdent, true);
}
if (dynamicReference == null) {
throw new ColumnUnknownException(nestedIdent.sqlFqn());
}
DataType type = DataTypes.guessType(entry.getValue());
if (type == null) {
throw new ColumnValidationException(info.ident().columnIdent().sqlFqn(), "Invalid value");
}
dynamicReference.valueType(type);
nestedInfo = dynamicReference;
} else {
if (entry.getValue() == null) {
continue;
}
}
if (nestedInfo.valueType() == DataTypes.OBJECT && entry.getValue() instanceof Map) {
normalizeObjectValue((Map<String, Object>) entry.getValue(), nestedInfo);
} else if (isObjectArray(nestedInfo.valueType()) && entry.getValue() instanceof Object[]) {
normalizeObjectArrayValue((Object[]) entry.getValue(), nestedInfo);
} else {
entry.setValue(normalizePrimitiveValue(entry.getValue(), nestedInfo));
}
}
}
use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class Schemas method getDroppableTable.
public DocTableInfo getDroppableTable(TableIdent tableIdent) {
TableInfo tableInfo = getTableInfo(tableIdent);
if (!(tableInfo instanceof DocTableInfo)) {
throw new UnsupportedOperationException(String.format(Locale.ENGLISH, "The table %s is not dropable.", tableInfo.ident()));
}
DocTableInfo docTableInfo = (DocTableInfo) tableInfo;
if (docTableInfo.isAlias() && !docTableInfo.isPartitioned() && !isOrphanedAlias(docTableInfo)) {
throw new UnsupportedOperationException(String.format(Locale.ENGLISH, "%s is an alias and hence not dropable.", tableInfo.ident()));
}
return docTableInfo;
}
use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class AbstractScalarFunctionsTest method prepareFunctions.
@Before
public void prepareFunctions() throws Exception {
DocTableInfo tableInfo = TestingTableInfo.builder(new TableIdent(DocSchemaInfo.NAME, "users"), null).add("id", DataTypes.INTEGER).add("name", DataTypes.STRING).add("tags", new ArrayType(DataTypes.STRING)).add("age", DataTypes.INTEGER).add("a", DataTypes.INTEGER).add("x", DataTypes.LONG).add("shape", DataTypes.GEO_SHAPE).add("timestamp", DataTypes.TIMESTAMP).add("timezone", DataTypes.STRING).add("interval", DataTypes.STRING).add("time_format", DataTypes.STRING).add("long_array", new ArrayType(DataTypes.LONG)).add("int_array", new ArrayType(DataTypes.INTEGER)).add("long_set", new SetType(DataTypes.LONG)).add("regex_pattern", DataTypes.STRING).add("geoshape", DataTypes.GEO_SHAPE).add("geopoint", DataTypes.GEO_POINT).add("geostring", DataTypes.STRING).add("is_awesome", DataTypes.BOOLEAN).add("double_val", DataTypes.DOUBLE).add("float_val", DataTypes.DOUBLE).add("short_val", DataTypes.SHORT).add("obj", DataTypes.OBJECT, ImmutableList.of()).build();
DocTableRelation tableRelation = new DocTableRelation(tableInfo);
tableSources = ImmutableMap.of(new QualifiedName("users"), tableRelation);
sqlExpressions = new SqlExpressions(tableSources);
functions = sqlExpressions.getInstance(Functions.class);
}
use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class TransportShardUpsertActionTest method testGeneratedColumnsValidationWorksForArrayColumns.
@Test
public void testGeneratedColumnsValidationWorksForArrayColumns() throws Exception {
// test no exception are thrown when validating array generated columns
Map<String, Object> updatedColumns = MapBuilder.<String, Object>newMapBuilder().put("obj", MapBuilder.<String, Object>newMapBuilder().put("arr", new Object[] { 1 }).map()).map();
Map<String, Object> updatedGeneratedColumns = MapBuilder.<String, Object>newMapBuilder().put("arr", new Object[] { 1 }).map();
DocTableInfo docTableInfo = new TestingTableInfo.Builder(new TableIdent(null, "generated_column"), new Routing(Collections.<String, Map<String, List<Integer>>>emptyMap())).add("obj", DataTypes.OBJECT, null).add("obj", new ArrayType(DataTypes.INTEGER), Arrays.asList("arr")).addGeneratedColumn("arr", new ArrayType(DataTypes.INTEGER), "obj['arr']", false).build(getFunctions());
transportShardUpsertAction.processGeneratedColumns(docTableInfo, updatedColumns, updatedGeneratedColumns, false);
}
Aggregations