Search in sources :

Example 6 with ClassAdObjectPool

use of org.apache.asterix.external.classad.object.pool.ClassAdObjectPool in project asterixdb by apache.

the class ClassAdToADMTest method testSchemaless.

/**
     *
     */
public void testSchemaless() {
    try {
        ClassAdObjectPool objectPool = new ClassAdObjectPool();
        ClassAd pAd = new ClassAd(objectPool);
        String[] files = new String[] { "/classad/jobads.txt" };
        ClassAdParser parser = new ClassAdParser(objectPool);
        CharArrayLexerSource lexerSource = new CharArrayLexerSource();
        for (String path : files) {
            List<Path> paths = new ArrayList<>();
            Map<String, String> config = new HashMap<>();
            config.put(ExternalDataConstants.KEY_RECORD_START, "[");
            config.put(ExternalDataConstants.KEY_RECORD_END, "]");
            paths.add(Paths.get(getClass().getResource(path).toURI()));
            FileSystemWatcher watcher = new FileSystemWatcher(paths, null, false);
            LocalFSInputStream in = new LocalFSInputStream(watcher);
            SemiStructuredRecordReader recordReader = new SemiStructuredRecordReader();
            recordReader.configure(in, config);
            try {
                Value val = new Value(objectPool);
                while (recordReader.hasNext()) {
                    val.reset();
                    IRawRecord<char[]> record = recordReader.next();
                    lexerSource.setNewSource(record.get());
                    parser.setLexerSource(lexerSource);
                    parser.parseNext(pAd);
                    Map<CaseInsensitiveString, ExprTree> attrs = pAd.getAttrList();
                    for (Entry<CaseInsensitiveString, ExprTree> entry : attrs.entrySet()) {
                        ExprTree tree = entry.getValue();
                        switch(tree.getKind()) {
                            case ATTRREF_NODE:
                            case CLASSAD_NODE:
                            case EXPR_ENVELOPE:
                            case EXPR_LIST_NODE:
                            case FN_CALL_NODE:
                            case OP_NODE:
                                break;
                            case LITERAL_NODE:
                                break;
                            default:
                                System.out.println("Something is wrong");
                                break;
                        }
                    }
                }
            } finally {
                recordReader.close();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        assertTrue(false);
    }
}
Also used : Path(java.nio.file.Path) ClassAdObjectPool(org.apache.asterix.external.classad.object.pool.ClassAdObjectPool) ClassAd(org.apache.asterix.external.classad.ClassAd) HashMap(java.util.HashMap) CharArrayLexerSource(org.apache.asterix.external.classad.CharArrayLexerSource) ArrayList(java.util.ArrayList) CaseInsensitiveString(org.apache.asterix.external.classad.CaseInsensitiveString) CaseInsensitiveString(org.apache.asterix.external.classad.CaseInsensitiveString) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ClassAdParser(org.apache.asterix.external.library.ClassAdParser) FileSystemWatcher(org.apache.asterix.external.util.FileSystemWatcher) SemiStructuredRecordReader(org.apache.asterix.external.input.record.reader.stream.SemiStructuredRecordReader) Value(org.apache.asterix.external.classad.Value) ExprTree(org.apache.asterix.external.classad.ExprTree) LocalFSInputStream(org.apache.asterix.external.input.stream.LocalFSInputStream)

Example 7 with ClassAdObjectPool

use of org.apache.asterix.external.classad.object.pool.ClassAdObjectPool in project asterixdb by apache.

the class ClassAdUnitTest method test.

/**
     * Rigourous Test :-)
     */
public void test() {
    String[] args = { "", "-d", "-all" };
    try {
        ClassAdUnitTester.test(args.length, args, new ClassAdObjectPool());
    } catch (Throwable e) {
        e.printStackTrace();
        assertTrue(false);
    }
    assertTrue(true);
}
Also used : ClassAdObjectPool(org.apache.asterix.external.classad.object.pool.ClassAdObjectPool)

Example 8 with ClassAdObjectPool

use of org.apache.asterix.external.classad.object.pool.ClassAdObjectPool in project asterixdb by apache.

the class Value method toString.

@Override
public String toString() {
    ClassAdUnParser unparser = new PrettyPrint(new ClassAdObjectPool());
    AMutableCharArrayString unparsed_text = new AMutableCharArrayString();
    switch(valueType) {
        case ABSOLUTE_TIME_VALUE:
        case CLASSAD_VALUE:
        case RELATIVE_TIME_VALUE:
        case SLIST_VALUE:
        case LIST_VALUE:
            try {
                unparser.unparse(unparsed_text, this);
            } catch (HyracksDataException e) {
                e.printStackTrace();
            }
            return unparsed_text.toString();
        case BOOLEAN_VALUE:
            if (boolVal) {
                return "true";
            } else {
                return "false";
            }
        case ERROR_VALUE:
            return "error";
        case INTEGER_VALUE:
            return String.valueOf(longVal);
        case NULL_VALUE:
            return "(null)";
        case REAL_VALUE:
            return String.valueOf(doubleVal);
        case STRING_VALUE:
            return stringVal;
        case UNDEFINED_VALUE:
            return "undefined";
        default:
            break;
    }
    return null;
}
Also used : ClassAdObjectPool(org.apache.asterix.external.classad.object.pool.ClassAdObjectPool) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

ClassAdObjectPool (org.apache.asterix.external.classad.object.pool.ClassAdObjectPool)8 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)4 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 CaseInsensitiveString (org.apache.asterix.external.classad.CaseInsensitiveString)3 ClassAd (org.apache.asterix.external.classad.ClassAd)3 SemiStructuredRecordReader (org.apache.asterix.external.input.record.reader.stream.SemiStructuredRecordReader)3 LocalFSInputStream (org.apache.asterix.external.input.stream.LocalFSInputStream)3 ClassAdParser (org.apache.asterix.external.library.ClassAdParser)3 FileSystemWatcher (org.apache.asterix.external.util.FileSystemWatcher)3 CharArrayLexerSource (org.apache.asterix.external.classad.CharArrayLexerSource)2 Value (org.apache.asterix.external.classad.Value)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 PrintStream (java.io.PrintStream)1 ExprTree (org.apache.asterix.external.classad.ExprTree)1 ARecordType (org.apache.asterix.om.types.ARecordType)1 IAType (org.apache.asterix.om.types.IAType)1 IPrinter (org.apache.hyracks.algebricks.data.IPrinter)1