use of org.apache.avro.util.Utf8 in project gora by apache.
the class DataStoreTestUtil method createEmployee.
public static <K> Employee createEmployee() throws Exception {
Employee employee = Employee.newBuilder().build();
employee.setName(new Utf8("Random Joe"));
employee.setDateOfBirth(System.currentTimeMillis() - 20L * YEAR_IN_MS);
employee.setSalary(100000);
employee.setSsn(new Utf8("101010101010"));
return employee;
}
use of org.apache.avro.util.Utf8 in project gora by apache.
the class DataStoreTestUtil method testPutBytes.
public static byte[] testPutBytes(DataStore<String, WebPage> store) throws Exception {
store.createSchema();
WebPage page = WebPage.newBuilder().build();
page.setUrl(new Utf8("http://example.com"));
byte[] contentBytes = "example content in example.com".getBytes(Charset.defaultCharset());
ByteBuffer buff = ByteBuffer.wrap(contentBytes);
page.setContent(buff);
store.put("com.example/http", page);
store.close();
return contentBytes;
}
use of org.apache.avro.util.Utf8 in project gora by apache.
the class LogManager method parseLine.
/** Parses a single log line in combined log format using StringTokenizers */
private Pageview parseLine(String line) throws ParseException {
StringTokenizer matcher = new StringTokenizer(line);
//parse the log line
String ip = matcher.nextToken();
//discard
matcher.nextToken();
matcher.nextToken();
long timestamp = dateFormat.parse(matcher.nextToken("]").substring(2)).getTime();
matcher.nextToken("\"");
String request = matcher.nextToken("\"");
String[] requestParts = request.split(" ");
String httpMethod = requestParts[0];
String url = requestParts[1];
matcher.nextToken(" ");
int httpStatusCode = Integer.parseInt(matcher.nextToken());
int responseSize = Integer.parseInt(matcher.nextToken());
matcher.nextToken("\"");
String referrer = matcher.nextToken("\"");
matcher.nextToken("\"");
String userAgent = matcher.nextToken("\"");
//construct and return pageview object
Pageview pageview = new Pageview();
pageview.setIp(new Utf8(ip));
pageview.setTimestamp(timestamp);
pageview.setHttpMethod(new Utf8(httpMethod));
pageview.setUrl(new Utf8(url));
pageview.setHttpStatusCode(httpStatusCode);
pageview.setResponseSize(responseSize);
pageview.setReferrer(new Utf8(referrer));
pageview.setUserAgent(new Utf8(userAgent));
return pageview;
}
use of org.apache.avro.util.Utf8 in project gora by apache.
the class SolrStore method getUnionSchema.
/**
* Given an object and the object schema this function obtains, from within
* the UNION schema, the position of the type used. If no data type can be
* inferred then we return a default value of position 0.
*
* @param pValue
* @param pUnionSchema
* @return the unionSchemaPosition.
*/
private int getUnionSchema(Object pValue, Schema pUnionSchema) {
int unionSchemaPos = 0;
for (Schema currentSchema : pUnionSchema.getTypes()) {
Type schemaType = currentSchema.getType();
if (pValue instanceof Utf8 && schemaType.equals(Type.STRING))
return unionSchemaPos;
else if (pValue instanceof ByteBuffer && schemaType.equals(Type.BYTES))
return unionSchemaPos;
else if (pValue instanceof Integer && schemaType.equals(Type.INT))
return unionSchemaPos;
else if (pValue instanceof Long && schemaType.equals(Type.LONG))
return unionSchemaPos;
else if (pValue instanceof Double && schemaType.equals(Type.DOUBLE))
return unionSchemaPos;
else if (pValue instanceof Float && schemaType.equals(Type.FLOAT))
return unionSchemaPos;
else if (pValue instanceof Boolean && schemaType.equals(Type.BOOLEAN))
return unionSchemaPos;
else if (pValue instanceof Map && schemaType.equals(Type.MAP))
return unionSchemaPos;
else if (pValue instanceof List && schemaType.equals(Type.ARRAY))
return unionSchemaPos;
else if (pValue instanceof Persistent && schemaType.equals(Type.RECORD))
return unionSchemaPos;
unionSchemaPos++;
}
// default
return DEFAULT_UNION_SCHEMA;
}
use of org.apache.avro.util.Utf8 in project gora by apache.
the class DefaultFactoryTest method createHeadersFilter.
private MapFieldValueFilter<String, WebPage> createHeadersFilter() {
MapFieldValueFilter<String, WebPage> filter = new MapFieldValueFilter<>();
filter.setFieldName(WebPage.Field.HEADERS.toString());
filter.setMapKey(new Utf8("C.T"));
filter.getOperands().add("text/html");
return filter;
}
Aggregations