Package org.kitesdk.morphline.base

Examples of org.kitesdk.morphline.base.Configs


        private final String type;
        private final ByteArrayValueMapper byteArrayMapper;

        // also see ByteArrayExtractors
        public Mapping(Config config, MorphlineContext context) {
            Configs configs = new Configs();
            this.inputColumn = resolveColumnName(configs.getString(config, "inputColumn"));
            this.columnFamily = Bytes.toBytes(splitFamilyAndQualifier(inputColumn)[0]);
           
            String qualifierString = splitFamilyAndQualifier(inputColumn)[1];
            this.isWildCard = qualifierString.endsWith("*");
            if (isWildCard) {
                qualifierString = qualifierString.substring(0, qualifierString.length() - 1);
            }
            this.qualifier = Bytes.toBytes(qualifierString);
           
            String outputField = configs.getString(config, "outputField", null);
            this.outputFieldNames = configs.getStringList(config, "outputFields", null);
            if (outputField == null && outputFieldNames == null) {
              throw new MorphlineCompilationException("Either outputField or outputFields must be defined", config);
            }
            if (outputField != null && outputFieldNames != null) {
              throw new MorphlineCompilationException("Must not define both outputField and outputFields at the same time", config);
            }
            if (outputField == null) {
              this.isDynamicOutputFieldName = false;
              this.outputFieldName = null;
            } else {
              this.isDynamicOutputFieldName = outputField.endsWith("*");
              if (isDynamicOutputFieldName) {
                  this.outputFieldName = outputField.substring(0, outputField.length() - 1);
              } else {
                  this.outputFieldName = outputField;
              }
            }
           
            this.type = configs.getString(config, "type", "byte[]");
            if (type.equals("byte[]")) { // pass through byte[] to downstream morphline commands without conversion
                this.byteArrayMapper = new ByteArrayValueMapper() {
                    @Override
                    public Collection map(byte[] input) {
                        return Collections.singletonList(input);
                    }
                };
            } else {
                this.byteArrayMapper = ByteArrayValueMappers.getMapper(type);
            }

            LowerCaseValueSource source = new Validator<LowerCaseValueSource>().validateEnum(config,
                    configs.getString(config, "source", LowerCaseValueSource.value.toString()),
                    LowerCaseValueSource.class);

            if (source == LowerCaseValueSource.value) {
                if (isWildCard) {
                    this.extractor = new PrefixMatchingCellExtractor(columnFamily, qualifier);
                } else {
                    this.extractor = new SingleCellExtractor(columnFamily, qualifier);
                }
            } else {
                if (isWildCard) {
                    this.extractor = new PrefixMatchingQualifierExtractor(columnFamily, qualifier);
                } else {
                    throw new IllegalArgumentException("Can't create a non-prefix-based qualifier extractor");
                }
            }
           
            configs.validateArguments(config);
            if (context instanceof HBaseMorphlineContext) {
                ((HBaseMorphlineContext)context).getExtractors().add(this.extractor);
            }
        }
View Full Code Here


    assertTimeUnitEquals(TimeUnit.NANOSECONDS, "ns");
  }
 
  private void assertTimeUnitEquals(TimeUnit unit, String str) {
    Config config = ConfigFactory.parseString("foo : " + str);
    assertSame(unit, new Configs().getTimeUnit(config, "foo"));   
  }
View Full Code Here

 
  @Test
  public void testEmptyStringThrowsSyntaxError() throws Exception {
    Config config = ConfigFactory.parseString("foo : \"\"");
    try {
      new Configs().getTimeUnit(config, "foo");
      fail();
    } catch (IllegalArgumentException e) {
      ; // expected
    }
  }
View Full Code Here

  }
 
  @Test
  public void testValidateArgumentsWithoutQuotes() throws Exception {
    Config config = ConfigFactory.parseString("{ foo : bar, see : you.there.soon }");
    Configs configs = new Configs();
    assertEquals("bar", configs.getString(config, "foo"));
    assertEquals("you.there.soon", configs.getString(config, "see"));
    configs.validateArguments(config);   
  }
View Full Code Here

  }
 
  @Test
  public void testValidateArgumentsWithQuotes() throws Exception {
    Config config = ConfigFactory.parseString("{ foo : bar, \"see\" : \"you.there.soon.~!@#$%^&*()_+=-\" }");
    Configs configs = new Configs();
    assertEquals("bar", configs.getString(config, "foo"));
    assertEquals("you.there.soon.~!@#$%^&*()_+=-", configs.getString(config, "see"));
    configs.validateArguments(config);   
  }
View Full Code Here

    assertNameValueEquals(trimQuote(key), trimQuote(value), config);
    assertNameValueEquals2(trimQuote(key), trimQuote(value), config);
  }
 
  private void assertNameValueEquals(String key, String value, Config config) {
    for (Map.Entry<String, Object> entry : new Configs().getEntrySet(config)) {
      assertEquals(key, entry.getKey());
      assertEquals(value, entry.getValue());
    }
  }
View Full Code Here

 
  @Test
  public void testCompletelyEmpty() throws Exception {
    String str = "{}";
    Config config = ConfigFactory.parseString(str);
    MetricFilter filter = PatternMetricFilter.parse(new Configs(), config);
    assertSame(filter, MetricFilter.ALL);
    assertTrue(filter.matches("foo", new Counter()));
  }
View Full Code Here

 
  @Test
  public void testEmpty() throws Exception {
    String str = "{ metricFilter : {} }";
    Config config = ConfigFactory.parseString(str);
    MetricFilter filter = PatternMetricFilter.parse(new Configs(), config);
    assertNotSame(filter, MetricFilter.ALL);
    assertTrue(filter.matches("foo", new Counter()));
    assertTrue(filter.toString().length() > 0);
  }
View Full Code Here

      "\n \"literal:foo.bar\" : \"glob:*\"" +
      "\n \"literal:boo\" : \"glob:*Timer\"" +
      "\n }}}";

    Config config = ConfigFactory.parseString(str);
    MetricFilter filter = PatternMetricFilter.parse(new Configs(), config);
    assertNotSame(filter, MetricFilter.ALL);
    assertTrue(filter.matches("foo", new Counter()));
    assertTrue(filter.matches("boo", new Counter()));
    assertFalse(filter.matches("foo.bar", new Counter()));
    assertFalse(filter.matches("boo", new Timer()));
View Full Code Here

      "\n \"literal:foo\" : \"glob:*\"" +
      "\n }" +
      "\n }}";

    Config config = ConfigFactory.parseString(str);
    MetricFilter filter = PatternMetricFilter.parse(new Configs(), config);
    assertNotSame(filter, MetricFilter.ALL);
    assertTrue(filter.matches("foo", new Counter()));
    assertFalse(filter.matches("boo", new Counter()));
    assertTrue(filter.toString().length() > 0);
  }
View Full Code Here

TOP

Related Classes of org.kitesdk.morphline.base.Configs

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.