diff options
author | Geir Storli <geirst@yahoo-inc.com> | 2017-04-06 07:36:23 +0000 |
---|---|---|
committer | Geir Storli <geirst@yahoo-inc.com> | 2017-04-06 07:36:23 +0000 |
commit | 4e854f5b20a4ec144861831acb3c8e796b436729 (patch) | |
tree | 5b11e7eb56324e870fa1152ef88d66af395a6e38 /searchcommon | |
parent | 061459c448f68a2afefe4b4e8e10ce8056626fd9 (diff) |
Use datatype and collection type from config when building schema for imported fields.
Diffstat (limited to 'searchcommon')
4 files changed, 38 insertions, 45 deletions
diff --git a/searchcommon/src/tests/schema/imported-fields-cfg/imported-fields.cfg b/searchcommon/src/tests/schema/imported-fields-cfg/imported-fields.cfg index ccfec672134..d41ccc4bd61 100644 --- a/searchcommon/src/tests/schema/imported-fields-cfg/imported-fields.cfg +++ b/searchcommon/src/tests/schema/imported-fields-cfg/imported-fields.cfg @@ -2,6 +2,10 @@ attribute[2] attribute[0].name imported_a attribute[0].referencefield ref_a attribute[0].targetfield target_a +attribute[0].datatype INT32 +attribute[0].collectiontype SINGLE attribute[1].name imported_b attribute[1].referencefield ref_b attribute[1].targetfield target_b +attribute[1].datatype STRING +attribute[1].collectiontype ARRAY diff --git a/searchcommon/src/tests/schema/schema_test.cpp b/searchcommon/src/tests/schema/schema_test.cpp index 1365de0fd96..9368e92f691 100644 --- a/searchcommon/src/tests/schema/schema_test.cpp +++ b/searchcommon/src/tests/schema/schema_test.cpp @@ -418,8 +418,8 @@ TEST("require that schema can be built from imported-fields config") SchemaConfigurer configurer(s, "dir:" + TEST_PATH("imported-fields-cfg")); const auto &imported = s.getImportedAttributeFields(); EXPECT_EQUAL(2u, imported.size()); - TEST_DO(assertField(SIAF("imported_a", DataType::STRING, CollectionType::SINGLE), imported[0])); - TEST_DO(assertField(SIAF("imported_b", DataType::STRING, CollectionType::SINGLE), imported[1])); + TEST_DO(assertField(SIAF("imported_a", DataType::INT32, CollectionType::SINGLE), imported[0])); + TEST_DO(assertField(SIAF("imported_b", DataType::STRING, CollectionType::ARRAY), imported[1])); } } // namespace index diff --git a/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.cpp b/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.cpp index cc6d1f972f6..61571efa9e6 100644 --- a/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.cpp +++ b/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.cpp @@ -15,8 +15,10 @@ namespace index { using schema::DataType; using schema::CollectionType; +namespace { + Schema::DataType -SchemaBuilder::convert(const IndexschemaConfig::Indexfield::Datatype &type) +convertIndexDataType(const IndexschemaConfig::Indexfield::Datatype &type) { switch (type) { case IndexschemaConfig::Indexfield::STRING: @@ -31,7 +33,7 @@ SchemaBuilder::convert(const IndexschemaConfig::Indexfield::Datatype &type) Schema::CollectionType -SchemaBuilder::convert(const IndexschemaConfig::Indexfield::Collectiontype & type) +convertIndexCollectionType(const IndexschemaConfig::Indexfield::Collectiontype &type) { switch (type) { case IndexschemaConfig::Indexfield::SINGLE: @@ -44,36 +46,36 @@ SchemaBuilder::convert(const IndexschemaConfig::Indexfield::Collectiontype & typ return CollectionType::SINGLE; } - +template <typename ConfigType> Schema::DataType -SchemaBuilder::convert(const AttributesConfig::Attribute::Datatype &type) +convertDataType(const ConfigType &type) { switch (type) { - case AttributesConfig::Attribute::STRING: + case ConfigType::STRING: return DataType::STRING; - case AttributesConfig::Attribute::UINT1: + case ConfigType::UINT1: return DataType::UINT1; - case AttributesConfig::Attribute::UINT2: + case ConfigType::UINT2: return DataType::UINT2; - case AttributesConfig::Attribute::UINT4: + case ConfigType::UINT4: return DataType::UINT4; - case AttributesConfig::Attribute::INT8: + case ConfigType::INT8: return DataType::INT8; - case AttributesConfig::Attribute::INT16: + case ConfigType::INT16: return DataType::INT16; - case AttributesConfig::Attribute::INT32: + case ConfigType::INT32: return DataType::INT32; - case AttributesConfig::Attribute::INT64: + case ConfigType::INT64: return DataType::INT64; - case AttributesConfig::Attribute::FLOAT: + case ConfigType::FLOAT: return DataType::FLOAT; - case AttributesConfig::Attribute::DOUBLE: + case ConfigType::DOUBLE: return DataType::DOUBLE; - case AttributesConfig::Attribute::PREDICATE: + case ConfigType::PREDICATE: return DataType::BOOLEANTREE; - case AttributesConfig::Attribute::TENSOR: + case ConfigType::TENSOR: return DataType::TENSOR; - case AttributesConfig::Attribute::REFERENCE: + case ConfigType::REFERENCE: return DataType::REFERENCE; default: break; @@ -82,16 +84,16 @@ SchemaBuilder::convert(const AttributesConfig::Attribute::Datatype &type) return DataType::STRING; } - +template <typename ConfigType> Schema::CollectionType -SchemaBuilder::convert(const AttributesConfig::Attribute::Collectiontype &type) +convertCollectionType(const ConfigType &type) { switch (type) { - case AttributesConfig::Attribute::SINGLE: + case ConfigType::SINGLE: return CollectionType::SINGLE; - case AttributesConfig::Attribute::ARRAY: + case ConfigType::ARRAY: return CollectionType::ARRAY; - case AttributesConfig::Attribute::WEIGHTEDSET: + case ConfigType::WEIGHTEDSET: return CollectionType::WEIGHTEDSET; } return CollectionType::SINGLE; @@ -99,7 +101,7 @@ SchemaBuilder::convert(const AttributesConfig::Attribute::Collectiontype &type) Schema::DataType -SchemaBuilder::convertSummaryType(const vespalib::string & type) +convertSummaryType(const vespalib::string &type) { if (type == "byte") { return DataType::INT8; @@ -128,6 +130,7 @@ SchemaBuilder::convertSummaryType(const vespalib::string & type) return DataType::RAW; } +} void SchemaBuilder::build(const IndexschemaConfig &cfg, Schema &schema) @@ -141,8 +144,8 @@ SchemaBuilder::build(const IndexschemaConfig &cfg, Schema &schema) LOG(warning, "Your field '%s' is a rise index. Those are no longer supported as of Vespa-5.89.\n" " Redeploy and follow instructions to mitigate.", f.name.c_str()); } else { - schema.addIndexField(Schema::IndexField(f.name, convert(f.datatype), - convert(f.collectiontype)). + schema.addIndexField(Schema::IndexField(f.name, convertIndexDataType(f.datatype), + convertIndexCollectionType(f.collectiontype)). setPrefix(f.prefix). setPhrases(f.phrases). setPositions(f.positions). @@ -166,8 +169,8 @@ SchemaBuilder::build(const AttributesConfig &cfg, Schema &schema) for (size_t i = 0; i < cfg.attribute.size(); ++i) { const AttributesConfig::Attribute & a = cfg.attribute[i]; schema.addAttributeField(Schema::Field(a.name, - convert(a.datatype), - convert(a.collectiontype))); + convertDataType(a.datatype), + convertCollectionType(a.collectiontype))); } } @@ -206,9 +209,9 @@ void SchemaBuilder::build(const ImportedFieldsConfig &cfg, Schema &schema) { for (const auto &attr : cfg.attribute) { - // TODO: Use correct datatype and collection type when available in config. schema.addImportedAttributeField(Schema::ImportedAttributeField(attr.name, - schema::DataType::STRING)); + convertDataType(attr.datatype), + convertCollectionType(attr.collectiontype))); } } diff --git a/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.h b/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.h index 4a2f8e5149e..962dc50c5ad 100644 --- a/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.h +++ b/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.h @@ -19,20 +19,6 @@ namespace index { **/ class SchemaBuilder { - static Schema::DataType - convert(const vespa::config::search::IndexschemaConfig::Indexfield::Datatype &type); - - static Schema::CollectionType - convert(const vespa::config::search::IndexschemaConfig::Indexfield::Collectiontype &type); - - static Schema::DataType - convert(const vespa::config::search::AttributesConfig::Attribute::Datatype &type); - - static Schema::CollectionType - convert(const vespa::config::search::AttributesConfig::Attribute::Collectiontype &type); - - static Schema::DataType - convertSummaryType(const vespalib::string &type); public: /** * Build from indexschema config. |