Search in sources :

Example 1 with Iced

use of water.Iced in project h2o-3 by h2oai.

the class AstRename method apply.

@Override
public ValNum apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
    Key oldKey = Key.make(env.expand(asts[1].exec(env).getStr()));
    Key newKey = Key.make(env.expand(asts[2].exec(env).getStr()));
    Iced o = DKV.remove(oldKey).get();
    if (o instanceof Frame)
        DKV.put(newKey, new Frame(newKey, ((Frame) o)._names, ((Frame) o).vecs()));
    else if (o instanceof Model) {
        ((Model) o)._key = newKey;
        DKV.put(newKey, o);
    } else
        throw new IllegalArgumentException("Trying to rename Value of type " + o.getClass());
    return new ValNum(Double.NaN);
}
Also used : Frame(water.fvec.Frame) Model(hex.Model) Iced(water.Iced) ValNum(water.rapids.vals.ValNum) Key(water.Key)

Example 2 with Iced

use of water.Iced in project h2o-3 by h2oai.

the class MetadataHandler method listSchemas.

/** Fetch the metadata for all the Schemas. */
// called through reflection by RequestServer
@SuppressWarnings("unused")
public MetadataV3 listSchemas(int version, MetadataV3 docs) {
    Map<String, Class<? extends Schema>> ss = SchemaServer.schemas();
    docs.schemas = new SchemaMetadataV3[ss.size()];
    // NOTE: this will throw an exception if the classname isn't found:
    int i = 0;
    for (Class<? extends Schema> schema_class : ss.values()) {
        // No hardwired version! YAY!  FINALLY!
        Schema schema = Schema.newInstance(schema_class);
        // get defaults
        try {
            Iced impl = (Iced) schema.getImplClass().newInstance();
            schema.fillFromImpl(impl);
        } catch (Exception e) {
        // ignore if create fails; this can happen for abstract classes
        }
        docs.schemas[i++] = new SchemaMetadataV3(new SchemaMetadata(schema));
    }
    return docs;
}
Also used : SchemaMetadataV3(water.api.schemas3.SchemaMetadataV3) Iced(water.Iced) MalformedURLException(java.net.MalformedURLException)

Example 3 with Iced

use of water.Iced in project h2o-3 by h2oai.

the class MetadataHandler method fetchSchemaMetadata.

/** Fetch the metadata for a Schema by its simple Schema name (e.g., "DeepLearningParametersV2"). */
// called through reflection by RequestServer
@SuppressWarnings("unused")
public MetadataV3 fetchSchemaMetadata(int version, MetadataV3 docs) {
    if ("void".equals(docs.schemaname)) {
        docs.schemas = new SchemaMetadataV3[0];
        return docs;
    }
    docs.schemas = new SchemaMetadataV3[1];
    // NOTE: this will throw an exception if the classname isn't found:
    Schema schema = Schema.newInstance(docs.schemaname);
    // get defaults
    try {
        Iced impl = (Iced) schema.getImplClass().newInstance();
        schema.fillFromImpl(impl);
    } catch (Exception e) {
    // ignore if create fails; this can happen for abstract classes
    }
    SchemaMetadataV3 meta = new SchemaMetadataV3(new SchemaMetadata(schema));
    docs.schemas[0] = meta;
    return docs;
}
Also used : SchemaMetadataV3(water.api.schemas3.SchemaMetadataV3) Iced(water.Iced) MalformedURLException(java.net.MalformedURLException)

Example 4 with Iced

use of water.Iced in project h2o-3 by h2oai.

the class IcedHashMapGeneric method write_impl.

