Skip to content

Commit

Permalink
Merge branch 'main' into remove-python-37-and-38
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-g authored Dec 30, 2024
2 parents 5bb4de0 + a4d4085 commit 131f577
Show file tree
Hide file tree
Showing 48 changed files with 485 additions and 219 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-lang-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:

interop:
name: Node ${{ matrix.node }} Interop
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
strategy:
matrix:
node:
Expand Down
8 changes: 5 additions & 3 deletions doc/content/en/docs/++version++/Specification/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,8 @@ A logical type is always serialized using its underlying Avro type so that value
Language implementations must ignore unknown logical types when reading, and should use the underlying Avro type. If a logical type is invalid, for example a decimal with scale greater than its precision, then implementations should ignore the logical type and use the underlying Avro type.

### Decimal

#### Fixed precision
The `decimal` logical type represents an arbitrary-precision signed decimal number of the form _unscaled × 10<sup>-scale</sup>_.

A `decimal` logical type annotates Avro _bytes_ or _fixed_ types. The byte array must contain the two's-complement representation of the unscaled integer value in big-endian byte order. The scale is fixed, and is specified using an attribute.
Expand All @@ -810,19 +812,19 @@ Scale must be zero or a positive integer less than or equal to the precision.

For the purposes of schema resolution, two schemas that are `decimal` logical types _match_ if their scales and precisions match.

**alternative**
#### Scalable precision

As it's not always possible to fix scale and precision in advance for a decimal field, `big-decimal` is another `decimal` logical type restrict to Avro _bytes_.

_Currently only available in Java and Rust_.
_Currently only available in C++, Java and Rust_.

```json
{
"type": "bytes",
"logicalType": "big-decimal"
}
```
Here, as scale property is stored in value itself it needs more bytes than preceding `decimal` type, but it allows more flexibility.
Here, bytes array contains two serialized properties. First part is an Avro byte arrays which is the two's-complement representation of the unscaled integer value in big-endian byte order. The second part is the scale property stored as an Avro integer. Scale must be zero or a positive integer less than or equal to the precision. Value itself needs more bytes than preceding `decimal` type, but it allows more flexibility.

### UUID

Expand Down
16 changes: 8 additions & 8 deletions doc/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion doc/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"devDependencies": {
"autoprefixer": "^10.4.0",
"postcss": "^8.4.47",
"postcss": "^8.4.49",
"postcss-cli": "^11.0.0"
}
}
166 changes: 89 additions & 77 deletions lang/c++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ list(GET AVRO_VERSION 2 AVRO_VERSION_PATCH)
project (Avro-cpp)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR})

option(AVRO_BUILD_EXECUTABLES "Build executables" ON)
option(AVRO_BUILD_TESTS "Build tests" ON)

