Skip to content

Commit c1c8557

Browse files
committed
Updated JSON nested operations to properly escape any dynamically created JSONPointer instances.
1 parent 06cc0e2 commit c1c8557

13 files changed

+33
-12
lines changed

CHANGES.txt

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ Cascading Change Log
22

33
4.6.0 [unreleased]
44

5+
Updated JSON nested operations to properly escape any dynamically created JSONPointer instances.
6+
57
Updated c.t.h.i.TapOutputCollector to initialize the filenamePattern after Tap#sinkConfInit has been called.
68

79
Fixed issue where c.t.l.h.LocalHfsAdaptor would not copy back applied properties during source/sink init phase.

cascading-nested-json/src/main/java/cascading/nested/json/JSONBuildAsAggregator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
/**
3232
* Class JSONBuildAsAggregator provides for the ability to create new JSON objects from aggregated tuple values.
3333
*
34-
* @see <a href=https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
34+
* @see <a href="https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
3535
* @see NestedBaseBuildAggregator for more details.
3636
*/
3737
public class JSONBuildAsAggregator extends NestedBaseBuildAggregator<JsonNode, ArrayNode>

cascading-nested-json/src/main/java/cascading/nested/json/JSONBuildAsFunction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
/**
3232
* Class JSONBuildAsFunction provides for the ability to create new JSON objects from streamed tuple values.
3333
*
34-
* @see <a href=https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
34+
* @see <a href="https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
3535
* @see NestedBaseBuildFunction for more details.
3636
*/
3737
public class JSONBuildAsFunction extends NestedBaseBuildFunction<JsonNode, ArrayNode>

cascading-nested-json/src/main/java/cascading/nested/json/JSONBuildIntoFunction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
/**
3232
* Class JSONBuildIntoFunction provides for the ability to update existing JSON objects from streamed tuple values.
3333
*
34-
* @see <a href=https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
34+
* @see <a href="https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
3535
* @see NestedBaseBuildFunction for more details.
3636
*/
3737
public class JSONBuildIntoFunction extends NestedBaseBuildFunction<JsonNode, ArrayNode>

cascading-nested-json/src/main/java/cascading/nested/json/JSONCopyAsFunction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* Class JSONCopyAsFunction provides for the ability to create new JSON objects from an existing
3333
* JSON object.
3434
*
35-
* @see <a href=https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
35+
* @see <a href="https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
3636
* @see NestedBaseCopyFunction for more details.
3737
*/
3838
public class JSONCopyAsFunction extends NestedBaseCopyFunction<JsonNode, ArrayNode>

cascading-nested-json/src/main/java/cascading/nested/json/JSONCopyIntoFunction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* Class JSONCopyIntoFunction provides for the ability to update an existing JSON objects from an existing
3333
* JSON object.
3434
*
35-
* @see <a href=https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
35+
* @see <a href="https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
3636
* @see NestedBaseCopyFunction for more details.
3737
*/
3838
public class JSONCopyIntoFunction extends NestedBaseCopyFunction<JsonNode, ArrayNode>

cascading-nested-json/src/main/java/cascading/nested/json/JSONCreateFunction.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* will be set on the final JSON object. This is useful for prevent null values from being set, artificially
3838
* increasing the size of the final object.
3939
*
40-
* @see <a href=https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
40+
* @see <a href="https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
4141
* @see NestedCreateFunction for more details.
4242
*/
4343
public class JSONCreateFunction extends NestedCreateFunction<JsonNode, ArrayNode>
@@ -277,4 +277,11 @@ public JSONCreateFunction( JSONCoercibleType coercibleType, Fields fieldDeclarat
277277
{
278278
super( coercibleType, fieldDeclaration, defaultValueFilter, pointerMap );
279279
}
280+
281+
@Override
282+
protected String escapePointerElement( String element )
283+
{
284+
// https://datatracker.ietf.org/doc/html/draft-ietf-appsawg-json-pointer-03#section-3
285+
return element.replace( "~", "~0" ).replace( "/", "~1" );
286+
}
280287
}

