@@ -53,65 +53,66 @@ public MongoDataConverter(ArrayEncoding arrayEncoding) {
53
53
}
54
54
55
55
public Struct convertRecord (
56
- Entry <String , BsonValue > keyvalueforStruct , Schema schema , Struct struct ) {
57
- convertFieldValue (keyvalueforStruct , struct , schema );
56
+ Entry <String , BsonValue > keyValueForStruct , Schema schema , Struct struct ) {
57
+ convertFieldValue (keyValueForStruct , struct , schema );
58
58
return struct ;
59
59
}
60
60
61
+ @ SuppressWarnings ("JavaUtilDate" )
61
62
public void convertFieldValue (
62
- Entry <String , BsonValue > keyvalueforStruct , Struct struct , Schema schema ) {
63
+ Entry <String , BsonValue > keyValueForStruct , Struct struct , Schema schema ) {
63
64
Object colValue = null ;
64
65
65
- String key = keyvalueforStruct .getKey ();
66
- BsonType type = keyvalueforStruct .getValue ().getBsonType ();
66
+ String key = keyValueForStruct .getKey ();
67
+ BsonType type = keyValueForStruct .getValue ().getBsonType ();
67
68
68
69
switch (type ) {
69
70
case NULL :
70
71
colValue = null ;
71
72
break ;
72
73
73
74
case STRING :
74
- colValue = keyvalueforStruct .getValue ().asString ().getValue ().toString ();
75
+ colValue = keyValueForStruct .getValue ().asString ().getValue ().toString ();
75
76
break ;
76
77
77
78
case OBJECT_ID :
78
- colValue = keyvalueforStruct .getValue ().asObjectId ().getValue ().toString ();
79
+ colValue = keyValueForStruct .getValue ().asObjectId ().getValue ().toString ();
79
80
break ;
80
81
81
82
case DOUBLE :
82
- colValue = keyvalueforStruct .getValue ().asDouble ().getValue ();
83
+ colValue = keyValueForStruct .getValue ().asDouble ().getValue ();
83
84
break ;
84
85
85
86
case BINARY :
86
- colValue = keyvalueforStruct .getValue ().asBinary ().getData ();
87
+ colValue = keyValueForStruct .getValue ().asBinary ().getData ();
87
88
break ;
88
89
89
90
case INT32 :
90
- colValue = keyvalueforStruct .getValue ().asInt32 ().getValue ();
91
+ colValue = keyValueForStruct .getValue ().asInt32 ().getValue ();
91
92
break ;
92
93
93
94
case INT64 :
94
- colValue = keyvalueforStruct .getValue ().asInt64 ().getValue ();
95
+ colValue = keyValueForStruct .getValue ().asInt64 ().getValue ();
95
96
break ;
96
97
97
98
case BOOLEAN :
98
- colValue = keyvalueforStruct .getValue ().asBoolean ().getValue ();
99
+ colValue = keyValueForStruct .getValue ().asBoolean ().getValue ();
99
100
break ;
100
101
101
102
case DATE_TIME :
102
- colValue = new Date (keyvalueforStruct .getValue ().asDateTime ().getValue ());
103
+ colValue = new Date (keyValueForStruct .getValue ().asDateTime ().getValue ());
103
104
break ;
104
105
105
106
case JAVASCRIPT :
106
- colValue = keyvalueforStruct .getValue ().asJavaScript ().getCode ();
107
+ colValue = keyValueForStruct .getValue ().asJavaScript ().getCode ();
107
108
break ;
108
109
109
110
case JAVASCRIPT_WITH_SCOPE :
110
111
Struct jsStruct = new Struct (schema .field (key ).schema ());
111
112
Struct jsScopeStruct = new Struct (schema .field (key ).schema ().field ("scope" ).schema ());
112
- jsStruct .put ("code" , keyvalueforStruct .getValue ().asJavaScriptWithScope ().getCode ());
113
+ jsStruct .put ("code" , keyValueForStruct .getValue ().asJavaScriptWithScope ().getCode ());
113
114
BsonDocument jwsDoc =
114
- keyvalueforStruct .getValue ().asJavaScriptWithScope ().getScope ().asDocument ();
115
+ keyValueForStruct .getValue ().asJavaScriptWithScope ().getScope ().asDocument ();
115
116
116
117
for (Entry <String , BsonValue > jwsDocKey : jwsDoc .entrySet ()) {
117
118
convertFieldValue (jwsDocKey , jsScopeStruct , schema .field (key ).schema ());
@@ -123,17 +124,17 @@ public void convertFieldValue(
123
124
124
125
case REGULAR_EXPRESSION :
125
126
Struct regexStruct = new Struct (schema .field (key ).schema ());
126
- regexStruct .put ("regex" , keyvalueforStruct .getValue ().asRegularExpression ().getPattern ());
127
- regexStruct .put ("options" , keyvalueforStruct .getValue ().asRegularExpression ().getOptions ());
127
+ regexStruct .put ("regex" , keyValueForStruct .getValue ().asRegularExpression ().getPattern ());
128
+ regexStruct .put ("options" , keyValueForStruct .getValue ().asRegularExpression ().getOptions ());
128
129
colValue = regexStruct ;
129
130
break ;
130
131
131
132
case TIMESTAMP :
132
- colValue = new Date (1000L * keyvalueforStruct .getValue ().asTimestamp ().getTime ());
133
+ colValue = new Date (1000L * keyValueForStruct .getValue ().asTimestamp ().getTime ());
133
134
break ;
134
135
135
136
case DECIMAL128 :
136
- colValue = keyvalueforStruct .getValue ().asDecimal128 ().getValue ().toString ();
137
+ colValue = keyValueForStruct .getValue ().asDecimal128 ().getValue ().toString ();
137
138
break ;
138
139
139
140
case DOCUMENT :
@@ -143,7 +144,7 @@ public void convertFieldValue(
143
144
}
144
145
Schema documentSchema = field .schema ();
145
146
Struct documentStruct = new Struct (documentSchema );
146
- BsonDocument docs = keyvalueforStruct .getValue ().asDocument ();
147
+ BsonDocument docs = keyValueForStruct .getValue ().asDocument ();
147
148
148
149
for (Entry <String , BsonValue > doc : docs .entrySet ()) {
149
150
convertFieldValue (doc , documentStruct , documentSchema );
@@ -153,7 +154,7 @@ public void convertFieldValue(
153
154
break ;
154
155
155
156
case ARRAY :
156
- if (keyvalueforStruct .getValue ().asArray ().isEmpty ()) {
157
+ if (keyValueForStruct .getValue ().asArray ().isEmpty ()) {
157
158
switch (arrayEncoding ) {
158
159
case ARRAY :
159
160
colValue = Lists .newArrayList ();
@@ -166,8 +167,8 @@ public void convertFieldValue(
166
167
} else {
167
168
switch (arrayEncoding ) {
168
169
case ARRAY :
169
- BsonType valueType = keyvalueforStruct .getValue ().asArray ().get (0 ).getBsonType ();
170
- List <BsonValue > arrValues = keyvalueforStruct .getValue ().asArray ().getValues ();
170
+ BsonType valueType = keyValueForStruct .getValue ().asArray ().get (0 ).getBsonType ();
171
+ List <BsonValue > arrValues = keyValueForStruct .getValue ().asArray ().getValues ();
171
172
List <Object > list = Lists .newArrayList ();
172
173
173
174
arrValues .forEach (
@@ -183,7 +184,7 @@ public void convertFieldValue(
183
184
colValue = list ;
184
185
break ;
185
186
case DOCUMENT :
186
- final BsonArray array = keyvalueforStruct .getValue ().asArray ();
187
+ final BsonArray array = keyValueForStruct .getValue ().asArray ();
187
188
final Map <String , BsonValue > convertedArray = Maps .newHashMap ();
188
189
final Schema arraySchema = schema .field (key ).schema ();
189
190
final Struct arrayStruct = new Struct (arraySchema );
@@ -206,11 +207,11 @@ public void convertFieldValue(
206
207
default :
207
208
return ;
208
209
}
209
- struct .put (key , keyvalueforStruct .getValue ().isNull () ? null : colValue );
210
+ struct .put (key , keyValueForStruct .getValue ().isNull () ? null : colValue );
210
211
}
211
212
212
213
// TODO FIX Cyclomatic Complexity is 30 (max allowed is 12). [CyclomaticComplexity]
213
- @ SuppressWarnings ("checkstyle:CyclomaticComplexity" )
214
+ @ SuppressWarnings ({ "checkstyle:CyclomaticComplexity" , "JavaUtilDate" } )
214
215
private void convertFieldValue (
215
216
Schema valueSchema , BsonType valueType , BsonValue arrValue , List <Object > list ) {
216
217
if (arrValue .getBsonType () == BsonType .STRING && valueType == BsonType .STRING ) {
@@ -272,9 +273,9 @@ protected String arrayElementStructName(int index) {
272
273
return "_" + index ;
273
274
}
274
275
275
- public void addFieldSchema (Entry <String , BsonValue > keyValuesforSchema , SchemaBuilder builder ) {
276
- String key = ( String ) keyValuesforSchema .getKey ();
277
- BsonType type = keyValuesforSchema .getValue ().getBsonType ();
276
+ public void addFieldSchema (Entry <String , BsonValue > keyValuesForSchema , SchemaBuilder builder ) {
277
+ String key = keyValuesForSchema .getKey ();
278
+ BsonType type = keyValuesForSchema .getValue ().getBsonType ();
278
279
279
280
switch (type ) {
280
281
case NULL :
@@ -311,19 +312,19 @@ public void addFieldSchema(Entry<String, BsonValue> keyValuesforSchema, SchemaBu
311
312
break ;
312
313
313
314
case JAVASCRIPT_WITH_SCOPE :
314
- SchemaBuilder jswithscope = SchemaBuilder .struct ().name (builder .name () + "." + key );
315
- jswithscope .field ("code" , Schema .OPTIONAL_STRING_SCHEMA );
316
- SchemaBuilder scope = SchemaBuilder .struct ().name (jswithscope .name () + ".scope" ).optional ();
315
+ SchemaBuilder jsWithScope = SchemaBuilder .struct ().name (builder .name () + "." + key );
316
+ jsWithScope .field ("code" , Schema .OPTIONAL_STRING_SCHEMA );
317
+ SchemaBuilder scope = SchemaBuilder .struct ().name (jsWithScope .name () + ".scope" ).optional ();
317
318
BsonDocument jwsDocument =
318
- keyValuesforSchema .getValue ().asJavaScriptWithScope ().getScope ().asDocument ();
319
+ keyValuesForSchema .getValue ().asJavaScriptWithScope ().getScope ().asDocument ();
319
320
320
321
for (Entry <String , BsonValue > jwsDocumentKey : jwsDocument .entrySet ()) {
321
322
addFieldSchema (jwsDocumentKey , scope );
322
323
}
323
324
324
325
Schema scopeBuild = scope .build ();
325
- jswithscope .field ("scope" , scopeBuild ).build ();
326
- builder .field (key , jswithscope );
326
+ jsWithScope .field ("scope" , scopeBuild ).build ();
327
+ builder .field (key , jsWithScope );
327
328
break ;
328
329
329
330
case REGULAR_EXPRESSION :
@@ -336,7 +337,7 @@ public void addFieldSchema(Entry<String, BsonValue> keyValuesforSchema, SchemaBu
336
337
case DOCUMENT :
337
338
SchemaBuilder builderDoc =
338
339
SchemaBuilder .struct ().name (builder .name () + "." + key ).optional ();
339
- BsonDocument docs = keyValuesforSchema .getValue ().asDocument ();
340
+ BsonDocument docs = keyValuesForSchema .getValue ().asDocument ();
340
341
341
342
for (Entry <String , BsonValue > doc : docs .entrySet ()) {
342
343
addFieldSchema (doc , builderDoc );
@@ -345,7 +346,7 @@ public void addFieldSchema(Entry<String, BsonValue> keyValuesforSchema, SchemaBu
345
346
break ;
346
347
347
348
case ARRAY :
348
- if (keyValuesforSchema .getValue ().asArray ().isEmpty ()) {
349
+ if (keyValuesForSchema .getValue ().asArray ().isEmpty ()) {
349
350
switch (arrayEncoding ) {
350
351
case ARRAY :
351
352
builder .field (
@@ -359,17 +360,17 @@ public void addFieldSchema(Entry<String, BsonValue> keyValuesforSchema, SchemaBu
359
360
} else {
360
361
switch (arrayEncoding ) {
361
362
case ARRAY :
362
- BsonArray value = keyValuesforSchema .getValue ().asArray ();
363
+ BsonArray value = keyValuesForSchema .getValue ().asArray ();
363
364
BsonType valueType = value .get (0 ).getBsonType ();
364
- testType (builder , key , keyValuesforSchema .getValue (), valueType );
365
+ testType (builder , key , keyValuesForSchema .getValue (), valueType );
365
366
builder .field (
366
367
key ,
367
368
SchemaBuilder .array (subSchema (builder , key , valueType , value ))
368
369
.optional ()
369
370
.build ());
370
371
break ;
371
372
case DOCUMENT :
372
- final BsonArray array = keyValuesforSchema .getValue ().asArray ();
373
+ final BsonArray array = keyValuesForSchema .getValue ().asArray ();
373
374
final SchemaBuilder arrayStructBuilder =
374
375
SchemaBuilder .struct ().name (builder .name () + "." + key ).optional ();
375
376
final Map <String , BsonValue > convertedArray = Maps .newHashMap ();
0 commit comments