Skip to content

Commit dba105f

Browse files
ahilgerfacebook-github-bot
authored andcommitted
add annotation for key-sorted order serialization
Summary: Enables key-sorted ordering on serialize for `set` and `map` respectively. This is needed to unblock thrift-py3 inplace migration rollout. Reviewed By: createdbysk Differential Revision: D77412601 fbshipit-source-id: 60c3d90a62256ba54c8b77d3dbe9cb7b5218de43
1 parent 97814ee commit dba105f

File tree

34 files changed

+2790
-6
lines changed

34 files changed

+2790
-6
lines changed

third-party/thrift/src/thrift/annotation/python.thrift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,17 @@ struct Py3EnableCppAdapter {}
112112
@scope.Struct
113113
@scope.Exception
114114
struct MigrationBlockingAllowInheritance {}
115+
116+
/// Enables sorted order for a field with `set` type.
117+
/// Only affects serialization for thrift-python and thrift-py3.
118+
/// Note that `set` in thrift-python has no stable ordering once deserialized.
119+
/// DO NOT RELY on this. Brittle tests that rely on this will eventually be disabled.
120+
@scope.Field
121+
struct DeprecatedSortSetOnSerialize {}
122+
123+
/// Enables key-sorted order for a field with `map` type.
124+
/// Only affects thrift-python and thrift-py3.
125+
/// Note that key sorting only occurs on serialization, and not on deserialization.
126+
/// DO NOT RELY on this. Brittle tests that rely on this will eventually be disabled.
127+
@scope.Field
128+
struct DeprecatedKeySortMapOnSerialize {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/**
2+
* Autogenerated by Thrift
3+
*
4+
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5+
* @generated
6+
*/
7+
package com.facebook.thrift.annotation.python_deprecated;
8+
9+
import java.util.List;
10+
import java.util.ArrayList;
11+
import java.util.Map;
12+
import java.util.HashMap;
13+
import java.util.Set;
14+
import java.util.HashSet;
15+
import java.util.Collections;
16+
import java.util.BitSet;
17+
import java.util.Arrays;
18+
import com.facebook.thrift.*;
19+
import com.facebook.thrift.annotations.*;
20+
import com.facebook.thrift.async.*;
21+
import com.facebook.thrift.meta_data.*;
22+
import com.facebook.thrift.server.*;
23+
import com.facebook.thrift.transport.*;
24+
import com.facebook.thrift.protocol.*;
25+
26+
/**
27+
* Enables key-sorted order for a field with `map` type.
28+
* Only affects thrift-python and thrift-py3.
29+
* Note that key sorting only occurs on serialization, and not on deserialization.
30+
* DO NOT RELY on this. Brittle tests that rely on this will eventually be disabled.
31+
*/
32+
@SuppressWarnings({ "unused", "serial" })
33+
public class DeprecatedKeySortMapOnSerialize implements TBase, java.io.Serializable, Cloneable {
34+
private static final TStruct STRUCT_DESC = new TStruct("DeprecatedKeySortMapOnSerialize");
35+
36+
37+
public DeprecatedKeySortMapOnSerialize() {
38+
}
39+
40+
/**
41+
* Performs a deep copy on <i>other</i>.
42+
*/
43+
public DeprecatedKeySortMapOnSerialize(DeprecatedKeySortMapOnSerialize other) {
44+
}
45+
46+
public DeprecatedKeySortMapOnSerialize deepCopy() {
47+
return new DeprecatedKeySortMapOnSerialize(this);
48+
}
49+
50+
@Override
51+
public boolean equals(Object _that) {
52+
if (_that == null)
53+
return false;
54+
if (this == _that)
55+
return true;
56+
if (!(_that instanceof DeprecatedKeySortMapOnSerialize))
57+
return false;
58+
DeprecatedKeySortMapOnSerialize that = (DeprecatedKeySortMapOnSerialize)_that;
59+
60+
return true;
61+
}
62+
63+
@Override
64+
public int hashCode() {
65+
return Arrays.deepHashCode(new Object[] {});
66+
}
67+
68+
// This is required to satisfy the TBase interface, but can't be implemented on immutable struture.
69+
public void read(TProtocol iprot) throws TException {
70+
throw new TException("unimplemented in android immutable structure");
71+
}
72+
73+
public static DeprecatedKeySortMapOnSerialize deserialize(TProtocol iprot) throws TException {
74+
TField __field;
75+
iprot.readStructBegin();
76+
while (true)
77+
{
78+
__field = iprot.readFieldBegin();
79+
if (__field.type == TType.STOP) {
80+
break;
81+
}
82+
switch (__field.id)
83+
{
84+
default:
85+
TProtocolUtil.skip(iprot, __field.type);
86+
break;
87+
}
88+
iprot.readFieldEnd();
89+
}
90+
iprot.readStructEnd();
91+
92+
DeprecatedKeySortMapOnSerialize _that;
93+
_that = new DeprecatedKeySortMapOnSerialize(
94+
);
95+
_that.validate();
96+
return _that;
97+
}
98+
99+
public void write(TProtocol oprot) throws TException {
100+
validate();
101+
102+
oprot.writeStructBegin(STRUCT_DESC);
103+
oprot.writeFieldStop();
104+
oprot.writeStructEnd();
105+
}
106+
107+
@Override
108+
public String toString() {
109+
return toString(1, true);
110+
}
111+
112+
@Override
113+
public String toString(int indent, boolean prettyPrint) {
114+
return TBaseHelper.toStringHelper(this, indent, prettyPrint);
115+
}
116+
117+
public void validate() throws TException {
118+
// check for required fields
119+
}
120+
121+
}
122+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/**
2+
* Autogenerated by Thrift
3+
*
4+
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5+
* @generated
6+
*/
7+
package com.facebook.thrift.annotation.python_deprecated;
8+
9+
import java.util.List;
10+
import java.util.ArrayList;
11+
import java.util.Map;
12+
import java.util.HashMap;
13+
import java.util.Set;
14+
import java.util.HashSet;
15+
import java.util.Collections;
16+
import java.util.BitSet;
17+
import java.util.Arrays;
18+
import com.facebook.thrift.*;
19+
import com.facebook.thrift.annotations.*;
20+
import com.facebook.thrift.async.*;
21+
import com.facebook.thrift.meta_data.*;
22+
import com.facebook.thrift.server.*;
23+
import com.facebook.thrift.transport.*;
24+
import com.facebook.thrift.protocol.*;
25+
26+
/**
27+
* Enables sorted order for a field with `set` type.
28+
* Only affects serialization for thrift-python and thrift-py3.
29+
* Note that `set` in thrift-python has no stable ordering once deserialized.
30+
* DO NOT RELY on this. Brittle tests that rely on this will eventually be disabled.
31+
*/
32+
@SuppressWarnings({ "unused", "serial" })
33+
public class DeprecatedSortSetOnSerialize implements TBase, java.io.Serializable, Cloneable {
34+
private static final TStruct STRUCT_DESC = new TStruct("DeprecatedSortSetOnSerialize");
35+
36+
37+
public DeprecatedSortSetOnSerialize() {
38+
}
39+
40+
/**
41+
* Performs a deep copy on <i>other</i>.
42+
*/
43+
public DeprecatedSortSetOnSerialize(DeprecatedSortSetOnSerialize other) {
44+
}
45+
46+
public DeprecatedSortSetOnSerialize deepCopy() {
47+
return new DeprecatedSortSetOnSerialize(this);
48+
}
49+
50+
@Override
51+
public boolean equals(Object _that) {
52+
if (_that == null)
53+
return false;
54+
if (this == _that)
55+
return true;
56+
if (!(_that instanceof DeprecatedSortSetOnSerialize))
57+
return false;
58+
DeprecatedSortSetOnSerialize that = (DeprecatedSortSetOnSerialize)_that;
59+
60+
return true;
61+
}
62+
63+
@Override
64+
public int hashCode() {
65+
return Arrays.deepHashCode(new Object[] {});
66+
}
67+
68+
// This is required to satisfy the TBase interface, but can't be implemented on immutable struture.
69+
public void read(TProtocol iprot) throws TException {
70+
throw new TException("unimplemented in android immutable structure");
71+
}
72+
73+
public static DeprecatedSortSetOnSerialize deserialize(TProtocol iprot) throws TException {
74+
TField __field;
75+
iprot.readStructBegin();
76+
while (true)
77+
{
78+
__field = iprot.readFieldBegin();
79+
if (__field.type == TType.STOP) {
80+
break;
81+
}
82+
switch (__field.id)
83+
{
84+
default:
85+
TProtocolUtil.skip(iprot, __field.type);
86+
break;
87+
}
88+
iprot.readFieldEnd();
89+
}
90+
iprot.readStructEnd();
91+
92+
DeprecatedSortSetOnSerialize _that;
93+
_that = new DeprecatedSortSetOnSerialize(
94+
);
95+
_that.validate();
96+
return _that;
97+
}
98+
99+
public void write(TProtocol oprot) throws TException {
100+
validate();
101+
102+
oprot.writeStructBegin(STRUCT_DESC);
103+
oprot.writeFieldStop();
104+
oprot.writeStructEnd();
105+
}
106+
107+
@Override
108+
public String toString() {
109+
return toString(1, true);
110+
}
111+
112+
@Override
113+
public String toString(int indent, boolean prettyPrint) {
114+
return TBaseHelper.toStringHelper(this, indent, prettyPrint);
115+
}
116+
117+
public void validate() throws TException {
118+
// check for required fields
119+
}
120+
121+
}
122+

third-party/thrift/src/thrift/compiler/test/fixtures/adapter/out/go/gen-go/thrift/annotation/python/codec.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,24 @@ var (
101101
NewFunc: func() thrift.Struct { return NewMigrationBlockingAllowInheritance() },
102102
},
103103
}
104+
premadeCodecTypeSpec_python_DeprecatedSortSetOnSerialize = &thrift.TypeSpec{
105+
FullName: "python.DeprecatedSortSetOnSerialize",
106+
CodecStructSpec:
107+
&thrift.CodecStructSpec{
108+
ScopedName: "python.DeprecatedSortSetOnSerialize",
109+
IsUnion: false,
110+
NewFunc: func() thrift.Struct { return NewDeprecatedSortSetOnSerialize() },
111+
},
112+
}
113+
premadeCodecTypeSpec_python_DeprecatedKeySortMapOnSerialize = &thrift.TypeSpec{
114+
FullName: "python.DeprecatedKeySortMapOnSerialize",
115+
CodecStructSpec:
116+
&thrift.CodecStructSpec{
117+
ScopedName: "python.DeprecatedKeySortMapOnSerialize",
118+
IsUnion: false,
119+
NewFunc: func() thrift.Struct { return NewDeprecatedKeySortMapOnSerialize() },
120+
},
121+
}
104122
)
105123