cascading-nested-json/src/main/java/cascading/nested/json/JSONGetAllAggregateFunction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* <p>
4343
* See {@link cascading.nested.core.aggregate.SimpleNestedAggregate} for a convenient base implementation.
4444
*
45-
* @see <a href=https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
45+
* @see <a href="https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
4646
* @see NestedGetAllAggregateFunction for more details.
4747
*/
4848
public class JSONGetAllAggregateFunction extends NestedGetAllAggregateFunction<JsonNode, ArrayNode>

cascading-nested-json/src/main/java/cascading/nested/json/JSONGetAllFunction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* descent reference, {@code /person/**}{@code /name}. In the later case, use an empty pointer, {@code ""}, to reference
3737
* the value of the array. Rely on the {@code fieldDeclaration} to coerce this value appropriately.
3838
*
39-
* @see <a href=https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
39+
* @see <a href="https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
4040
* @see NestedGetAllFunction for more details.
4141
*/
4242
public class JSONGetAllFunction extends NestedGetAllFunction<JsonNode, ArrayNode>

cascading-nested-json/src/main/java/cascading/nested/json/JSONGetFunction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* Class JSONGetFunction provides the ability to convert a JSON object into a single tuple where each
3333
* field value is referenced by a Json pointer in the object.
3434
*
35-
* @see <a href=https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
35+
* @see <a href="https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
3636
* @see NestedGetFunction for more details.
3737
*/
3838
public class JSONGetFunction extends NestedGetFunction<JsonNode, ArrayNode>

cascading-nested-json/src/main/java/cascading/nested/json/JSONRegexFilter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/**
3131
* Class JSONRegexFilter provides for the ability to to filter a tuple stream based on the values in a JSON object.
3232
*
33-
* @see <a href=https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
33+
* @see <a href="https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
3434
* @see NestedRegexFilter for more details.
3535
*/
3636
public class JSONRegexFilter extends NestedRegexFilter

cascading-nested-json/src/main/java/cascading/nested/json/JSONSetFunction.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
/**
3333
* Class JSONSetFunction provides for the ability to simply set multiple tuple values onto an existing JSON object.
3434
*
35-
* @see <a href=https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
35+
* @see <a href="https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
3636
* @see NestedSetFunction for more details.
3737
*/
3838
public class JSONSetFunction extends NestedSetFunction<JsonNode, ArrayNode>
@@ -145,4 +145,11 @@ public JSONSetFunction( JSONCoercibleType coercibleType, Fields fieldDeclaration
145145
{
146146
super( coercibleType, fieldDeclaration, pointerMap );
147147
}
148+
149+
@Override
150+
protected String escapePointerElement( String element )
151+
{
152+
// https://datatracker.ietf.org/doc/html/draft-ietf-appsawg-json-pointer-03#section-3
153+
return element.replace( "~", "~0" ).replace( "/", "~1" );
154+
}
148155
}

cascading-nested/src/main/java/cascading/nested/core/NestedBaseFunction.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,19 @@ public void prepare( FlowProcess flowProcess, OperationCall<NestedBaseFunction.C
123123
{
124124
Fields argument = iterator.next();
125125

126-
Pointer<Node> pointer = compiler.compile( rootPointer + "/" + argument.get( 0 ).toString() );
126+
Pointer<Node> pointer = compiler.compile( rootPointer + "/" + escapePointerElement( argument.get( 0 ).toString() ) );
127127
resolvedPointers.put( argument, new Pair<>( defaultValueFilter, pointer ) );
128128
}
129129
}
130130

131131
operationCall.setContext( new Context( resolvedPointers, Tuple.size( 1 ) ) );
132132
}
133133

134+
protected String escapePointerElement( String element )
135+
{
136+
return element;
137+
}
138+
134139
@Override
135140
public void operate( FlowProcess flowProcess, FunctionCall<NestedBaseFunction.Context> functionCall )
136141
{

0 commit comments

Comments
 (0)