Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Hoisted Text Span Symbol Table Bug #1043

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 5 additions & 15 deletions src/main/java/com/amazon/ion/impl/IonReaderTextUserX.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2007-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file 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.
*/

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package com.amazon.ion.impl;

import static com.amazon.ion.SystemSymbols.ION_1_0;
Expand Down Expand Up @@ -267,6 +254,7 @@ private static final class IonReaderTextSpan
implements Span, TextSpan, OffsetSpan
{
private final UnifiedDataPageX _data_page;
private final SymbolTable _symbols;
private final IonType _container_type;

private final long _start_offset;
Expand All @@ -284,6 +272,7 @@ private static final class IonReaderTextSpan
// page of buffered input Which is the case for the time
// being. Later, when this is stream aware, this needs to change.
_data_page = current_stream._buffer.getCurrentPage();
_symbols = reader.getSymbolTable();
_container_type = reader.getContainerType();

_start_offset = reader._value_start_offset - reader._physical_start_offset;
Expand Down Expand Up @@ -391,6 +380,7 @@ private void hoistImpl(Span span)
}
IonType container = text_span.getContainerType();
re_init(iis, container, text_span._start_line, text_span._start_column);
_symbols = text_span._symbols;
}


Expand Down
48 changes: 48 additions & 0 deletions src/test/java/com/amazon/ion/TextSpanHoistingTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package com.amazon.ion;

import com.amazon.ion.facet.Facets;
import com.amazon.ion.system.IonReaderBuilder;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;

import java.io.IOException;

public class TextSpanHoistingTest
{
@Test
public void hoistingTextSpanAlsoHoistsSymbolTable() throws IOException {
String textWithSymbolTables =
"$ion_1_0 $ion_symbol_table::{ symbols:[\"bar\"] } { foo1: $10 }" +
"$ion_1_0 $ion_symbol_table::{ symbols:[\"baz\"] } { foo2: $10 }";

IonReader reader = IonReaderBuilder.standard().build(textWithSymbolTables);
SeekableReader seekableReader = Facets.asFacet(SeekableReader.class, reader);

Assertions.assertEquals(IonType.STRUCT, reader.next());
Span span = seekableReader.currentSpan();
reader.stepIn();
Assertions.assertEquals(IonType.SYMBOL, reader.next());
Assertions.assertEquals("foo1", reader.getFieldName());
Assertions.assertEquals("bar", reader.stringValue());
reader.stepOut();

Assertions.assertEquals(IonType.STRUCT, reader.next());
reader.stepIn();
Assertions.assertEquals(IonType.SYMBOL, reader.next());
Assertions.assertEquals("foo2", reader.getFieldName());
Assertions.assertEquals("baz", reader.stringValue());
reader.stepOut();

// now re-seek to the first value
seekableReader.hoist(span);

Assertions.assertEquals(IonType.STRUCT, reader.next());
reader.stepIn();
Assertions.assertEquals(IonType.SYMBOL, reader.next());
Assertions.assertEquals("foo1", reader.getFieldName());
Assertions.assertEquals("bar", reader.stringValue());
reader.stepOut();
}
}