106124
// Premade struct specs
@@ -264,6 +282,32 @@ var (
264282
FieldSpecNameToIndex: map[string]int{
265283
},
266284
}
285+
premadeStructSpec_DeprecatedSortSetOnSerialize =
286+
&thrift.StructSpec{
287+
Name: "DeprecatedSortSetOnSerialize",
288+
ScopedName: "python.DeprecatedSortSetOnSerialize",
289+
IsUnion: false,
290+
IsException: false,
291+
FieldSpecs: []thrift.FieldSpec{
292+
},
293+
FieldSpecIDToIndex: map[int16]int{
294+
},
295+
FieldSpecNameToIndex: map[string]int{
296+
},
297+
}
298+
premadeStructSpec_DeprecatedKeySortMapOnSerialize =
299+
&thrift.StructSpec{
300+
Name: "DeprecatedKeySortMapOnSerialize",
301+
ScopedName: "python.DeprecatedKeySortMapOnSerialize",
302+
IsUnion: false,
303+
IsException: false,
304+
FieldSpecs: []thrift.FieldSpec{
305+
},
306+
FieldSpecIDToIndex: map[int16]int{
307+
},
308+
FieldSpecNameToIndex: map[string]int{
309+
},
310+
}
267311
)
268312

269313
var premadeCodecSpecsMap = func() map[string]*thrift.TypeSpec {
@@ -278,6 +322,8 @@ var premadeCodecSpecsMap = func() map[string]*thrift.TypeSpec {
278322
fbthriftTypeSpecsMap[premadeCodecTypeSpec_python_UseCAPI.FullName] = premadeCodecTypeSpec_python_UseCAPI
279323
fbthriftTypeSpecsMap[premadeCodecTypeSpec_python_Py3EnableCppAdapter.FullName] = premadeCodecTypeSpec_python_Py3EnableCppAdapter
280324
fbthriftTypeSpecsMap[premadeCodecTypeSpec_python_MigrationBlockingAllowInheritance.FullName] = premadeCodecTypeSpec_python_MigrationBlockingAllowInheritance
325+
fbthriftTypeSpecsMap[premadeCodecTypeSpec_python_DeprecatedSortSetOnSerialize.FullName] = premadeCodecTypeSpec_python_DeprecatedSortSetOnSerialize
326+
fbthriftTypeSpecsMap[premadeCodecTypeSpec_python_DeprecatedKeySortMapOnSerialize.FullName] = premadeCodecTypeSpec_python_DeprecatedKeySortMapOnSerialize
281327
return fbthriftTypeSpecsMap
282328
}()
283329

third-party/thrift/src/thrift/compiler/test/fixtures/adapter/out/go/gen-go/thrift/annotation/python/metadata.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ var (
8585
Name: "python.MigrationBlockingAllowInheritance",
8686
},
8787
}
88+
premadeThriftType_python_DeprecatedSortSetOnSerialize =
89+
&metadata.ThriftType{
90+
TStruct:
91+
&metadata.ThriftStructType{
92+
Name: "python.DeprecatedSortSetOnSerialize",
93+
},
94+
}
95+
premadeThriftType_python_DeprecatedKeySortMapOnSerialize =
96+
&metadata.ThriftType{
97+
TStruct:
98+
&metadata.ThriftStructType{
99+
Name: "python.DeprecatedKeySortMapOnSerialize",
100+
},
101+
}
88102
)
89103

