return new ColumnImpl(this.tableName, parseEntityAttribute(value)); } else if (!tokenType.equals(TokenType.ID) && op.equals(ComparisonOperator.IN)) { return EntityQualifierUtils.parseList(value); } else if (tokenType.equals(TokenType.NUMBER)) {
public static double eval(String expression, TaggedLogAPIEntity entity) throws Exception { ExpressionParser parser = parse(expression); List<String> dependencies = parser.getDependentFields(); Map<String, Double> context = new HashMap<String, Double>(); for (String field : dependencies) { String methodName = "get" + field.substring(0, 1).toUpperCase() + field.substring(1); String methodUID = entity.getClass().getName() + "." + methodName; Method m; synchronized (_entityMethodCache) { m = _entityMethodCache.get(methodUID); if (m == null) { m = entity.getClass().getMethod(methodName); _entityMethodCache.put(methodUID, m); } } Object obj = m.invoke(entity); Double doubleValue = EntityQualifierUtils.convertObjToDouble(obj); // if(doubleValue == Double.NaN) throw new IllegalArgumentException("Field "+field+": "+obj+" in // expression "+expression+" is not number"); context.put(field, doubleValue); } return parser.eval(context); }
public static byte[] toBytes(EntityDefinition ed, String qualifierName, String qualifierValueInStr){ // Get field type from entity class // and skip for not-found fields query expression Object typedValue = null; EntitySerDeser serDeser = null; if(ed.isTag(qualifierName)){ typedValue = qualifierValueInStr; serDeser = EntityDefinitionManager.getSerDeser(String.class); }else{ try{ Field field = ed.getEntityClass().getDeclaredField(qualifierName); Class<?> fieldType = field.getType(); serDeser = EntityDefinitionManager.getSerDeser(fieldType); if(serDeser == null){ throw new IllegalArgumentException("Can't find EntitySerDeser for field: "+ qualifierName +"'s type: "+fieldType +", so the field is not supported to be filtered yet"); } typedValue = convertStringToObject(qualifierValueInStr, fieldType); } catch (NoSuchFieldException ex) { // Handle the field not found exception in caller LOG.error("Field " + qualifierName + " not found in " + ed.getEntityClass()); throw new IllegalArgumentException("Field "+qualifierName+" not found in "+ed.getEntityClass(),ex); } } return serDeser.serialize(typedValue); }
List<String> valueSet = EntityQualifierUtils.parseList(entry.getValue()); Iterator<String> it = valueSet.iterator(); String fieldName = entry.getKey(); BinaryComparator comparator = new BinaryComparator(EntityQualifierUtils.toBytes(_ed, fieldName, value)); SingleColumnValueFilter filter = new SingleColumnValueFilter(_ed.getColumnFamily().getBytes(), qualifierName.getBytes(), convertToHBaseCompareOp(entry.getOp()), comparator);
@Test public void testNegativeLongEntityQualifierHelper() { Exception ex = null; try { byte[] value = EntityQualifierUtils.toBytes(ed, "field4", "-100000"); } catch (IllegalArgumentException e) { ex = e; } Assert.assertNull(ex); }
comparable = _comparator; } else { Class type = EntityQualifierUtils.getType(ed, entry.getKey()); comparable = new BinaryComparator(EntityQualifierUtils.toBytes(ed, entry.getKey(), entry.getValue())); } else { comparable = new TypedByteArrayComparator(EntityQualifierUtils .toBytes(ed, entry.getKey(), entry.getValue()), type);
logTags.put(entry.getKey(), new String(entry.getValue())); }else if (TokenConstant.isExpression(entry.getKey())){ if(doubleMap == null) doubleMap = EntityQualifierUtils.bytesMapToDoubleMap(allQualifierValues, ed);
List<String> valueSet = EntityQualifierUtils.parseList(entry.getValue()); Iterator<String> it = valueSet.iterator(); String fieldName = entry.getKey(); BinaryComparator comparator = new BinaryComparator(EntityQualifierUtils.toBytes(ed, fieldName, value)); SingleColumnValueFilter filter = new SingleColumnValueFilter(ed.getColumnFamily()
@Test public void testLongEntityQualifierHelper() { byte[] value = EntityQualifierUtils.toBytes(ed, "field4", "100000"); Assert.assertTrue(Bytes.compareTo(value, Bytes.toBytes(100000l - 1l)) > 0); Assert.assertTrue(Bytes.compareTo(value, Bytes.toBytes(100000l)) == 0); Assert.assertTrue(Bytes.compareTo(value, Bytes.toBytes(100000l + 1l)) < 0); }
comparable = _comparator; } else{ Class type = EntityQualifierUtils.getType(_ed, entry.getKey()); comparable = new BinaryComparator(EntityQualifierUtils.toBytes(_ed, entry.getKey(), entry.getValue())); }else { comparable = new TypedByteArrayComparator(EntityQualifierUtils.toBytes(_ed, entry.getKey(), entry.getValue()),type);
} else if (TokenConstant.isExpression(entry.getKey())) { if (doubleMap == null) { doubleMap = EntityQualifierUtils.bytesMapToDoubleMap(allQualifierValues, ed);
return new ColumnImpl(this.tableName, parseEntityAttribute(value)); } else if (!tokenType.equals(TokenType.ID) && op.equals(ComparisonOperator.IN)) { return EntityQualifierUtils.parseList(value); } else if (tokenType.equals(TokenType.NUMBER)) {
@Test public void testIntEntityQualifierHelper() { byte[] value = EntityQualifierUtils.toBytes(ed, "field1", "2"); Assert.assertTrue(Bytes.compareTo(value, Bytes.toBytes(1)) > 0); Assert.assertTrue(Bytes.compareTo(value, Bytes.toBytes(2)) == 0); Assert.assertTrue(Bytes.compareTo(value, Bytes.toBytes(3)) < 0); }
String expression = TokenConstant.parseExpressionContent(aggregatedField); try { Map<String,Double> doubleMap = EntityQualifierUtils.bytesMapToDoubleMap(values, entityDefinition); if(entityDefinition.getMetricDefinition() == null) { double value = ExpressionParser.eval(expression,doubleMap);
public static double eval(String expression,TaggedLogAPIEntity entity) throws Exception { ExpressionParser parser = parse(expression); List<String> dependencies = parser.getDependentFields(); Map<String,Double> context = new HashMap<String,Double>(); for(String field:dependencies){ String methodName = "get"+field.substring(0, 1).toUpperCase() + field.substring(1); String methodUID = entity.getClass().getName()+"."+methodName; Method m; synchronized (_entityMethodCache) { m = _entityMethodCache.get(methodUID); if (m == null) { m = entity.getClass().getMethod(methodName); _entityMethodCache.put(methodUID, m); } } Object obj = m.invoke(entity); Double doubleValue = EntityQualifierUtils.convertObjToDouble(obj); // if(doubleValue == Double.NaN) throw new IllegalArgumentException("Field "+field+": "+obj+" in expression "+expression+" is not number"); context.put(field,doubleValue); } return parser.eval(context); } }
public static byte[] toBytes(EntityDefinition ed, String qualifierName, String qualifierValueInStr) { // Get field type from entity class // and skip for not-found fields query expression Object typedValue = null; EntitySerDeser serDeser = null; if (ed.isTag(qualifierName)) { typedValue = qualifierValueInStr; serDeser = EntityDefinitionManager.getSerDeser(String.class); } else { try { Field field = ed.getEntityClass().getDeclaredField(qualifierName); Class<?> fieldType = field.getType(); serDeser = EntityDefinitionManager.getSerDeser(fieldType); if (serDeser == null) { throw new IllegalArgumentException("Can't find EntitySerDeser for field: " + qualifierName + "'s type: " + fieldType + ", so the field is not supported to be filtered yet"); } typedValue = convertStringToObject(qualifierValueInStr, fieldType); } catch (NoSuchFieldException ex) { // Handle the field not found exception in caller LOG.error("Field " + qualifierName + " not found in " + ed.getEntityClass()); throw new IllegalArgumentException("Field " + qualifierName + " not found in " + ed.getEntityClass(), ex); } } return serDeser.serialize(typedValue); }
tagFilters.get(fieldName).addAll(EntityQualifierUtils.parseList(value)); } else if (ComparisonOperator.LIKE.equals(op) || ComparisonOperator.NOT_LIKE.equals(op)
@Test public void testDoubleEntityQualifierHelper() { byte[] value = EntityQualifierUtils.toBytes(ed, "field5", "1.0"); Assert.assertTrue(Bytes.compareTo(value, Bytes.toBytes(0.5)) > 0); Assert.assertTrue(Bytes.compareTo(value, Bytes.toBytes(1.0)) == 0); Assert.assertTrue(Bytes.compareTo(value, Bytes.toBytes(2.2)) < 0); // TODO There is problem with negative double // Assert.assertTrue(Bytes.compareTo(Bytes.toBytes(-0.6),Bytes.toBytes(-0.5)) < 0); }