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 java.util.List;
 
 import static com.facebook.presto.RowPagesBuilder.rowPagesBuilder;
 import static com.facebook.presto.SessionTestUtils.TEST_SESSION;
 import static com.facebook.presto.operator.OperatorAssertion.assertOperatorEquals;
 import static com.facebook.presto.spi.type.BigintType.BIGINT;
 import static com.facebook.presto.spi.type.DoubleType.DOUBLE;
 import static com.facebook.presto.spi.type.TypeSignature.parseTypeSignature;
 import static com.facebook.presto.testing.MaterializedResult.resultBuilder;
 import static com.facebook.presto.testing.TestingTaskContext.createTaskContext;
 import static io.airlift.concurrent.Threads.daemonThreadsNamed;
 import static java.lang.Double.NEGATIVE_INFINITY;
 import static java.lang.Double.NaN;
 import static java.lang.Double.POSITIVE_INFINITY;
 import static java.util.concurrent.Executors.newCachedThreadPool;
 
 @Test(singleThreaded = true)
 public class TestUnnestOperator
 {
     private ExecutorService executor;
     private DriverContext driverContext;
 
     @BeforeMethod
     public void setUp()
     {
          = newCachedThreadPool(daemonThreadsNamed("test-%s"));
 
                 .addPipelineContext(truetrue)
                 .addDriverContext();
     }
 
     @AfterMethod
     public void tearDown()
     {
         .shutdownNow();
     }
 
     @Test
     public void testUnnest()
             throws Exception
     {
         MetadataManager metadata = MetadataManager.createTestMetadataManager();
         Type arrayType = metadata.getType(parseTypeSignature("array<bigint>"));
         Type mapType = metadata.getType(parseTypeSignature("map<bigint,bigint>"));
 
         List<Pageinput = rowPagesBuilder(arrayTypemapType)
                 .row(1, ArrayType.toStackRepresentation(ImmutableList.of(2, 3), ), MapType.toStackRepresentation(ImmutableMap.of(4, 5), ))
                 .row(2, ArrayType.toStackRepresentation(ImmutableList.of(99), ), null)
                 .row(3, nullnull)
                 .pageBreak()
                 .row(6, ArrayType.toStackRepresentation(ImmutableList.of(7, 8), ), MapType.toStackRepresentation(ImmutableMap.of(9, 10, 11, 12), ))
                 .build();
 
         OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory(
                 0, ImmutableList.of(0), ImmutableList.<Type>of(), ImmutableList.of(1, 2), ImmutableList.of(arrayTypemapType), false);
         Operator operator = operatorFactory.createOperator();
 
                 .row(1, 2, 4, 5)
                 .row(1, 3, nullnull)
                 .row(2, 99, nullnull)
                 .row(6, 7, 9, 10)
                 .row(6, 8, 11, 12)
                 .build();
 
         assertOperatorEquals(operatorinputexpected);
     }
 
     @Test
     public void testUnnestWithOrdinality()
            throws Exception
    {
        MetadataManager metadata = MetadataManager.createTestMetadataManager();
        Type arrayType = metadata.getType(parseTypeSignature("array<bigint>"));
        Type mapType = metadata.getType(parseTypeSignature("map<bigint,bigint>"));
        List<Pageinput = rowPagesBuilder(arrayTypemapType)
                .row(1, ArrayType.toStackRepresentation(ImmutableList.of(2, 3), ), MapType.toStackRepresentation(ImmutableMap.of(4, 5), ))
                .row(2, ArrayType.toStackRepresentation(ImmutableList.of(99), ), null)
                .row(3, nullnull)
                .pageBreak()
                .row(6, ArrayType.toStackRepresentation(ImmutableList.of(7, 8), ), MapType.toStackRepresentation(ImmutableMap.of(9, 10, 11, 12), ))
                .build();
        OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory(
                0, ImmutableList.of(0), ImmutableList.<Type>of(), ImmutableList.of(1, 2), ImmutableList.of(arrayTypemapType), true);
        Operator operator = operatorFactory.createOperator();
                .row(1, 2, 4, 5, 1)
                .row(1, 3, nullnull, 2)
                .row(2, 99, nullnull, 1)
                .row(6, 7, 9, 10, 1)
                .row(6, 8, 11, 12, 2)
                .build();
        assertOperatorEquals(operatorinputexpected);
    }
    @Test
    public void testUnnestNonNumericDoubles()
            throws Exception
    {
        MetadataManager metadata = MetadataManager.createTestMetadataManager();
        Type arrayType = metadata.getType(parseTypeSignature("array<double>"));
        Type mapType = metadata.getType(parseTypeSignature("map<bigint,double>"));
        List<Pageinput = rowPagesBuilder(arrayTypemapType)
                .row(1, ArrayType.toStackRepresentation(ImmutableList.of(.), ),
                        MapType.toStackRepresentation(ImmutableMap.of(1, , 2, , 3, ), ))
                .build();
        OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory(
                0, ImmutableList.of(0), ImmutableList.<Type>of(), ImmutableList.of(1, 2), ImmutableList.of(arrayTypemapType), false);
        Operator operator = operatorFactory.createOperator();
                .row(1, , 1, )
                .row(1, , 2, )
                .row(1, , 3, )
                .build();
        assertOperatorEquals(operatorinputexpected);
    }
New to GrepCode? Check out our FAQ X