Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
1bcdadb
Encoer v1 with interop data
jklamer Apr 22, 2022
afee9fd
unit tested
jklamer Apr 23, 2022
a89010d
fmt
jklamer Apr 23, 2022
a67a35c
Interop tested
jklamer Apr 23, 2022
d955204
uneed file
jklamer Apr 23, 2022
8141d2e
remove bugs
jklamer Apr 23, 2022
6821a02
clippy
jklamer Apr 23, 2022
de03d26
fix README
jklamer Apr 26, 2022
b0e3e22
rat fix
jklamer Apr 26, 2022
15b91c5
Update lang/rust/avro/src/writer.rs
jklamer May 1, 2022
cf9f394
Update lang/rust/avro/src/writer.rs
jklamer May 1, 2022
b4663b3
Update lang/rust/avro/src/writer.rs
jklamer May 1, 2022
2b91fcf
Update lang/rust/avro/src/writer.rs
jklamer May 1, 2022
061b89d
Update lang/rust/avro/src/writer.rs
jklamer May 1, 2022
8a971d2
PR changes
jklamer May 1, 2022
7588433
static setup
jklamer May 1, 2022
8041112
Specific rename and interop test in script
jklamer May 4, 2022
3aeceae
typo
jklamer May 4, 2022
c6ac535
AVRO-3492: Add support for deriving Schema::Record aliases (#1647)
martin-g Apr 18, 2022
65f8d0e
AVRO-3494: Rust: uncomment some tests which actually pass
martin-g Apr 18, 2022
3aa2c37
AVRO-3494: Uncomment a test for recursive types (#1648)
martin-g Apr 18, 2022
db855f6
AVRO-3492: Add logic to derive the aliases for Schema::Enum (#1649)
martin-g Apr 18, 2022
7679228
AVRO-3415: Add code coverage report support for csharp (#1565)
KyleSchoonover Apr 19, 2022
0d5a022
AVRO-3384: Define C# Coding Style Guidelines (#1534)
KyleSchoonover Apr 19, 2022
b465b39
AVRO-3424: Added support to parse string into Schema.Type (#1571)
KyleSchoonover Apr 19, 2022
7f82a81
AVRO-3003: Fully qualify enum default value in C# code gen (#1596)
massada Apr 19, 2022
328f590
AVRO-3458: Added tests for GenericRecord (#1606)
KyleSchoonover Apr 19, 2022
16efcc3
AVRO-2883: Fix namespace mapping (#1610)
zcsizmadia Apr 19, 2022
9556eb4
AVRO-2211: SchemaBuilder equivalent or other means of schema creation…
yanivru Apr 19, 2022
bfc5165
AVRO-3841: Try exact schema match first in union type (#1635)
zcsizmadia Apr 19, 2022
bd3307f
AVRO-3495: Rust: Fields order should not matter (#1650)
martin-g Apr 19, 2022
2fff83d
Bump slf4j.version from 1.7.33 to 1.7.36 in /lang/java (#1646)
dependabot[bot] Apr 19, 2022
6ede153
AVRO-3491 Avoid a cast after is check (#1645)
KyleSchoonover Apr 19, 2022
25c43c1
AVRO-3496: Rust: Use visitor.visit_borrowed_str() when possible (#1652)
martin-g Apr 19, 2022
73d22fa
AVRO-3477: Add unit tests for logical types with fixed base type (#1629)
zcsizmadia Apr 19, 2022
8c9f3fa
AVRO-3465: Add avrogen protocol tests (#1616)
zcsizmadia Apr 20, 2022
7e7e286
AVRO-3484: Add support for deriving a default value for a record fiel…
martin-g Apr 20, 2022
80ecb27
AVRO-3497 Simplify conditional expression (#1658)
KyleSchoonover Apr 20, 2022
9cb9275
AVRO-3500: Use property-based testing for the IT tests in avro_derive…
martin-g Apr 20, 2022
faa355c
Configure Dependabot to check for Rust updates daily
martin-g Apr 21, 2022
1d59139
AVRO-3501: Rust: Cache ~/.cargo and target folder for faster builds (…
martin-g Apr 21, 2022
d0b679c
Avro 3502 logical type wrong order (#1664)
martin-g Apr 21, 2022
7d060ab
Update uuid requirement from 0.8.2 to 1.0.0 in /lang/rust (#1660)
dependabot[bot] Apr 21, 2022
b44b520
Bump jmh.version from 1.34 to 1.35 in /lang/java (#1662)
dependabot[bot] Apr 21, 2022
19bd662
Bump zstd-jni from 1.5.1-1 to 1.5.2-2 in /lang/java (#1663)
dependabot[bot] Apr 21, 2022
95643ae
Bump libthrift from 0.15.0 to 0.16.0 in /lang/java (#1665)
dependabot[bot] Apr 21, 2022
31c4bc3
AVRO-3498 Deprecate NameCtorKey (#1657)
KyleSchoonover Apr 21, 2022
cddea87
AVRO-3490 Updated to use throw expressions (#1644)
KyleSchoonover Apr 21, 2022
ddbb8cc
Bump grpc.version from 1.45.0 to 1.45.1 in /lang/java (#1671)
dependabot[bot] Apr 25, 2022
7ab95ec
Bump underscore from 1.13.2 to 1.13.3 in /lang/js (#1669)
dependabot[bot] Apr 25, 2022
0aa6da2
AVRO-3484: Followup Check default json parsing at compile time for de…
jklamer Apr 25, 2022
4731dee
AVRO-3427: skip creation of namespace directories for csharp schema (…
kordos Apr 25, 2022
b63eacb
AVRO-3482: Reuse MAGIC in DataFileReader (#1639)
rbalamohan Apr 27, 2022
8f9dd6f
AVRO-2870: Avoid throwing from destructor in DataFileWriterBase (#921)
oandrew Apr 30, 2022
7735001
Updated the checksum for PHP composer download (#1677)
thiru-mg May 2, 2022
5f109d6
Remove trailing ^M to make Git happy
martin-g May 3, 2022
18ddaf5
Encoer v1 with interop data
jklamer Apr 22, 2022
6545a4b
unit tested
jklamer Apr 23, 2022
91f75be
fmt
jklamer Apr 23, 2022
adc8add
AVRO-3506: Cleanup and minor improvements
martin-g May 4, 2022
01600ec
AVRO-3506: Cleanup
martin-g May 4, 2022
94a4be0
Merge branch 'master' into jklamer/SingleObjectWriter
martin-g May 4, 2022
8640187
AVRO-3506: Add licence header to TestGenerateInteropSingleObjectEncoding
martin-g May 4, 2022
77de905
AVRO-3506: Fix spotless issues in the new Java test classes
martin-g May 4, 2022
651f769
AVRO-3506: Fix the path to the schema file
martin-g May 4, 2022
47d0f82
AVRO-3506: Fix the id to match the expected value
martin-g May 4, 2022
a31a195
AVRO-3506: Fix spotless again
martin-g May 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lang/csharp/src/apache/main/CodeGen/CodeGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ private static string ReplaceMappedNamespacesInSchema(string input, IEnumerable<
if (namespaceMapping == null || input == null)
return input;

// Replace namespace in "namespace" definitions:
// Replace namespace in "namespace" definitions:
// "namespace": "originalnamespace" -> "namespace": "mappednamespace"
// "namespace": "originalnamespace.whatever" -> "namespace": "mappednamespace.whatever"
// Note: It keeps the original whitespaces
Expand Down
4 changes: 2 additions & 2 deletions lang/csharp/src/apache/test/Schema/SchemaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private static void testToString(Schema sc, string schema)
{
try
{
//remove any excess spaces in the JSON to normalize the match with toString
//remove any excess spaces in the JSON to normalize the match with toString
schema = schema.Replace("{ ", "{")
.Replace("} ", "}")
.Replace("\" ", "\"")
Expand Down Expand Up @@ -575,7 +575,7 @@ public void TestUnion(string s, Schema.Type[] types)

UnionSchema schema = UnionSchema.Create(types.Select(t => (Schema)PrimitiveSchema.Create(t)).ToList());
Assert.AreEqual(sc, schema);

Assert.AreEqual(Schema.Type.Union, sc.Tag);
UnionSchema us = (UnionSchema)sc;
Assert.AreEqual(types.Length, us.Count);
Expand Down
10 changes: 5 additions & 5 deletions lang/csharp/src/apache/test/Util/LogicalTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void TestDecimal(
"-123456789123456789.56",
"000000000000000001.01",
"-000000000000000001.01"
)] string s,
)] string s,
[Values(
"\"bytes\"",
"{\"type\": \"fixed\", \"size\": 16, \"name\": \"n\"}"
Expand All @@ -94,7 +94,7 @@ public void TestDecimalScale(
"-1234567891234567890123456789",
"0000000000000000000000000001",
"-0000000000000000000000000001"
)] string s,
)] string s,
[Values(1, 2, 3, 4, 5, 6, 7, 8)] int scale,
[Values(
"\"bytes\"",
Expand Down Expand Up @@ -313,7 +313,7 @@ public void TestLocalTimestampMicrosecond(string s, string e)
}

expectedDate = expectedDate.ToLocalTime();

var avroLocalTimestampMicro = new LocalTimestampMicrosecond();
var convertedDate = (DateTime)avroLocalTimestampMicro.ConvertToLogicalValue(avroLocalTimestampMicro.ConvertToBaseValue(date, schema), schema);
Assert.AreEqual(expectedDate, convertedDate);
Expand Down Expand Up @@ -342,7 +342,7 @@ public void TestTimeMillisecond(string s, string e, bool expectRangeError)
var timeMilliSchema = (LogicalSchema)Schema.Parse("{\"type\": \"int\", \"logicalType\": \"time-millis\"}");

var time = TimeSpan.Parse(s);

var avroTimeMilli = new TimeMillisecond();

if (expectRangeError)
Expand Down Expand Up @@ -385,7 +385,7 @@ public void TestTimeMicrosecond(string s, string e, bool expectRangeError)
var timeMicroSchema = (LogicalSchema)Schema.Parse("{\"type\": \"long\", \"logicalType\": \"time-micros\"}");

var time = TimeSpan.Parse(s);

var avroTimeMicro = new TimeMicrosecond();

if (expectRangeError)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.avro.message;

import org.apache.avro.Schema;
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericRecordBuilder;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Arrays;

/**
* Generates <code>test_message.bin</code> - a <a href=
* "https://avro.apache.org/docs/current/spec.html#single_object_encoding">single
* object encoded</a> Avro message.
*/
public class TestGenerateInteropSingleObjectEncoding {
private static final String RESOURCES_FOLDER = System.getProperty("share.dir", "../../../share")
+ "/test/data/messageV1";
private static final File SCHEMA_FILE = new File(RESOURCES_FOLDER + "/test_schema.avsc");
private static final File MESSAGE_FILE = new File(RESOURCES_FOLDER + "/test_message.bin");
private static Schema SCHEMA;
private static GenericRecordBuilder BUILDER;

@BeforeClass
public static void setup() throws IOException {
try (FileInputStream fileInputStream = new FileInputStream(SCHEMA_FILE)) {
SCHEMA = new Schema.Parser().parse(fileInputStream);
BUILDER = new GenericRecordBuilder(SCHEMA);
}
}

@Test
public void generateData() throws IOException {
MessageEncoder<GenericData.Record> encoder = new BinaryMessageEncoder<>(GenericData.get(), SCHEMA);
BUILDER.set("id", 42L).set("name", "Bill").set("tags", Arrays.asList("dog_lover", "cat_hater")).build();
ByteBuffer buffer = encoder.encode(
BUILDER.set("id", 42L).set("name", "Bill").set("tags", Arrays.asList("dog_lover", "cat_hater")).build());
new FileOutputStream(MESSAGE_FILE).write(buffer.array());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.avro.message;

import org.apache.avro.Schema;
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericRecordBuilder;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.util.Arrays;

/**
* Tests that <code>test_message.bin</code> is properly encoded <a href=
* "https://avro.apache.org/docs/current/spec.html#single_object_encoding">single
* object</a>
*/
public class TestInteropSingleObjectEncoding {
private static final String RESOURCES_FOLDER = System.getProperty("share.dir", "../../../share")
+ "/test/data/messageV1";
private static final File SCHEMA_FILE = new File(RESOURCES_FOLDER + "/test_schema.avsc");
private static final File MESSAGE_FILE = new File(RESOURCES_FOLDER + "/test_message.bin");
private static Schema SCHEMA;
private static GenericRecordBuilder BUILDER;

@BeforeClass
public static void setup() throws IOException {
try (FileInputStream fileInputStream = new FileInputStream(SCHEMA_FILE)) {
SCHEMA = new Schema.Parser().parse(fileInputStream);
BUILDER = new GenericRecordBuilder(SCHEMA);
}
}

@Test
public void checkSingleObjectEncoding() throws IOException {
MessageEncoder<GenericData.Record> encoder = new BinaryMessageEncoder<>(GenericData.get(), SCHEMA);
ByteBuffer buffer = encoder.encode(
BUILDER.set("id", 42L).set("name", "Bill").set("tags", Arrays.asList("dog_lover", "cat_hater")).build());
byte[] fileBuffer = Files.readAllBytes(MESSAGE_FILE.toPath());
Assert.assertArrayEquals(fileBuffer, buffer.array());
}
}
60 changes: 60 additions & 0 deletions lang/rust/avro/examples/test_interop_single_object_encoding.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

use apache_avro::{schema::AvroSchema, types::Value};

const RESOURCES_FOLDER: &str = "../../share/test/data/messageV1";

struct InteropMessage;

impl AvroSchema for InteropMessage {
fn get_schema() -> apache_avro::Schema {
let schema = std::fs::read_to_string(format!("{}/test_schema.avsc", RESOURCES_FOLDER))
.expect("File should exist with schema inside");
apache_avro::Schema::parse_str(schema.as_str())
.expect("File should exist with schema inside")
}
}

impl From<InteropMessage> for Value {
fn from(_: InteropMessage) -> Value {
Value::Record(vec![
("id".into(), 42i64.into()),
("name".into(), "Bill".into()),
(
"tags".into(),
Value::Array(
vec!["dog_lover", "cat_hater"]
.into_iter()
.map(|s| s.into())
.collect(),
),
),
])
}
}

fn main() {
let file_message = std::fs::read(format!("{}/test_message.bin", RESOURCES_FOLDER))
.expect("File with single object not found or error occurred while reading");
let mut generated_encoding: Vec<u8> = Vec::new();
apache_avro::SingleObjectWriter::<InteropMessage>::with_capacity(1024)
.expect("resolve expected")
.write_value(InteropMessage, &mut generated_encoding)
.expect("Should encode");
assert_eq!(file_message, generated_encoding)
}
16 changes: 10 additions & 6 deletions lang/rust/avro/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
// under the License.

use crate::{
schema::{NamesRef, Namespace, ResolvedSchema, Schema, SchemaKind},
schema::{Name, Namespace, ResolvedSchema, Schema, SchemaKind},
types::{Value, ValueKind},
util::{zig_i32, zig_i64},
AvroResult, Error,
};
use std::convert::{TryFrom, TryInto};
use std::{
borrow::Borrow,
collections::HashMap,
convert::{TryFrom, TryInto},
};

/// Encode a `Value` into avro format.
///
Expand All @@ -47,19 +51,19 @@ fn encode_int(i: i32, buffer: &mut Vec<u8>) {
zig_i32(i, buffer)
}

pub(crate) fn encode_internal(
pub(crate) fn encode_internal<S: Borrow<Schema>>(
value: &Value,
schema: &Schema,
names: &NamesRef,
names: &HashMap<Name, S>,
enclosing_namespace: &Namespace,
buffer: &mut Vec<u8>,
) -> AvroResult<()> {
if let Schema::Ref { ref name } = schema {
let fully_qualified_name = name.fully_qualified_name(enclosing_namespace);
let resolved = *names
let resolved = names
.get(&fully_qualified_name)
.ok_or(Error::SchemaResolutionError(fully_qualified_name))?;
return encode_internal(value, resolved, names, enclosing_namespace, buffer);
return encode_internal(value, resolved.borrow(), names, enclosing_namespace, buffer);
}

match value {
Expand Down
4 changes: 4 additions & 0 deletions lang/rust/avro/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ pub enum Error {
value_kind: ValueKind,
supported_schema: Vec<SchemaKind>,
},
#[error(
"Internal buffer not drained properly. Re-initialize the single object writer struct!"
)]
IllegalSingleObjectWriterState,
}

impl serde::ser::Error for Error {
Expand Down
2 changes: 1 addition & 1 deletion lang/rust/avro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ pub use reader::{from_avro_datum, Reader};
pub use schema::Schema;
pub use ser::to_value;
pub use util::max_allocation_bytes;
pub use writer::{to_avro_datum, Writer};
pub use writer::{to_avro_datum, GenericSingleObjectWriter, SingleObjectWriter, Writer};

#[macro_use]
extern crate log;
Expand Down
Loading