Search in sources :

Example 6 with RowKeyBuilder

use of org.apache.metron.profiler.hbase.RowKeyBuilder in project metron by apache.

the class GetProfile method apply.

/**
 * Apply the function.
 * @param args The function arguments.
 * @param context
 */
@Override
public Object apply(List<Object> args, Context context) throws ParseException {
    String profile = getArg(0, String.class, args);
    String entity = getArg(1, String.class, args);
    Optional<List<ProfilePeriod>> periods = Optional.ofNullable(getArg(2, List.class, args));
    // Optional arguments
    @SuppressWarnings("unchecked") List<Object> groups = null;
    Map configOverridesMap = null;
    if (args.size() < 4) {
        // no optional args, so default 'groups' and configOverridesMap remains null.
        groups = new ArrayList<>(0);
    } else if (args.get(3) instanceof List) {
        // correct extensible usage
        groups = getArg(3, List.class, args);
        if (args.size() >= 5) {
            configOverridesMap = getArg(4, Map.class, args);
            if (configOverridesMap.isEmpty())
                configOverridesMap = null;
        }
    } else {
        // Deprecated "varargs" style usage for groups_list
        // configOverridesMap cannot be specified so it remains null.
        groups = getGroupsArg(3, args);
    }
    Map<String, Object> effectiveConfig = getEffectiveConfig(context, configOverridesMap);
    Object defaultValue = null;
    // lazily create new profiler client if needed
    if (client == null || !cachedConfigMap.equals(effectiveConfig)) {
        RowKeyBuilder rowKeyBuilder = getRowKeyBuilder(effectiveConfig);
        ColumnBuilder columnBuilder = getColumnBuilder(effectiveConfig);
        HTableInterface table = getTable(effectiveConfig);
        client = new HBaseProfilerClient(table, rowKeyBuilder, columnBuilder);
        cachedConfigMap = effectiveConfig;
    }
    if (cachedConfigMap != null) {
        defaultValue = ProfilerClientConfig.PROFILER_DEFAULT_VALUE.get(cachedConfigMap);
    }
    return client.fetch(Object.class, profile, entity, groups, periods.orElse(new ArrayList<>(0)), Optional.ofNullable(defaultValue));
}
Also used : ArrayList(java.util.ArrayList) SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) RowKeyBuilder(org.apache.metron.profiler.hbase.RowKeyBuilder) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface) HBaseProfilerClient(org.apache.metron.profiler.client.HBaseProfilerClient) ArrayList(java.util.ArrayList) List(java.util.List) ColumnBuilder(org.apache.metron.profiler.hbase.ColumnBuilder) ValueOnlyColumnBuilder(org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

RowKeyBuilder (org.apache.metron.profiler.hbase.RowKeyBuilder)6 SaltyRowKeyBuilder (org.apache.metron.profiler.hbase.SaltyRowKeyBuilder)5 ColumnBuilder (org.apache.metron.profiler.hbase.ColumnBuilder)4 ValueOnlyColumnBuilder (org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder)4 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)3 ProfileMeasurement (org.apache.metron.profiler.ProfileMeasurement)3 Before (org.junit.Before)3 HashMap (java.util.HashMap)2 DefaultStellarStatefulExecutor (org.apache.metron.stellar.common.DefaultStellarStatefulExecutor)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 Configuration (org.apache.hadoop.conf.Configuration)1 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)1 ProfileConfig (org.apache.metron.common.configuration.profiler.ProfileConfig)1 ProfileResult (org.apache.metron.common.configuration.profiler.ProfileResult)1 HTableProvider (org.apache.metron.hbase.HTableProvider)1 MockHBaseTableProvider (org.apache.metron.hbase.mock.MockHBaseTableProvider)1 MockHTable (org.apache.metron.hbase.mock.MockHTable)1