90104
var premadeThriftTypesMap = func() map[string]*metadata.ThriftType {
@@ -99,6 +113,8 @@ var premadeThriftTypesMap = func() map[string]*metadata.ThriftType {
99113
fbthriftThriftTypesMap["python.UseCAPI"] = premadeThriftType_python_UseCAPI
100114
fbthriftThriftTypesMap["python.Py3EnableCppAdapter"] = premadeThriftType_python_Py3EnableCppAdapter
101115
fbthriftThriftTypesMap["python.MigrationBlockingAllowInheritance"] = premadeThriftType_python_MigrationBlockingAllowInheritance
116+
fbthriftThriftTypesMap["python.DeprecatedSortSetOnSerialize"] = premadeThriftType_python_DeprecatedSortSetOnSerialize
117+
fbthriftThriftTypesMap["python.DeprecatedKeySortMapOnSerialize"] = premadeThriftType_python_DeprecatedKeySortMapOnSerialize
102118
return fbthriftThriftTypesMap
103119
}()
104120

@@ -214,6 +230,26 @@ var structMetadatas = func() []*metadata.ThriftStruct {
214230
},
215231
)
216232
}()
233+
func() {
234+
fbthriftResults = append(fbthriftResults,
235+
&metadata.ThriftStruct{
236+
Name: "python.DeprecatedSortSetOnSerialize",
237+
IsUnion: false,
238+
Fields: []*metadata.ThriftField{
239+
},
240+
},
241+
)
242+
}()
243+
func() {
244+
fbthriftResults = append(fbthriftResults,
245+
&metadata.ThriftStruct{
246+
Name: "python.DeprecatedKeySortMapOnSerialize",
247+
IsUnion: false,
248+
Fields: []*metadata.ThriftField{
249+
},
250+
},
251+
)
252+
}()
217253
return fbthriftResults
218254
}()
219255

0 commit comments

Comments
 (0)