if (WIN32 AND NOT CYGWIN AND NOT MSYS)
add_definitions (/EHa)
add_definitions (
Expand All @@ -78,9 +81,12 @@ if (AVRO_ADD_PROTECTOR_FLAGS)
endif ()
endif ()


find_package (Boost 1.38 REQUIRED
COMPONENTS filesystem iostreams program_options regex system)
if (AVRO_BUILD_TESTS OR AVRO_BUILD_EXECUTABLES)
find_package (Boost 1.38 REQUIRED
COMPONENTS filesystem iostreams program_options system)
else ()
find_package (Boost 1.38 REQUIRED COMPONENTS iostreams)
endif ()

include(FetchContent)
FetchContent_Declare(
Expand Down Expand Up @@ -149,86 +155,90 @@ set_target_properties (avrocpp_s PROPERTIES
target_link_libraries (avrocpp ${Boost_LIBRARIES} ${SNAPPY_LIBRARIES} fmt::fmt-header-only)
target_include_directories(avrocpp PRIVATE ${SNAPPY_INCLUDE_DIR})

add_executable (precompile test/precompile.cc)

target_link_libraries (precompile avrocpp_s)

macro (gen file ns)
add_custom_command (OUTPUT ${file}.hh
COMMAND avrogencpp
-p -
-i ${CMAKE_CURRENT_SOURCE_DIR}/jsonschemas/${file}
-o ${file}.hh -n ${ns}
DEPENDS avrogencpp ${CMAKE_CURRENT_SOURCE_DIR}/jsonschemas/${file})
add_custom_target (${file}_hh DEPENDS ${file}.hh)
endmacro (gen)

gen (empty_record empty)
gen (bigrecord testgen)
gen (bigrecord_r testgen_r)
gen (bigrecord2 testgen2)
gen (tweet testgen3)
gen (union_array_union uau)
gen (union_map_union umu)
gen (union_conflict uc)
gen (union_empty_record uer)
gen (recursive rec)
gen (reuse ru)
gen (circulardep cd)
gen (tree1 tr1)
gen (tree2 tr2)
gen (crossref cr)
gen (primitivetypes pt)
gen (cpp_reserved_words cppres)
gen (cpp_reserved_words_union_typedef cppres_union)
gen (big_union big_union)
gen (union_redundant_types redundant_types)

add_executable (avrogencpp impl/avrogencpp.cc)
target_link_libraries (avrogencpp avrocpp_s)

target_include_directories(avrocpp_s PUBLIC
target_include_directories(avrocpp PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_include_directories(avrocpp PUBLIC
target_include_directories(avrocpp_s PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

enable_testing()

macro (unittest name)
add_executable (${name} test/${name}.cc)
target_link_libraries (${name} avrocpp ${Boost_LIBRARIES} ${SNAPPY_LIBRARIES})
add_test (NAME ${name} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${name})
endmacro (unittest)

unittest (buffertest)
unittest (unittest)
unittest (SchemaTests)
unittest (LargeSchemaTests)
unittest (CodecTests)
unittest (StreamTests)
unittest (SpecificTests)
unittest (DataFileTests)
unittest (JsonTests)
unittest (AvrogencppTests)
unittest (CompilerTests)
unittest (AvrogencppTestReservedWords)
unittest (CommonsSchemasTests)

add_dependencies (AvrogencppTestReservedWords cpp_reserved_words_hh)
add_dependencies (AvrogencppTestReservedWords cpp_reserved_words_hh
cpp_reserved_words_union_typedef_hh)

add_dependencies (AvrogencppTests bigrecord_hh bigrecord_r_hh bigrecord2_hh
tweet_hh
union_array_union_hh union_map_union_hh union_conflict_hh
recursive_hh reuse_hh circulardep_hh tree1_hh tree2_hh crossref_hh
primitivetypes_hh empty_record_hh cpp_reserved_words_union_typedef_hh
union_empty_record_hh big_union_hh union_redundant_types_hh)
if (AVRO_BUILD_EXECUTABLES)
add_executable (precompile test/precompile.cc)

target_link_libraries (precompile avrocpp_s)

macro (gen file ns)
add_custom_command (OUTPUT ${file}.hh
COMMAND avrogencpp
-p -
-i ${CMAKE_CURRENT_SOURCE_DIR}/jsonschemas/${file}
-o ${file}.hh -n ${ns}
DEPENDS avrogencpp ${CMAKE_CURRENT_SOURCE_DIR}/jsonschemas/${file})
add_custom_target (${file}_hh DEPENDS ${file}.hh)
endmacro (gen)

gen (empty_record empty)
gen (bigrecord testgen)
gen (bigrecord_r testgen_r)
gen (bigrecord2 testgen2)
gen (tweet testgen3)
gen (union_array_union uau)
gen (union_map_union umu)
gen (union_conflict uc)
gen (union_empty_record uer)
gen (recursive rec)
gen (reuse ru)
gen (circulardep cd)
gen (tree1 tr1)
gen (tree2 tr2)
gen (crossref cr)
gen (primitivetypes pt)
gen (cpp_reserved_words cppres)
gen (cpp_reserved_words_union_typedef cppres_union)
gen (big_union big_union)
gen (union_redundant_types redundant_types)

add_executable (avrogencpp impl/avrogencpp.cc)
target_link_libraries (avrogencpp avrocpp_s ${Boost_LIBRARIES})
endif ()

if (AVRO_BUILD_TESTS)
enable_testing()

macro (unittest name)
add_executable (${name} test/${name}.cc)
target_link_libraries (${name} avrocpp_s ${Boost_LIBRARIES} ${SNAPPY_LIBRARIES})
add_test (NAME ${name} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${name})
endmacro (unittest)

unittest (buffertest)
unittest (unittest)
unittest (SchemaTests)
unittest (LargeSchemaTests)
unittest (CodecTests)
unittest (StreamTests)
unittest (SpecificTests)
unittest (DataFileTests)
unittest (JsonTests)
unittest (AvrogencppTests)
unittest (CompilerTests)
unittest (AvrogencppTestReservedWords)
unittest (CommonsSchemasTests)

add_dependencies (AvrogencppTestReservedWords cpp_reserved_words_hh)
add_dependencies (AvrogencppTestReservedWords cpp_reserved_words_hh
cpp_reserved_words_union_typedef_hh)

add_dependencies (AvrogencppTests bigrecord_hh bigrecord_r_hh bigrecord2_hh
tweet_hh
union_array_union_hh union_map_union_hh union_conflict_hh
recursive_hh reuse_hh circulardep_hh tree1_hh tree2_hh crossref_hh
primitivetypes_hh empty_record_hh cpp_reserved_words_union_typedef_hh
union_empty_record_hh big_union_hh union_redundant_types_hh)
endif ()

include (InstallRequiredSystemLibraries)

Expand All @@ -241,7 +251,9 @@ install (TARGETS avrocpp avrocpp_s
ARCHIVE DESTINATION lib
RUNTIME DESTINATION lib)

install (TARGETS avrogencpp RUNTIME DESTINATION bin)
if (AVRO_BUILD_EXECUTABLES)
install (TARGETS avrogencpp RUNTIME DESTINATION bin)
endif ()

install (DIRECTORY include/avro DESTINATION include
FILES_MATCHING PATTERN *.hh)
Expand Down
1 change: 0 additions & 1 deletion lang/c++/examples/imaginary.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "avro/Decoder.hh"
#include "avro/Encoder.hh"
#include "avro/Specific.hh"
#include "boost/any.hpp"

namespace i {
struct cpx {
Expand Down
6 changes: 5 additions & 1 deletion lang/c++/impl/Compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,11 @@ static LogicalType makeLogicalType(const Entity &e, const Object &m) {
}

LogicalType::Type t = LogicalType::NONE;
if (typeField == "date")
if (typeField == "big-decimal"
&& !containsField(m, "precision")
&& !containsField(m, "scale"))
t = LogicalType::BIG_DECIMAL;
else if (typeField == "date")
t = LogicalType::DATE;
else if (typeField == "time-millis")
t = LogicalType::TIME_MILLIS;
Expand Down
4 changes: 2 additions & 2 deletions lang/c++/impl/CustomAttributes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

namespace avro {

boost::optional<std::string> CustomAttributes::getAttribute(const std::string &name) const {
boost::optional<std::string> result;
std::optional<std::string> CustomAttributes::getAttribute(const std::string &name) const {
std::optional<std::string> result;
std::map<std::string, std::string>::const_iterator iter =
attributes_.find(name);
if (iter == attributes_.end()) {
Expand Down
6 changes: 6 additions & 0 deletions lang/c++/impl/DataFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ boost::iostreams::zlib_params get_zlib_params() {
ret.noheader = true;
return ret;
}

} // namespace

DataFileWriterBase::DataFileWriterBase(const char *filename, const ValidSchema &schema, size_t syncInterval,
Expand Down Expand Up @@ -442,6 +443,11 @@ void DataFileReaderBase::readDataBlock() {
}

void DataFileReaderBase::close() {
stream_.reset();
eof_ = true;
objectCount_ = 0;
blockStart_ = 0;
blockEnd_ = 0;
}

static string toString(const vector<uint8_t> &v) {
Expand Down
3 changes: 3 additions & 0 deletions lang/c++/impl/LogicalType.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ void LogicalType::setScale(int32_t scale) {
void LogicalType::printJson(std::ostream &os) const {
switch (type_) {
case LogicalType::NONE: break;
case LogicalType::BIG_DECIMAL:
os << R"("logicalType": "big-decimal")";
break;
case LogicalType::DECIMAL:
os << R"("logicalType": "decimal")";
os << ", \"precision\": " << precision_;
Expand Down
7 changes: 7 additions & 0 deletions lang/c++/impl/Node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ void Node::setLogicalType(LogicalType logicalType) {
// Check that the logical type is applicable to the node type.
switch (logicalType.type()) {
case LogicalType::NONE: break;
case LogicalType::BIG_DECIMAL: {
if (type_ != AVRO_BYTES) {
throw Exception("BIG_DECIMAL logical type can annotate "
"only BYTES type");
}
break;
}
case LogicalType::DECIMAL: {
if (type_ != AVRO_BYTES && type_ != AVRO_FIXED) {
throw Exception("DECIMAL logical type can annotate "
Expand Down
6 changes: 5 additions & 1 deletion lang/c++/impl/Resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ class FixedParser : public Resolver {
size_t offset_;
};

class ResolverFactory : private boost::noncopyable {
class ResolverFactory {

template<typename T>
unique_ptr<Resolver>
Expand Down Expand Up @@ -512,6 +512,10 @@ class ResolverFactory : private boost::noncopyable {
}

public:
ResolverFactory() = default;
ResolverFactory(const ResolverFactory &) = delete;
ResolverFactory &operator=(const ResolverFactory &) = delete;

unique_ptr<Resolver>
construct(const NodePtr &writer, const NodePtr &reader, const Layout &offset) {

Expand Down
Loading

0 comments on commit 131f577

Please sign in to comment.