Package org.elasticsearch.hadoop.util

Examples of org.elasticsearch.hadoop.util.FieldAlias


            return false;
        }

        TupleEntry entry = sourceCall.getIncomingEntry();
        Map data = (Map) context[1];
        FieldAlias alias = (FieldAlias) context[2];

        if (entry.getFields().isDefined()) {
            // lookup using writables
            Text lookupKey = new Text();
            // TODO: it's worth benchmarking whether using an index/offset yields significantly better performance
            for (Comparable<?> field : entry.getFields()) {
                if (IS_ES_10) {
                    // check for multi-level alias
                    Object result = data;
                    for (String level : StringUtils.tokenize(alias.toES(field.toString()), ".")) {
                        lookupKey.set(level);
                        result = ((Map) result).get(lookupKey);
                        if (result == null) {
                            break;
                        }
                    }
                    CascadingUtils.setObject(entry, field, result);
                }
                else {
                    lookupKey.set(alias.toES(field.toString()));
                    CascadingUtils.setObject(entry, field, data.get(lookupKey));
                }
            }
        }
        else {
View Full Code Here


            return false;
        }

        TupleEntry entry = sourceCall.getIncomingEntry();
        Map<String, ?> data = (Map<String, ?>) query.next()[1];
        FieldAlias alias = (FieldAlias) sourceCall.getContext()[0];

        if (entry.getFields().isDefined()) {
            // lookup using writables
            // TODO: it's worth benchmarking whether using an index/offset yields significantly better performance
            for (Comparable<?> field : entry.getFields()) {
                if (IS_ES_10) {
                    Object result = data;
                    // check for multi-level alias
                    for (String level : StringUtils.tokenize(alias.toES(field.toString()), ".")) {
                        result = ((Map) result).get(level);
                        if (result == null) {
                            break;
                        }
                    }
                    entry.setObject(field, result);
                }
                else {
                    //NB: coercion should be applied automatically by the TupleEntry
                    entry.setObject(field, data.get(alias.toES(field.toString())));
                }
            }
        }
        else {
            // no definition means no coercion
View Full Code Here

            }
        }
    }

    static FieldAlias alias(Settings settings) {
        return new FieldAlias(SettingsUtils.aliases(settings.getProperty(MAPPING_NAMES)));
    }
View Full Code Here

        return names;
    }

    static Collection<String> fieldToAlias(Settings settings, Fields fields) {
        FieldAlias fa = alias(settings);
        List<String> names = asStrings(fields);
        for (int i = 0; i < names.size(); i++) {
            String original = names.get(i);
            String alias = fa.toES(original);
            if (alias != null) {
                names.set(i, alias);
            }
        }
        return names;
View Full Code Here

            return new DateTime(esDate, DateTimeZone.UTC);
        }
    }

    static FieldAlias alias(Settings settings) {
        return new FieldAlias(SettingsUtils.aliases(settings.getProperty(MAPPING_NAMES)));
    }
View Full Code Here

        }
    }

    static String asProjection(RequiredFieldList list, Properties props) {
        List<String> fields = new ArrayList<String>();
        FieldAlias alias = alias(new PropertiesSettings(props));
        for (RequiredField field : list.getFields()) {
            addField(field, fields, alias, "");
        }

        return StringUtils.concatenateAndUriEncode(fields, ",");
View Full Code Here

    }

    public PigValueWriter(boolean useTupleFieldNames) {
        writeUnknownTypes = false;
        this.useTupleFieldNames = useTupleFieldNames;
        alias = new FieldAlias();
    }
View Full Code Here

    @Test
    public void testFieldMap() throws Exception {
        Properties tableProperties = new Properties();
        tableProperties.put(HiveConstants.MAPPING_NAMES, "timestamp:@timestamp , foo:123foo");
        FieldAlias alias = HiveUtils.alias(new PropertiesSettings(tableProperties));
        assertEquals("@timestamp", alias.toES("timestamp"));
        assertEquals("123foo", alias.toES("foo"));
        assertEquals("bar", alias.toES("BaR"));
    }
View Full Code Here

    @Test
    public void testFieldMapWithColumns() throws Exception {
        Properties tableProperties = new Properties();
        tableProperties.put(HiveConstants.MAPPING_NAMES, "timestamp:@timestamp , foo:123foo");
        tableProperties.put(HiveConstants.COLUMNS, "id,name,timestamp,foo");
        FieldAlias alias = HiveUtils.alias(new PropertiesSettings(tableProperties));
        assertEquals("@timestamp", alias.toES("timestamp"));
        assertEquals("123foo", alias.toES("foo"));
        assertEquals("bar", alias.toES("BaR"));
    }
View Full Code Here

    private FieldAlias alias;

    public HiveValueWriter() {
        this.writeUnknownTypes = false;
        this.writableWriter = new HiveWritableValueWriter(false);
        this.alias = new FieldAlias();
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.hadoop.util.FieldAlias

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.