Example #1
0
  @Test
  public void testCollectUnknownReference() throws Throwable {
    expectedException.expect(UnhandledServerException.class);
    expectedException.expectMessage("Unknown Reference some.table.some_column");

    Reference unknownReference =
        new Reference(
            new ReferenceInfo(
                new ReferenceIdent(new TableIdent("some", "table"), "some_column"),
                RowGranularity.NODE,
                DataTypes.BOOLEAN));
    CollectPhase collectNode =
        new CollectPhase(
            UUID.randomUUID(),
            0,
            "unknown",
            testRouting,
            Collections.<Symbol>singletonList(unknownReference),
            EMPTY_PROJECTIONS);
    collectNode.maxRowGranularity(RowGranularity.NODE);
    try {
      getBucket(collectNode);
    } catch (ExecutionException e) {
      throw e.getCause();
    }
  }
Example #2
0
  @Test
  public void testUnknownFunction() throws Throwable {
    // will be wrapped somewhere above
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Cannot find implementation for function unknown()");

    Symbol unknownFunction =
        new Function(
            new FunctionInfo(
                new FunctionIdent("unknown", ImmutableList.<DataType>of()), DataTypes.BOOLEAN),
            ImmutableList.<Symbol>of());
    CollectPhase collectNode =
        new CollectPhase(
            UUID.randomUUID(),
            0,
            "unknownFunction",
            testRouting,
            Collections.singletonList(unknownFunction),
            EMPTY_PROJECTIONS);
    try {
      getBucket(collectNode);
    } catch (ExecutionException e) {
      throw e.getCause();
    }
  }
Example #3
0
  @Test
  public void testWrongRouting() throws Exception {

    expectedException.expect(UnhandledServerException.class);
    expectedException.expectMessage("unsupported routing");

    CollectPhase collectNode =
        new CollectPhase(
            UUID.randomUUID(),
            0,
            "wrong",
            new Routing(
                TreeMapBuilder.<String, Map<String, List<Integer>>>newMapBuilder()
                    .put(
                        "bla",
                        TreeMapBuilder.<String, List<Integer>>newMapBuilder()
                            .put("my_index", Arrays.asList(1))
                            .put("my_index", Arrays.asList(1))
                            .map())
                    .map()),
            ImmutableList.<Symbol>of(),
            EMPTY_PROJECTIONS);
    collectNode.maxRowGranularity(RowGranularity.DOC);
    operation.collect(collectNode, new CollectingProjector(), null);
  }
Example #4
0
  @Test
  public void testCollectShardExpressions() throws Exception {
    List<Symbol> toCollect = ImmutableList.<Symbol>of(testShardIdReference);
    CollectPhase collectNode =
        new CollectPhase(
            UUID.randomUUID(), 0, "shardCollect", shardRouting(0, 1), toCollect, EMPTY_PROJECTIONS);
    collectNode.maxRowGranularity(RowGranularity.SHARD);

    Bucket result = getBucket(collectNode);
    assertThat(result.size(), is(2));
    assertThat(result, containsInAnyOrder(isRow(0), isRow(1)));
  }
 private CollectPhase getCollectNode(
     List<Symbol> toCollect, Routing routing, WhereClause whereClause) {
   return new CollectPhase(
       UUID.randomUUID(),
       0,
       "docCollect",
       routing,
       RowGranularity.DOC,
       toCollect,
       ImmutableList.<Projection>of(),
       whereClause,
       DistributionInfo.DEFAULT_BROADCAST);
 }
Example #6
0
 @Test
 public void testCollectLiterals() throws Exception {
   List<Symbol> toCollect =
       Arrays.<Symbol>asList(
           Literal.newLiteral("foobar"),
           Literal.newLiteral(true),
           Literal.newLiteral(1),
           Literal.newLiteral(4.2));
   CollectPhase collectNode =
       new CollectPhase(
           UUID.randomUUID(), 0, "literals", testRouting, toCollect, EMPTY_PROJECTIONS);
   Bucket result = getBucket(collectNode);
   assertThat(result, contains(isRow(new BytesRef("foobar"), true, 1, 4.2)));
 }
