Package io.druid.data.input.impl

Examples of io.druid.data.input.impl.StringInputRowParser


    ObjectMapper jsonMapper = new DefaultObjectMapper();

    FireDepartment schema = new FireDepartment(
        new DataSchema(
            "foo",
            new StringInputRowParser(
                new JSONParseSpec(
                    new TimestampSpec(
                        "timestamp",
                        "auto"
                    ),
View Full Code Here


  @Test
  public void testDefaultExclusions() throws Exception
  {
    DataSchema schema = new DataSchema(
        "test",
        new StringInputRowParser(
            new JSONParseSpec(
                new TimestampSpec("time", "auto"),
                new DimensionsSpec(ImmutableList.of("dimB", "dimA"), null, null)
            ),
            null, null, null, null
View Full Code Here

  @Test
  public void testExplicitInclude() throws Exception
  {
    DataSchema schema = new DataSchema(
        "test",
        new StringInputRowParser(
            new JSONParseSpec(
                new TimestampSpec("time", "auto"),
                new DimensionsSpec(ImmutableList.of("time", "dimA", "dimB", "col2"), ImmutableList.of("dimC"), null)
            ),
            null, null, null, null
View Full Code Here

    );

    RabbitMQFirehoseFactory factory = new RabbitMQFirehoseFactory(
        connectionFactory,
        config,
        new StringInputRowParser(
            new JSONParseSpec(
                new TimestampSpec("timestamp", "auto"),
                new DimensionsSpec(
                    Arrays.asList("dim"),
                    Lists.<String>newArrayList(),
View Full Code Here

    JacksonifiedConnectionFactory connectionFactory = JacksonifiedConnectionFactory.makeDefaultConnectionFactory();

    RabbitMQFirehoseFactory factory = new RabbitMQFirehoseFactory(
        connectionFactory,
        config,
        new StringInputRowParser(
            new JSONParseSpec(
                new TimestampSpec("timestamp", "auto"),
                new DimensionsSpec(
                    Arrays.asList("dim"),
                    Lists.<String>newArrayList(),
View Full Code Here

  }

  @Override
  public Firehose connect(StringInputRowParser firehoseParser) throws IOException
  {
    final StringInputRowParser stringParser = firehoseParser;

    ConnectionOptions lyraOptions = new ConnectionOptions(this.connectionFactory);
    Config lyraConfig = new Config()
        .withRecoveryPolicy(
            new RetryPolicy()
                .withMaxRetries(config.getMaxRetries())
                .withRetryInterval(Duration.seconds(config.getRetryIntervalSeconds()))
                .withMaxDuration(Duration.seconds(config.getMaxDurationSeconds()))
        );

    String queue = config.getQueue();
    String exchange = config.getExchange();
    String routingKey = config.getRoutingKey();

    boolean durable = config.isDurable();
    boolean exclusive = config.isExclusive();
    boolean autoDelete = config.isAutoDelete();

    final Connection connection = Connections.create(lyraOptions, lyraConfig);

    connection.addShutdownListener(
        new ShutdownListener()
        {
          @Override
          public void shutdownCompleted(ShutdownSignalException cause)
          {
            log.warn(cause, "Connection closed!");
          }
        }
    );

    final Channel channel = connection.createChannel();
    channel.queueDeclare(queue, durable, exclusive, autoDelete, null);
    channel.queueBind(queue, exchange, routingKey);
    channel.addShutdownListener(
        new ShutdownListener()
        {
          @Override
          public void shutdownCompleted(ShutdownSignalException cause)
          {
            log.warn(cause, "Channel closed!");
          }
        }
    );

    // We create a QueueingConsumer that will not auto-acknowledge messages since that
    // happens on commit().
    final QueueingConsumer consumer = new QueueingConsumer(channel);
    channel.basicConsume(queue, false, consumer);

    return new Firehose()
    {
      /**
       * Storing the latest delivery as a member variable should be safe since this will only be run
       * by a single thread.
       */
      private Delivery delivery;

      /**
       * Store the latest delivery tag to be able to commit (acknowledge) the message delivery up to
       * and including this tag. See commit() for more detail.
       */
      private long lastDeliveryTag;

      @Override
      public boolean hasMore()
      {
        delivery = null;
        try {
          // Wait for the next delivery. This will block until something is available.
          delivery = consumer.nextDelivery();
          if (delivery != null) {
            lastDeliveryTag = delivery.getEnvelope().getDeliveryTag();
            // If delivery is non-null, we report that there is something more to process.
            return true;
          }
        }
        catch (InterruptedException e) {
          // A little unclear on how we should handle this.

          // At any rate, we're in an unknown state now so let's log something and return false.
          log.wtf(e, "Got interrupted while waiting for next delivery. Doubt this should ever happen.");
        }

        // This means that delivery is null or we caught the exception above so we report that we have
        // nothing more to process.
        return false;
      }

      @Override
      public InputRow nextRow()
      {
        if (delivery == null) {
          //Just making sure.
          log.wtf("I have nothing in delivery. Method hasMore() should have returned false.");
          return null;
        }

        return stringParser.parse(new String(delivery.getBody(), Charsets.UTF_8));
      }

      @Override
      public Runnable commit()
      {
View Full Code Here

              },
              Charsets.UTF_8
          ),
          new LineProcessor<Integer>()
          {
            StringInputRowParser parser = new StringInputRowParser(
                new DelimitedParseSpec(
                    new TimestampSpec("ts", "iso"),
                    new DimensionsSpec(Arrays.asList(DIMENSIONS), null, null),
                    "\t",
                    "\u0001",
                    Arrays.asList(COLUMNS)
                ),
                null, null, null, null
            );
            boolean runOnce = false;
            int lineCount = 0;

            @Override
            public boolean processLine(String line) throws IOException
            {
              if (!runOnce) {
                startTime.set(System.currentTimeMillis());
                runOnce = true;
              }

              retVal.add(parser.parse(line));

              ++lineCount;
              return true;
            }
View Full Code Here

        }
      }

      this.dataSchema = new DataSchema(
          dataSource,
          new StringInputRowParser(
              dataSpec == null ? null : dataSpec.toParseSpec(theTimestampSpec, dimensionExclusions),
              null, null, null, null
          ),
          rollupSpec == null
          ? new AggregatorFactory[]{}
View Full Code Here

TOP

Related Classes of io.druid.data.input.impl.StringInputRowParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.