[GitHub] [drill] vvysotskyi commented on a change in pull request #2068: DRILL-7717: Support Mongo extended types in V2 JSON loader

2020-05-04 Thread GitBox


vvysotskyi commented on a change in pull request #2068:
URL: https://github.com/apache/drill/pull/2068#discussion_r419241974



##
File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/store/easy/json/values/UtcTimestampValueListener.java
##
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ */
+package org.apache.drill.exec.store.easy.json.values;
+
+import java.time.Instant;
+import java.time.ZoneId;
+
+import org.apache.drill.exec.store.easy.json.loader.JsonLoaderImpl;
+import org.apache.drill.exec.store.easy.json.parser.TokenIterator;
+import org.apache.drill.exec.vector.accessor.ScalarWriter;
+
+import com.fasterxml.jackson.core.JsonToken;
+
+/**
+ * Per the https://docs.mongodb.com/manual/reference/mongodb-extended-json-v1/#bson.data_date;>
+ * V1 docs:
+ * 
+ * In Strict mode, {@code } is an ISO-8601 date format with a mandatory 
time zone field
+ * following the template -MM-DDTHH:mm:ss.mmm<+/-Offset>.
+ * 
+ * In Shell mode, {@code } is the JSON representation of a 64-bit signed
+ * integer giving the number of milliseconds since epoch UTC.
+ * 
+ * 
+ * Drill dates are in the local time zone, so conversion is needed.
+ */
+public class UtcTimestampValueListener extends ScalarListener {
+
+  private static final ZoneId localZoneId = ZoneId.systemDefault();

Review comment:
   Please rename it to upper case.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [drill] vvysotskyi commented on a change in pull request #2068: DRILL-7717: Support Mongo extended types in V2 JSON loader

2020-05-02 Thread GitBox


vvysotskyi commented on a change in pull request #2068:
URL: https://github.com/apache/drill/pull/2068#discussion_r418995949



##
File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/store/easy/json/extended/ExtendedTypeFieldFactory.java
##
@@ -0,0 +1,207 @@
+/*
+ * 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.
+ */
+package org.apache.drill.exec.store.easy.json.extended;
+
+import org.apache.drill.common.types.TypeProtos.MinorType;
+import org.apache.drill.exec.record.metadata.MetadataUtils;
+import org.apache.drill.exec.store.easy.json.loader.BaseFieldFactory;
+import org.apache.drill.exec.store.easy.json.loader.FieldDefn;
+import org.apache.drill.exec.store.easy.json.loader.FieldFactory;
+import org.apache.drill.exec.store.easy.json.loader.JsonLoaderImpl;
+import org.apache.drill.exec.store.easy.json.parser.ElementParser;
+import org.apache.drill.exec.store.easy.json.parser.TokenIterator;
+import org.apache.drill.exec.store.easy.json.parser.ValueParser;
+import org.apache.drill.exec.store.easy.json.values.BinaryValueListener;
+import org.apache.drill.exec.store.easy.json.values.UtcDateValueListener;
+import org.apache.drill.exec.store.easy.json.values.DecimalValueListener;
+import org.apache.drill.exec.store.easy.json.values.IntervalValueListener;
+import org.apache.drill.exec.store.easy.json.values.StrictBigIntValueListener;
+import org.apache.drill.exec.store.easy.json.values.StrictDoubleValueListener;
+import org.apache.drill.exec.store.easy.json.values.StrictIntValueListener;
+import org.apache.drill.exec.store.easy.json.values.StrictStringValueListener;
+import org.apache.drill.exec.store.easy.json.values.TimeValueListener;
+import org.apache.drill.exec.store.easy.json.values.UtcTimestampValueListener;
+
+import com.fasterxml.jackson.core.JsonToken;
+
+public class ExtendedTypeFieldFactory extends BaseFieldFactory {
+
+  public ExtendedTypeFieldFactory(JsonLoaderImpl loader, FieldFactory child) {
+super(loader, child);
+  }
+
+  @Override
+  public ElementParser fieldParser(FieldDefn fieldDefn) {
+ElementParser parser = buildExtendedTypeParser(fieldDefn);
+if (parser == null) {
+  return child.fieldParser(fieldDefn);
+} else {
+  return parser;
+}
+  }
+
+  private ElementParser buildExtendedTypeParser(FieldDefn fieldDefn) {
+
+// Extended types are objects: { "$type": ... }
+// Extended arrays are [ { "$type": ...
+TokenIterator tokenizer = fieldDefn.tokenizer();
+JsonToken token = tokenizer.requireNext();
+ElementParser parser;
+switch (token) {
+  case START_OBJECT:
+parser = extendedTypeParserFor(fieldDefn, false);
+break;
+  case START_ARRAY:
+parser = arrayParserFor(fieldDefn);
+break;
+  default:
+parser = null;
+}
+tokenizer.unget(token);
+return parser;
+  }
+
+  private ElementParser arrayParserFor(FieldDefn fieldDefn) {
+TokenIterator tokenizer = fieldDefn.tokenizer();
+JsonToken token = tokenizer.requireNext();
+if (token != JsonToken.START_OBJECT) {
+  tokenizer.unget(token);
+  return null;
+}
+
+ValueParser element = extendedTypeParserFor(fieldDefn, true);
+tokenizer.unget(token);
+if (element == null) {
+  return null;
+}
+
+return scalarArrayParserFor(element);
+  }
+
+  private BaseExtendedValueParser extendedTypeParserFor(FieldDefn fieldDefn, 
boolean isArray) {
+TokenIterator tokenizer = fieldDefn.tokenizer();
+JsonToken token = tokenizer.peek();
+if (token != JsonToken.FIELD_NAME) {
+  return null;
+}
+
+String key = tokenizer.textValue().trim();
+if (!key.startsWith(ExtendedTypeNames.TYPE_PREFIX)) {
+  return null;
+}
+return parserFor(fieldDefn, key, isArray);
+  }
+
+  private BaseExtendedValueParser parserFor(FieldDefn fieldDefn, String key, 
boolean isArray) {
+switch (key) {
+case ExtendedTypeNames.LONG:
+  return numberLongParser(fieldDefn, isArray);
+case ExtendedTypeNames.DECIMAL:
+  return numberDecimalParser(fieldDefn, isArray);
+case ExtendedTypeNames.DOUBLE:
+  return numberDoubleParser(fieldDefn, isArray);
+case ExtendedTypeNames.INT:
+  return