/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.asterix.app.scheduler;
import org.apache.asterix.app.dataflow.data.nontagged.serde.ADTFDeserializer;
import org.apache.asterix.common.api.INcApplication;
import org.apache.asterix.common.utils.Const;
import org.apache.asterix.dataflow.data.nontagged.serde.DataFieldSerializer;
import org.apache.asterix.dataflow.data.nontagged.serde.DataSerializableFactory;
import org.apache.asterix.dataflow.data.nontagged.serde.Deserializer;
import org.apache.asterix.dataflow.data.nontagged.serde.FieldSerializer;
import org.apache.asterix.om.types.ARecordType;
import org.apache.asterix.om.types.IAType;
import org.apache.asterix.om.types.hierachy.ATypeTag;
import org.apache.asterix.om.types.hierachy.ATypeTagged;
import org.apache.hyracks.api.exceptions.HyracksDataException;
import org.apache.hyracks.data.std.primitive.VIntSerializer;
import org.apache.hyracks.dataflow.common.data.accessors.ILangExpressionObjectConverter;
import org.apache.hyracks.dataflow.util.Pair;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.esotericsoftware.kryo.serializers.CollectionSerializer;
import com.esotericsoftware.kryo.serializers.FieldSerializerFactory;
public class Application extends INcApplication {
private FieldSerializer
_vIntSer;
private FieldSerializer _vStringSer;
private FieldSerializer _vLongTypeSer;
private FieldSerializer _vTypeTagSer;
private FieldSerializer _vStringSerAndTypeTagSer;
private FieldSerializer _vStringSerAndIntegerSer;
public Application(IAType type) {
super(type);
_vIntSer = new VIntSerializer();
_vStringSer = new VIntSerializer();
_vLongTypeSer = new VIntSerializer();
_vTypeTagSer = new VIntSerializer();
_vStringSerAndTypeTagSer = new VIntSerializer();
}
@Override
public byte codeLength() {
return -1;
}
@Override
public void write(Output output, Object value) throws HyracksDataException {
output.writeInt(value.hashCode());
}
@Override
public void read(Input input, byte[] buffer) throws HyracksDataException {
value = buffer[0] & 0xFFFFFFFFL;
}
public static Deserializer createApplicationDeserializer() throws HyracksDataException {
return Deserializer.create(Application.class, new DataSerializableFactory() {
@Override
public Application deserialize(int index, byte[] buffer, int start, int length) throws HyracksDataException {
return new Application(DataFieldSerializer.readFields(buffer, start, length));
}
}, new FieldSerializerFactory() {
@Override
public FieldSerializer create(INcApplication context) {
return new Application(context.getType());
}
});
}
public static Deserializer createAppTypeTagDeserializer() throws HyracksDataException {
return Deserializer.create(Application.class, new DataSerializableFactory() {
@Override
public Application deserialize(int index, byte[] buffer, int start, int length) throws HyracksDataException {
return new Application(DataFieldSerializer.readFields(buffer, start, length));
}
}, new FieldSerializerFactory() {
@Override
public FieldSerializer create(INcApplication context) {
return new Application(context.getType(), DataFieldSerializer.readFields(buffer, start, length));
}
});
}
public static Deserializer createApplicationDeserializer(int keySize) throws HyracksDataException {
return Deserializer.create(Application.class, new DataSerializableFactory() {
@Override
public Application deserialize(int index, byte[] buffer, int start, int length) throws HyracksDataException {
return new Application(DataFieldSerializer.readFields(buffer, start, length, keySize));
}
}, new FieldSerializerFactory() {
@Override
public FieldSerializer create(INcApplication context) {
return new Application(context.getType(), DataFieldSerializer.readFields(buffer, start, length, keySize));
}
});
}
@Override
public boolean deserialize(byte[] buffer, int start, int length, int keySize) throws HyracksDataException {
return super.deserialize(buffer, start, length, keySize);
}
public static Deserializer createAppAndVIntSerializer() throws HyracksDataException {
return Deserializer.create(Application.class, new DataSerializableFactory() {
@Override
public Application deserialize(int index, byte[] buffer, int start, int length) throws HyracksDataException {
return new Application(DataFieldSerializer.readFields(buffer, start, length), DataFieldSerializer.readFields(buffer, start, length));
}
}, new FieldSerializerFactory() {
@Override
public FieldSerializer create(INcApplication context) {
return new Application(context.getType(), DataFieldSerializer.readFields(buffer, start, length));
}
});
}
public static Deserializer createAppAndVIntSerializer(int keySize) throws HyracksDataException {
return Deserializer.create(Application.class, new DataSerializableFactory() {
@Override
public Application deserialize(int index, byte[] buffer, int start, int length) throws HyracksDataException {
return new Application(DataFieldSerializer.readFields(buffer, start, length, keySize), DataFieldSerializer.readFields(buffer, start, length));
}
}, new FieldSerializerFactory() {
@Override
public FieldSerializer create(INcApplication context) {
return new Application(context.getType(), DataFieldSerializer.readFields(buffer, start, length, keySize));
}
});
}
public static Deserializer createAppAndVStringSerializer() throws HyracksDataException {
return Deserializer.create(Application.class, new DataSerializableFactory() {
@Override
public Application deserialize(int index, byte[] buffer, int start, int length) throws HyracksDataException {
return new Application(DataFieldSerializer.readFields(buffer, start, length), DataFieldSerializer.readFields(buffer, start, length));
}
}, new FieldSerializerFactory() {
@Override
public FieldSerializer create(INcApplication context) {
return new Application(context.getType(), DataFieldSerializer.readFields(buffer, start, length));
}
});
}
public static Deserializer createAppAndVStringSerializer(int