// This comment is stolen from water.parser.Categorical:
//
// Since this is a *concurrent* hashtable, writing it whilst its being
// updated is tricky.  If the table is NOT being updated, then all is written
// as expected.  If the table IS being updated we only promise to write the
// Keys that existed at the time the table write began.  If elements are
// being deleted, they may be written anyways.  If the Values are changing, a
// random Value is written.
public final AutoBuffer write_impl(AutoBuffer ab) {
    _write_lock = true;
    try {
        for (Entry<K, V> e : map().entrySet()) {
            K key = e.getKey();
            assert key != null;
            V val = e.getValue();
            assert val != null;
            int mode = 0;
            if (key instanceof String) {
                if (val instanceof String) {
                    mode = 1;
                } else if (val instanceof Freezable) {
                    mode = 3;
                } else if (val instanceof Freezable[]) {
                    mode = 5;
                } else if (val instanceof Integer) {
                    mode = 7;
                } else {
                    throw new IllegalArgumentException("unsupported value class " + val.getClass().getName());
                }
            } else {
                if (!(key instanceof Iced))
                    throw new IllegalArgumentException("key must be String or Freezable, got " + key.getClass().getName());
                if (val instanceof String) {
                    mode = 2;
                } else if (val instanceof Freezable) {
                    mode = 4;
                } else if (val instanceof Freezable[]) {
                    mode = 6;
                } else if (val instanceof Integer) {
                    mode = 8;
                } else {
                    throw new IllegalArgumentException("unsupported value class " + val.getClass().getName());
                }
            }
            // Type of hashmap being serialized
            ab.put1(mode);
            // put key
            if (isStringKey(mode))
                ab.putStr((String) key);
            else
                ab.put((Freezable) key);
            // put value
            if (isStringVal(mode))
                ab.putStr((String) val);
            else if (isFreezeVal(mode))
                ab.put((Freezable) val);
            else if (isFArrayVal(mode)) {
                ab.put4(((Freezable[]) val).length);
                for (Freezable v : (Freezable[]) val) ab.put(v);
            } else if (isIntegrVal(mode))
                ab.put4((Integer) val);
            else
                throw H2O.fail();
        }
        ab.put1(-1);
    } catch (Throwable t) {
        System.err.println("Iced hash map serialization failed! " + t.toString() + ", msg = " + t.getMessage());
        t.printStackTrace();
        throw H2O.fail("Iced hash map serialization failed!" + t.toString() + ", msg = " + t.getMessage());
    } finally {
        _write_lock = false;
    }
    return ab;
}
Also used : Freezable(water.Freezable) Iced(water.Iced)

Example 5 with Iced

use of water.Iced in project h2o-3 by h2oai.

the class AvroParserProvider method createParserSetup.

@Override
public ParseSetup createParserSetup(Key[] inputs, ParseSetup requiredSetup) {
    // Also expect that files are not compressed
    assert inputs != null && inputs.length > 0 : "Inputs cannot be empty!";
    Key firstInput = inputs[0];
    Iced ice = DKV.getGet(firstInput);
    if (ice == null)
        throw new H2OIllegalArgumentException("Missing data", "Did not find any data under key " + firstInput);
    ByteVec bv = (ByteVec) (ice instanceof ByteVec ? ice : ((Frame) ice).vecs()[0]);
    byte[] bits = bv.getFirstBytes();
    try {
        AvroParser.AvroInfo avroInfo = AvroParser.extractAvroInfo(bits, requiredSetup);
        return new AvroParser.AvroParseSetup(requiredSetup, avroInfo.header, avroInfo.firstBlockSize, avroInfo.domains);
    } catch (Throwable e) {
        throw new H2OIllegalArgumentException("Wrong data", "Cannot find Avro header in input file: " + firstInput, e);
    }
}
Also used : Frame(water.fvec.Frame) H2OIllegalArgumentException(water.exceptions.H2OIllegalArgumentException) Iced(water.Iced) ByteVec(water.fvec.ByteVec) Key(water.Key)

Aggregations

Iced (water.Iced)6 Frame (water.fvec.Frame)3 MalformedURLException (java.net.MalformedURLException)2 Key (water.Key)2 SchemaMetadataV3 (water.api.schemas3.SchemaMetadataV3)2 H2OIllegalArgumentException (water.exceptions.H2OIllegalArgumentException)2 ByteVec (water.fvec.ByteVec)2 Model (hex.Model)1 Freezable (water.Freezable)1 ValNum (water.rapids.vals.ValNum)1