Example #7
0
 @Test
 public void testCollectShardExpressionsLiteralsAndNodeExpressions() throws Exception {
   CollectPhase collectNode =
       new CollectPhase(
           UUID.randomUUID(),
           0,
           "shardCollect",
           shardRouting(0, 1),
           Arrays.asList(testShardIdReference, Literal.newLiteral(true), testNodeReference),
           EMPTY_PROJECTIONS);
   collectNode.maxRowGranularity(RowGranularity.SHARD);
   Bucket result = getBucket(collectNode);
   assertThat(result.size(), is(2));
   assertThat(result, containsInAnyOrder(isRow(0, true, (short) 1), isRow(1, true, (short) 1)));
 }
Example #8
0
 @Test
 public void testCollectFunction() throws Exception {
   Function twoTimesTruthFunction = new Function(TestFunction.info, TO_COLLECT_TEST_REF);
   CollectPhase collectNode =
       new CollectPhase(
           UUID.randomUUID(),
           0,
           "unknown",
           testRouting,
           Arrays.asList(twoTimesTruthFunction, testNodeReference),
           EMPTY_PROJECTIONS);
   collectNode.maxRowGranularity(RowGranularity.NODE);
   Bucket result = getBucket(collectNode);
   assertThat(result.size(), equalTo(1));
   assertThat(result, contains(isRow(2, (short) 1)));
 }
Example #9
0
  @Test
  public void testCollectExpressions() throws Exception {
    CollectPhase collectNode =
        new CollectPhase(
            UUID.randomUUID(),
            0,
            "collect",
            testRouting,
            Collections.<Symbol>singletonList(testNodeReference),
            EMPTY_PROJECTIONS);
    collectNode.maxRowGranularity(RowGranularity.NODE);

    Bucket result = getBucket(collectNode);

    assertThat(result.size(), equalTo(1));
    assertThat(result, contains(isRow((short) 1)));
  }
Example #10
0
 @Test
 public void testCollectWithFalseWhereClause() throws Exception {
   CollectPhase collectNode =
       new CollectPhase(
           UUID.randomUUID(),
           0,
           "whereClause",
           testRouting,
           TO_COLLECT_TEST_REF,
           EMPTY_PROJECTIONS);
   collectNode.whereClause(
       new WhereClause(
           new Function(
               AndOperator.INFO,
               Arrays.<Symbol>asList(Literal.newLiteral(false), Literal.newLiteral(false)))));
   Bucket result = getBucket(collectNode);
   assertThat(result.size(), is(0));
 }
Example #11
0
 @Test
 public void testCollectWithTrueWhereClause() throws Exception {
   CollectPhase collectNode =
       new CollectPhase(
           UUID.randomUUID(),
           0,
           "whereClause",
           testRouting,
           TO_COLLECT_TEST_REF,
           EMPTY_PROJECTIONS);
   collectNode.whereClause(
       new WhereClause(
           new Function(
               AndOperator.INFO,
               Arrays.<Symbol>asList(Literal.newLiteral(true), Literal.newLiteral(true)))));
   collectNode.maxRowGranularity(RowGranularity.NODE);
   Bucket result = getBucket(collectNode);
   assertThat(result, contains(isRow((short) 1)));
 }
Example #12
0
  @Test
  public void testCollectShardExpressionsWhereShardIdIs0() throws Exception {
    EqOperator op =
        (EqOperator)
            functions.get(
                new FunctionIdent(
                    EqOperator.NAME,
                    ImmutableList.<DataType>of(DataTypes.INTEGER, DataTypes.INTEGER)));

    List<Symbol> toCollect = ImmutableList.<Symbol>of(testShardIdReference);
    CollectPhase collectNode =
        new CollectPhase(
            UUID.randomUUID(), 0, "shardCollect", shardRouting(0, 1), toCollect, EMPTY_PROJECTIONS);
    collectNode.whereClause(
        new WhereClause(
            new Function(op.info(), Arrays.asList(testShardIdReference, Literal.newLiteral(0)))));
    collectNode.maxRowGranularity(RowGranularity.SHARD);
    Bucket result = getBucket(collectNode);
    assertThat(result, contains(isRow(0)));
  }
