use of org.apache.asterix.om.base.AMutableString in project asterixdb by apache.
the class DatasetUtil method writePropertyTypeRecord.
@SuppressWarnings("unchecked")
public static void writePropertyTypeRecord(String name, String value, DataOutput out, ARecordType recordType) throws HyracksDataException {
IARecordBuilder propertyRecordBuilder = new RecordBuilder();
ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
propertyRecordBuilder.reset(recordType);
AMutableString aString = new AMutableString("");
ISerializerDeserializer<AString> stringSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING);
// write field 0
fieldValue.reset();
aString.setValue(name);
stringSerde.serialize(aString, fieldValue.getDataOutput());
propertyRecordBuilder.addField(0, fieldValue);
// write field 1
fieldValue.reset();
aString.setValue(value);
stringSerde.serialize(aString, fieldValue.getDataOutput());
propertyRecordBuilder.addField(1, fieldValue);
propertyRecordBuilder.write(out, true);
}
use of org.apache.asterix.om.base.AMutableString in project asterixdb by apache.
the class RecordFieldsUtil method addFieldType.
public void addFieldType(byte tagId, IARecordBuilder fieldRecordBuilder) throws HyracksDataException, AsterixException {
ArrayBackedValueStorage fieldAbvs = getTempBuffer();
ArrayBackedValueStorage valueAbvs = getTempBuffer();
// Name
fieldAbvs.reset();
stringSerde.serialize(typeName, fieldAbvs.getDataOutput());
// Value
valueAbvs.reset();
ATypeTag tag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(tagId);
AMutableString aString = new AMutableString("");
aString.setValue(tag.toString());
stringSerde.serialize(aString, valueAbvs.getDataOutput());
fieldRecordBuilder.addField(fieldAbvs, valueAbvs);
}
use of org.apache.asterix.om.base.AMutableString in project asterixdb by apache.
the class FunctionalTester method replace_variables.
/*********************************************************************
* Function: replace_variables
* Purpose:
*
* @throws HyracksDataException
*********************************************************************/
public static boolean replace_variables(AMutableString mutableLine, State state, Parameters parameters, ClassAdObjectPool objectPool) throws HyracksDataException {
boolean good_line;
String error;
good_line = true;
error = "";
Variable var = new Variable(objectPool);
for (; ; ) {
int dollar;
int current_position;
String variable_name;
AMutableCharArrayString variable_value = new AMutableCharArrayString();
current_position = 0;
dollar = mutableLine.getStringValue().indexOf('$', current_position);
if (dollar < 0) {
break;
}
current_position = dollar + 1;
if (!Character.isAlphabetic(mutableLine.getStringValue().charAt(current_position))) {
good_line = false;
error = "Bad variable name.";
break;
}
current_position++;
while (Character.isLetterOrDigit((mutableLine.getStringValue().charAt(current_position))) || mutableLine.getStringValue().charAt(current_position) == '_') {
current_position++;
}
variable_name = mutableLine.getStringValue().substring(dollar + 1, current_position);
var = variables.get(variable_name);
if (var == null) {
good_line = false;
error = "Unknown variable '$";
error += variable_name;
error += "'";
break;
}
var.getStringRepresentation(variable_value, objectPool);
// We have to be careful with substr() because with gcc 2.96, it likes to
// assert/except if you give it values that are too large.
String end;
if (current_position < mutableLine.getStringValue().length()) {
end = mutableLine.getStringValue().substring(current_position);
} else {
end = "";
}
mutableLine.setValue(mutableLine.getStringValue().substring(0, dollar) + variable_value.toString() + end);
}
if (parameters.debug) {
System.err.println("# after replacement: " + mutableLine.getStringValue());
}
if (!good_line) {
print_error_message(error, state);
}
return good_line;
}
use of org.apache.asterix.om.base.AMutableString in project asterixdb by apache.
the class FunctionalTester method handle_set.
/*********************************************************************
* Function: handle_set
* Purpose:
* @param objectPool
*********************************************************************/
public static void handle_set(AMutableString line, State state, Parameters parameters, ClassAdObjectPool objectPool) {
AMutableString option_name = new AMutableString(null);
AMutableString option_value = new AMutableString(null);
if (get_variable_name(line, false, option_name, state, parameters)) {
if (get_variable_name(line, false, option_value, state, parameters)) {
if (option_name.getStringValue().equalsIgnoreCase("format")) {
if (option_value.getStringValue().equalsIgnoreCase("compact")) {
state.format = PrintFormat.print_Compact;
} else if (option_value.getStringValue().equalsIgnoreCase("pretty")) {
state.format = PrintFormat.print_Pretty;
} else if (option_value.getStringValue().equalsIgnoreCase("xml")) {
state.format = PrintFormat.print_XML;
} else if (option_value.getStringValue().equalsIgnoreCase("xmlpretty")) {
state.format = PrintFormat.print_XMLPretty;
} else {
print_error_message("Unknown print format. Use compact, pretty, xml, or xmlpretty", state);
}
} else {
print_error_message("Unknown option. The only option currently available is format", state);
}
}
}
return;
}
use of org.apache.asterix.om.base.AMutableString in project asterixdb by apache.
the class FunctionalTester method get_command.
/*********************************************************************
* Function: get_command
* Purpose:
*********************************************************************/
public static Command get_command(AMutableString line, Parameters parameters) {
int current_position;
int length;
String command_name;
Command command;
current_position = 0;
length = line.getStringValue().length();
command_name = "";
command = Command.cmd_NoCommand;
// Skip whitespace
while (current_position < length && Character.isWhitespace(line.getStringValue().charAt(current_position))) {
current_position++;
}
// Find command name
while (current_position < length && Character.isAlphabetic(line.getStringValue().charAt(current_position))) {
command_name += line.getStringValue().charAt(current_position);
current_position++;
}
// Figure out what the command is.
if (command_name.length() == 0) {
command = Command.cmd_NoCommand;
} else if (command_name.equalsIgnoreCase("let")) {
command = Command.cmd_Let;
} else if (command_name.equalsIgnoreCase("eval")) {
command = Command.cmd_Eval;
} else if (command_name.equalsIgnoreCase("print")) {
command = Command.cmd_Print;
} else if (command_name.equalsIgnoreCase("same")) {
command = Command.cmd_Same;
} else if (command_name.equalsIgnoreCase("sameq")) {
command = Command.cmd_Sameq;
} else if (command_name.equalsIgnoreCase("diff")) {
command = Command.cmd_Diff;
} else if (command_name.equalsIgnoreCase("diffq")) {
command = Command.cmd_Diffq;
} else if (command_name.equalsIgnoreCase("set")) {
command = Command.cmd_Set;
} else if (command_name.equalsIgnoreCase("show")) {
command = Command.cmd_Show;
} else if (command_name.equalsIgnoreCase("writexml")) {
command = Command.cmd_Writexml;
} else if (command_name.equalsIgnoreCase("readxml")) {
command = Command.cmd_Readxml;
} else if (command_name.equalsIgnoreCase("echo")) {
command = Command.cmd_Echo;
} else if (command_name.equalsIgnoreCase("help")) {
command = Command.cmd_Help;
} else if (command_name.equalsIgnoreCase("quit")) {
command = Command.cmd_Quit;
} else {
command = Command.cmd_InvalidCommand;
}
shorten_line(line, current_position);
return command;
}
Aggregations