Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed 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 com.facebook.presto.operator;
 
 
 
 
 import static com.facebook.presto.spi.type.VarbinaryType.VARBINARY;
 import static com.facebook.presto.type.TypeJsonUtils.getDoubleValue;
 import static com.google.common.base.Preconditions.checkNotNull;
 
 public class MapUnnester
         extends Unnester
 {
     private final Type keyType;
     private final Type valueType;
 
     public MapUnnester(MapType mapType, @Nullable Slice slice)
     {
         super(2, slice);
         checkNotNull(mapType"mapType is null");
         this. = mapType.getKeyType();
         this. = mapType.getValueType();
     }
 
     @Override
     protected void appendTo(PageBuilder pageBuilderint outputChannelOffsetJsonParser jsonParser)
     {
         BlockBuilder keyBlockBuilder = pageBuilder.getBlockBuilder(outputChannelOffset);
         try {
             String value = jsonParser.getCurrentName();
             if (.getJavaType() == long.class) {
                 .writeLong(keyBlockBuilder, Long.valueOf(value));
             }
             else if (.getJavaType() == double.class) {
                 .writeDouble(keyBlockBuilder, Double.valueOf(value));
             }
             else if (.getJavaType() == boolean.class) {
                 .writeBoolean(keyBlockBuilder, Boolean.valueOf(value));
             }
             else if (.getJavaType() == Slice.class) {
                 Slice slice;
                 if (.equals()) {
                     slice = Slices.wrappedBuffer(BaseEncoding.base64().decode(value));
                 }
                 else {
                    slice = Slices.utf8Slice(value);
                 }
                 .writeSlice(keyBlockBuilderslice);
             }
             else {
                 throw new IllegalArgumentException("Unsupported stack type: " + .getJavaType());
             }
         }
         catch (IOException e) {
             throw Throwables.propagate(e);
         }
 
         readNextToken();
         BlockBuilder valueBlockBuilder = pageBuilder.getBlockBuilder(outputChannelOffset + 1);
         try {
             if (jsonParser.getCurrentToken() == .) {
                 valueBlockBuilder.appendNull();
             }
             else if ( instanceof ArrayType ||  instanceof MapType ||  instanceof RowType) {
                 DynamicSliceOutput dynamicSliceOutput = new DynamicSliceOutput();
                 try (JsonGenerator jsonGenerator = .createJsonGenerator(dynamicSliceOutput)) {
                     jsonGenerator.copyCurrentStructure(jsonParser);
                 }
                 .writeSlice(valueBlockBuilderdynamicSliceOutput.slice());
             }
             else if (.getJavaType() == long.class) {
                .writeLong(valueBlockBuilderjsonParser.getLongValue());
            }
            else if (.getJavaType() == double.class) {
                .writeDouble(valueBlockBuildergetDoubleValue(jsonParser));
            }
            else if (.getJavaType() == boolean.class) {
                .writeBoolean(valueBlockBuilderjsonParser.getBooleanValue());
            }
            else if (.getJavaType() == Slice.class) {
                .writeSlice(valueBlockBuilder, Slices.utf8Slice(jsonParser.getValueAsString()));
            }
            else {
                throw new IllegalArgumentException("Unsupported stack type: " + .getJavaType());
            }
        }
        catch (IOException e) {
            throw Throwables.propagate(e);
        }
    }
New to GrepCode? Check out our FAQ X