Example #13
0
 @Test
 public void testCollectWithNullWhereClause() throws Exception {
   EqOperator op =
       (EqOperator)
           functions.get(
               new FunctionIdent(
                   EqOperator.NAME,
                   ImmutableList.<DataType>of(DataTypes.INTEGER, DataTypes.INTEGER)));
   CollectPhase collectNode =
       new CollectPhase(
           UUID.randomUUID(),
           0,
           "whereClause",
           testRouting,
           TO_COLLECT_TEST_REF,
           EMPTY_PROJECTIONS);
   collectNode.whereClause(
       new WhereClause(
           new Function(op.info(), Arrays.<Symbol>asList(Literal.NULL, Literal.NULL))));
   Bucket result = getBucket(collectNode);
   assertThat(result.size(), is(0));
 }
  @Test
  public void testFileUriCollect() throws Exception {
    ClusterService clusterService = mock(ClusterService.class);
    DiscoveryNode discoveryNode = mock(DiscoveryNode.class);
    when(discoveryNode.id()).thenReturn("dummyNodeId");
    DiscoveryNodes discoveryNodes = mock(DiscoveryNodes.class);
    when(discoveryNodes.localNodeId()).thenReturn("dummyNodeId");
    ClusterState clusterState = mock(ClusterState.class);
    when(clusterState.nodes()).thenReturn(discoveryNodes);
    when(clusterService.state()).thenReturn(clusterState);
    DiscoveryService discoveryService = mock(DiscoveryService.class);
    when(discoveryService.localNode()).thenReturn(discoveryNode);
    IndicesService indicesService = mock(IndicesService.class);
    Functions functions =
        new Functions(
            ImmutableMap.<FunctionIdent, FunctionImplementation>of(),
            ImmutableMap.<String, DynamicFunctionResolver>of());
    ReferenceResolver referenceResolver =
        new ReferenceResolver() {
          @Override
          public ReferenceImplementation getImplementation(ReferenceIdent ident) {
            return null;
          }
        };

    NodeSettingsService nodeSettingsService = mock(NodeSettingsService.class);

    MapSideDataCollectOperation collectOperation =
        new MapSideDataCollectOperation(
            clusterService,
            ImmutableSettings.EMPTY,
            mock(TransportActionProvider.class, Answers.RETURNS_DEEP_STUBS.get()),
            mock(BulkRetryCoordinatorPool.class),
            functions,
            referenceResolver,
            mock(NodeSysExpression.class),
            indicesService,
            new ThreadPool(
                ImmutableSettings.builder().put("name", getClass().getName()).build(), null),
            new CollectServiceResolver(
                discoveryService,
                new SystemCollectService(
                    discoveryService,
                    functions,
                    new StatsTables(ImmutableSettings.EMPTY, nodeSettingsService))),
            mock(InformationSchemaCollectService.class),
            mock(UnassignedShardsCollectService.class));

    File tmpFile = temporaryFolder.newFile("fileUriCollectOperation.json");
    try (FileWriter writer = new FileWriter(tmpFile)) {
      writer.write("{\"name\": \"Arthur\", \"id\": 4, \"details\": {\"age\": 38}}\n");
      writer.write("{\"id\": 5, \"name\": \"Trillian\", \"details\": {\"age\": 33}}\n");
    }

    Routing routing =
        new Routing(
            TreeMapBuilder.<String, Map<String, List<Integer>>>newMapBuilder()
                .put("dummyNodeId", new TreeMap<String, List<Integer>>())
                .map());
    FileUriCollectPhase collectNode =
        new FileUriCollectPhase(
            UUID.randomUUID(),
            0,
            "test",
            routing,
            Literal.newLiteral(Paths.get(tmpFile.toURI()).toUri().toString()),
            Arrays.<Symbol>asList(
                createReference("name", DataTypes.STRING),
                createReference(new ColumnIdent("details", "age"), DataTypes.INTEGER)),
            Arrays.<Projection>asList(),
            null,
            false);
    CollectingProjector cd = new CollectingProjector();
    cd.startProjection(mock(ExecutionState.class));
    collectOperation.collect(collectNode, cd, mock(JobCollectContext.class));
    assertThat(cd.result().get(), contains(isRow("Arthur", 38), isRow("Trillian", 33)));
  }