1#include "duckdb/parser/parsed_data/sample_options.hpp"
2#include "duckdb/common/field_writer.hpp"
3#include "duckdb/common/serializer/format_serializer.hpp"
4#include "duckdb/common/serializer/format_deserializer.hpp"
5
6namespace duckdb {
7
8// **DEPRECATED**: Use EnumUtil directly instead.
9string SampleMethodToString(SampleMethod method) {
10 return EnumUtil::ToString(value: method);
11}
12
13void SampleOptions::Serialize(Serializer &serializer) {
14 FieldWriter writer(serializer);
15 writer.WriteSerializable(element: sample_size);
16 writer.WriteField<bool>(element: is_percentage);
17 writer.WriteField<SampleMethod>(element: method);
18 writer.WriteField<int64_t>(element: seed);
19 writer.Finalize();
20}
21
22void SampleOptions::FormatSerialize(FormatSerializer &serializer) const {
23 serializer.WriteProperty(tag: "sample_size", value: sample_size);
24 serializer.WriteProperty(tag: "is_percentage", value: is_percentage);
25 serializer.WriteProperty(tag: "method", value: method);
26 serializer.WriteProperty(tag: "seed", value: seed);
27}
28
29unique_ptr<SampleOptions> SampleOptions::FormatDeserialize(FormatDeserializer &deserializer) {
30 auto result = make_uniq<SampleOptions>();
31
32 deserializer.ReadProperty(tag: "sample_size", ret&: result->sample_size);
33 deserializer.ReadProperty(tag: "is_percentage", ret&: result->is_percentage);
34 deserializer.ReadProperty(tag: "method", ret&: result->method);
35 deserializer.ReadProperty(tag: "seed", ret&: result->seed);
36
37 return result;
38}
39
40unique_ptr<SampleOptions> SampleOptions::Deserialize(Deserializer &source) {
41 auto result = make_uniq<SampleOptions>();
42
43 FieldReader reader(source);
44 result->sample_size = reader.ReadRequiredSerializable<Value, Value>();
45 result->is_percentage = reader.ReadRequired<bool>();
46 result->method = reader.ReadRequired<SampleMethod>();
47 result->seed = reader.ReadRequired<int64_t>();
48 reader.Finalize();
49
50 return result;
51}
52
53unique_ptr<SampleOptions> SampleOptions::Copy() {
54 auto result = make_uniq<SampleOptions>();
55 result->sample_size = sample_size;
56 result->is_percentage = is_percentage;
57 result->method = method;
58 result->seed = seed;
59 return result;
60}
61
62bool SampleOptions::Equals(SampleOptions *a, SampleOptions *b) {
63 if (a == b) {
64 return true;
65 }
66 if (!a || !b) {
67 return false;
68 }
69 if (a->sample_size != b->sample_size || a->is_percentage != b->is_percentage || a->method != b->method ||
70 a->seed != b->seed) {
71 return false;
72 }
73 return true;
74}
75
76} // namespace duckdb
77