Search in sources :

Example 46 with Utf8

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;
}
Also used : Employee(org.apache.gora.examples.generated.Employee) Utf8(org.apache.avro.util.Utf8)

Example 47 with Utf8

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;
}
Also used : WebPage(org.apache.gora.examples.generated.WebPage) Utf8(org.apache.avro.util.Utf8) ByteBuffer(java.nio.ByteBuffer)

Example 48 with Utf8

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;
}
Also used : Pageview(org.apache.gora.tutorial.log.generated.Pageview) StringTokenizer(java.util.StringTokenizer) Utf8(org.apache.avro.util.Utf8)

Example 49 with Utf8

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;
}
Also used : Schema(org.apache.avro.Schema) Persistent(org.apache.gora.persistency.Persistent) ByteBuffer(java.nio.ByteBuffer) Type(org.apache.avro.Schema.Type) Utf8(org.apache.avro.util.Utf8) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 50 with Utf8

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;
}
Also used : WebPage(org.apache.gora.examples.generated.WebPage) Utf8(org.apache.avro.util.Utf8) MapFieldValueFilter(org.apache.gora.filter.MapFieldValueFilter)

Aggregations

Utf8 (org.apache.avro.util.Utf8)123 Test (org.junit.Test)34 WebPage (org.apache.gora.examples.generated.WebPage)32 GenericRecord (org.apache.avro.generic.GenericRecord)17 Schema (org.apache.avro.Schema)14 GenericData (org.apache.avro.generic.GenericData)13 ByteBuffer (java.nio.ByteBuffer)12 HashMap (java.util.HashMap)12 Map (java.util.Map)12 Employee (org.apache.gora.examples.generated.Employee)11 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 Field (org.apache.avro.Schema.Field)6 Record (org.apache.avro.generic.GenericData.Record)5 File (java.io.File)4 SpecificDatumReader (org.apache.avro.specific.SpecificDatumReader)4 Metadata (org.apache.gora.examples.generated.Metadata)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Iterator (java.util.Iterator)3 List (java.util.List)3