summaryrefslogtreecommitdiffstats
path: root/document/src
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@oath.com>2018-06-12 14:32:47 +0200
committerHenning Baldersheim <balder@oath.com>2018-06-12 14:53:28 +0200
commit90d9c4f6be7d09cb6a7f5570f10d86404cbfc15a (patch)
tree46d675f8eef5c41f9df8e8749da55be81ee8fd27 /document/src
parent7c4f18824d24d7c6124fbdb0ced7587bc6e19caf (diff)
Last style changes before lazy documentupdate PR.
Diffstat (limited to 'document/src')
-rw-r--r--document/src/tests/documentupdatetestcase.cpp36
-rw-r--r--document/src/vespa/document/datatype/datatype.cpp11
-rw-r--r--document/src/vespa/document/datatype/datatype.h3
-rw-r--r--document/src/vespa/document/datatype/structureddatatype.h3
-rw-r--r--document/src/vespa/document/fieldvalue/document.h18
-rw-r--r--document/src/vespa/document/update/documentupdate.h2
-rw-r--r--document/src/vespa/document/update/fieldupdate.cpp2
-rw-r--r--document/src/vespa/document/update/fieldupdate.h4
8 files changed, 32 insertions, 47 deletions
diff --git a/document/src/tests/documentupdatetestcase.cpp b/document/src/tests/documentupdatetestcase.cpp
index 6b52d4018b3..9ba17d95264 100644
--- a/document/src/tests/documentupdatetestcase.cpp
+++ b/document/src/tests/documentupdatetestcase.cpp
@@ -33,6 +33,7 @@ using namespace document::config_builder;
using vespalib::tensor::Tensor;
using vespalib::tensor::TensorCells;
using vespalib::tensor::TensorDimensions;
+using vespalib::nbostream;
namespace document {
@@ -100,7 +101,7 @@ namespace {
ByteBuffer::UP serializeHEAD(const DocumentUpdate & update)
{
- vespalib::nbostream stream;
+ nbostream stream;
VespaDocumentSerializer serializer(stream);
serializer.writeHEAD(update);
ByteBuffer::UP retVal(new ByteBuffer(stream.size()));
@@ -110,7 +111,7 @@ ByteBuffer::UP serializeHEAD(const DocumentUpdate & update)
ByteBuffer::UP serialize42(const DocumentUpdate & update)
{
- vespalib::nbostream stream;
+ nbostream stream;
VespaDocumentSerializer serializer(stream);
serializer.write42(update);
ByteBuffer::UP retVal(new ByteBuffer(stream.size()));
@@ -120,7 +121,7 @@ ByteBuffer::UP serialize42(const DocumentUpdate & update)
ByteBuffer::UP serialize(const ValueUpdate & update)
{
- vespalib::nbostream stream;
+ nbostream stream;
VespaDocumentSerializer serializer(stream);
serializer.write(update);
ByteBuffer::UP retVal(new ByteBuffer(stream.size()));
@@ -130,7 +131,7 @@ ByteBuffer::UP serialize(const ValueUpdate & update)
ByteBuffer::UP serialize(const FieldUpdate & update)
{
- vespalib::nbostream stream;
+ nbostream stream;
VespaDocumentSerializer serializer(stream);
serializer.write(update);
ByteBuffer::UP retVal(new ByteBuffer(stream.size()));
@@ -163,8 +164,7 @@ createTensor(const TensorCells &cells, const TensorDimensions &dimensions) {
FieldValue::UP createTensorFieldValue() {
auto fv(std::make_unique<TensorFieldValue>());
- *fv = createTensor({ {{{"x", "8"}, {"y", "9"}}, 11} },
- {"x", "y"});
+ *fv = createTensor({ {{{"x", "8"}, {"y", "9"}}, 11} }, {"x", "y"});
return std::move(fv);
}
@@ -174,11 +174,8 @@ void
DocumentUpdateTest::testSimpleUsage() {
DocumenttypesConfigBuilderHelper builder;
builder.document(42, "test",
- Struct("test.header")
- .addField("bytef", DataType::T_BYTE)
- .addField("intf", DataType::T_INT),
- Struct("test.body")
- .addField("intarr", Array(DataType::T_INT)));
+ Struct("test.header").addField("bytef", DataType::T_BYTE).addField("intf", DataType::T_INT),
+ Struct("test.body").addField("intarr", Array(DataType::T_INT)));
DocumentTypeRepo repo(builder.config());
const DocumentType* docType(repo.getDocumentType("test"));
const DataType *arrayType = repo.getDataType(*docType, "Array<Int>");
@@ -186,8 +183,7 @@ DocumentUpdateTest::testSimpleUsage() {
// Test that primitive value updates can be serialized
testValueUpdate(ClearValueUpdate(), *DataType::INT);
testValueUpdate(AssignValueUpdate(IntFieldValue(1)), *DataType::INT);
- testValueUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Div, 4.3),
- *DataType::FLOAT);
+ testValueUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Div, 4.3), *DataType::FLOAT);
testValueUpdate(AddValueUpdate(IntFieldValue(1), 4), *arrayType);
testValueUpdate(RemoveValueUpdate(IntFieldValue(1)), *arrayType);
@@ -551,8 +547,7 @@ DocumentUpdateTest::testIncrementExistingWSetField()
}
fixture.applyUpdateToDocument();
- std::unique_ptr<WeightedSetFieldValue> ws(
- fixture.doc.getAs<WeightedSetFieldValue>(fixture.field));
+ auto ws(fixture.doc.getAs<WeightedSetFieldValue>(fixture.field));
CPPUNIT_ASSERT_EQUAL(size_t(2), ws->size());
CPPUNIT_ASSERT(ws->contains(StringFieldValue("foo")));
CPPUNIT_ASSERT_EQUAL(1, ws->get(StringFieldValue("foo"), 0));
@@ -564,12 +559,11 @@ DocumentUpdateTest::testIncrementWithZeroResultWeightIsRemoved()
WeightedSetAutoCreateFixture fixture;
fixture.update.addUpdate(FieldUpdate(fixture.field)
.addUpdate(MapValueUpdate(StringFieldValue("baz"),
- ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 0))));
+ ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 0))));
fixture.applyUpdateToDocument();
- std::unique_ptr<WeightedSetFieldValue> ws(
- fixture.doc.getAs<WeightedSetFieldValue>(fixture.field));
+ auto ws(fixture.doc.getAs<WeightedSetFieldValue>(fixture.field));
CPPUNIT_ASSERT_EQUAL(size_t(1), ws->size());
CPPUNIT_ASSERT(ws->contains(StringFieldValue("foo")));
CPPUNIT_ASSERT(!ws->contains(StringFieldValue("baz")));
@@ -671,10 +665,9 @@ void DocumentUpdateTest::testGenerateSerializedFile()
ArithmeticValueUpdate(ArithmeticValueUpdate::Mul, 2))));
ByteBuffer::UP buf(serialize42(upd));
- int fd = open(TEST_PATH("data/serializeupdatecpp.dat").c_str(),
- O_WRONLY | O_TRUNC | O_CREAT, 0644);
+ int fd = open(TEST_PATH("data/serializeupdatecpp.dat").c_str(), O_WRONLY | O_TRUNC | O_CREAT, 0644);
if (write(fd, buf->getBuffer(), buf->getPos()) != (ssize_t)buf->getPos()) {
- throw vespalib::Exception("read failed");
+ throw vespalib::Exception("read failed");
}
close(fd);
}
@@ -698,7 +691,6 @@ void DocumentUpdateTest::testSetBadFieldTypes()
; // fprintf(stderr, "Got exception => OK: %s\n", e.what());
}
- // Apply update
update.applyTo(*doc);
// Verify that the field is NOT set in the document.
diff --git a/document/src/vespa/document/datatype/datatype.cpp b/document/src/vespa/document/datatype/datatype.cpp
index 08a91e0df64..3b56942b61e 100644
--- a/document/src/vespa/document/datatype/datatype.cpp
+++ b/document/src/vespa/document/datatype/datatype.cpp
@@ -6,6 +6,7 @@
#include <vespa/document/datatype/documenttype.h>
#include <vespa/document/datatype/weightedsetdatatype.h>
#include <vespa/document/fieldvalue/fieldvalues.h>
+#include <vespa/document/base/exceptions.h>
#include <vespa/vespalib/text/lowercase.h>
#include <stdexcept>
@@ -153,9 +154,7 @@ DataType::DataType(const vespalib::stringref & name)
{
}
-DataType::~DataType()
-{
-}
+DataType::~DataType() = default;
bool
DataType::operator==(const DataType& other) const
@@ -179,4 +178,10 @@ DataType::buildFieldPath(FieldPath & path, const vespalib::stringref & remainFie
}
}
+const Field&
+DataType::getField(int fieldId) const
+{
+ throw FieldNotFoundException(fieldId, 7, VESPA_STRLOC);
+}
+
} // document
diff --git a/document/src/vespa/document/datatype/datatype.h b/document/src/vespa/document/datatype/datatype.h
index fae33ea2a42..247d72db665 100644
--- a/document/src/vespa/document/datatype/datatype.h
+++ b/document/src/vespa/document/datatype/datatype.h
@@ -129,6 +129,9 @@ public:
*/
void buildFieldPath(FieldPath & fieldPath, const vespalib::stringref & remainFieldName) const;
+ /** @throws FieldNotFoundException if field does not exist. */
+ virtual const Field& getField(int fieldId) const;
+
DECLARE_IDENTIFIABLE_ABSTRACT(DataType);
private:
virtual void onBuildFieldPath(FieldPath & fieldPath, const vespalib::stringref & remainFieldName) const = 0;
diff --git a/document/src/vespa/document/datatype/structureddatatype.h b/document/src/vespa/document/datatype/structureddatatype.h
index 1454f16d517..31de0d93680 100644
--- a/document/src/vespa/document/datatype/structureddatatype.h
+++ b/document/src/vespa/document/datatype/structureddatatype.h
@@ -30,9 +30,6 @@ public:
/** @throws FieldNotFoundException if field does not exist. */
virtual const Field& getField(const vespalib::stringref & name) const = 0;
- /** @throws FieldNotFoundException if field does not exist. */
- virtual const Field& getField(int fieldId) const = 0;
-
virtual bool hasField(const vespalib::stringref & name) const = 0;
virtual bool hasField(int32_t fieldId) const = 0;
diff --git a/document/src/vespa/document/fieldvalue/document.h b/document/src/vespa/document/fieldvalue/document.h
index 59a6f3d0a31..e0a35411f9b 100644
--- a/document/src/vespa/document/fieldvalue/document.h
+++ b/document/src/vespa/document/fieldvalue/document.h
@@ -41,23 +41,13 @@ public:
Document(const Document&);
Document(const DataType &, const DocumentId&);
Document(const DataType &, DocumentId &, bool iWillAllowSwap);
- Document(const DocumentTypeRepo& repo,
- ByteBuffer& buffer,
- const DataType *anticipatedType = 0);
- Document(const DocumentTypeRepo& repo,
- vespalib::nbostream& stream,
- const DataType *anticipatedType = 0);
+ Document(const DocumentTypeRepo& repo, ByteBuffer& buffer, const DataType *anticipatedType = 0);
+ Document(const DocumentTypeRepo& repo, vespalib::nbostream& stream, const DataType *anticipatedType = 0);
/**
Constructor to deserialize only document and type from a buffer. Only relevant if includeContent is false.
*/
- Document(const DocumentTypeRepo& repo,
- ByteBuffer& buffer,
- bool includeContent,
- const DataType *anticipatedType);
- Document(const DocumentTypeRepo& repo,
- ByteBuffer& header,
- ByteBuffer& body,
- const DataType *anticipatedType = 0);
+ Document(const DocumentTypeRepo& repo, ByteBuffer& buffer, bool includeContent, const DataType *anticipatedType);
+ Document(const DocumentTypeRepo& repo, ByteBuffer& header, ByteBuffer& body, const DataType *anticipatedType = 0);
~Document();
void setRepo(const DocumentTypeRepo & repo);
diff --git a/document/src/vespa/document/update/documentupdate.h b/document/src/vespa/document/update/documentupdate.h
index c4b351674b5..c6250fb6b75 100644
--- a/document/src/vespa/document/update/documentupdate.h
+++ b/document/src/vespa/document/update/documentupdate.h
@@ -33,7 +33,7 @@
namespace document {
class Document;
-
+class VespaDocumentSerializer;
/**
* Class containing a document update. In vespa 5.0, support for field
* path updates was added, and a new serialization format was
diff --git a/document/src/vespa/document/update/fieldupdate.cpp b/document/src/vespa/document/update/fieldupdate.cpp
index 52fe0071b94..4644ae1f340 100644
--- a/document/src/vespa/document/update/fieldupdate.cpp
+++ b/document/src/vespa/document/update/fieldupdate.cpp
@@ -27,7 +27,7 @@ int readInt(ByteBuffer & buffer) {
}
-FieldUpdate::FieldUpdate(const DocumentTypeRepo& repo, const DocumentType& type, ByteBuffer& buffer, int16_t version)
+FieldUpdate::FieldUpdate(const DocumentTypeRepo& repo, const DataType & type, ByteBuffer& buffer, int16_t version)
: Printable(),
_field(type.getField(readInt(buffer))),
_updates()
diff --git a/document/src/vespa/document/update/fieldupdate.h b/document/src/vespa/document/update/fieldupdate.h
index fc94df605af..fa5bac1cca9 100644
--- a/document/src/vespa/document/update/fieldupdate.h
+++ b/document/src/vespa/document/update/fieldupdate.h
@@ -19,8 +19,6 @@
namespace document {
class Document;
-class DocumentType;
-class DocumentTypeRepo;
class FieldUpdate : public vespalib::Identifiable,
public Printable,
@@ -47,7 +45,7 @@ public:
* @param buffer A byte buffer that contains a serialized field update.
* @param serializationVersion The serialization version the update was serialized with.
*/
- FieldUpdate(const DocumentTypeRepo& repo, const DocumentType& type,
+ FieldUpdate(const DocumentTypeRepo& repo, const DataType & type,
ByteBuffer& buffer, int16_t version);
bool operator==(const FieldUpdate&) const;