>From Janhavi Tripurwar <[email protected]>: Janhavi Tripurwar has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/19830 )
Change subject: WIP: LPAD Function ...................................................................... WIP: LPAD Function Change-Id: I852598eeb891e1df7e87e12c5122f2114ccce32c --- D asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLpadEvaluator.java A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/pad/lpad/lpad.00.ddl.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/pad/lpad/lpad.02.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/pad/lpad/lpad.01.query.sqlpp M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLpadDescriptor.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringPadEvaluator.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLpadEval.java 7 files changed, 324 insertions(+), 200 deletions(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/30/19830/1 diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/pad/lpad/lpad.00.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/pad/lpad/lpad.00.ddl.sqlpp new file mode 100644 index 0000000..8e862b6 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/pad/lpad/lpad.00.ddl.sqlpp @@ -0,0 +1,22 @@ +/* + * 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. + */ + +drop dataset padding_example if exists; +create dataset padding_example primary key (id:int); +insert into padding_example ({"id": 1, "str": "Hi"}, {"id":2, "str": "-7262.98"}, {"id":3, "str": " Hello ?"}, {"id":4, "str": "Dear god"}); \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/pad/lpad/lpad.01.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/pad/lpad/lpad.01.query.sqlpp new file mode 100644 index 0000000..62925bb --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/pad/lpad/lpad.01.query.sqlpp @@ -0,0 +1,27 @@ +/* + * 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. + */ + +/* +SELECT id, str AS v, + LPAD(v, 10, ' ') AS pad_with_blank, + LPAD(v, 10, '$') AS pad_with_dollar_sign, + LPAD(v, 10, '1$x') AS pad_with_three_chars + FROM padding_example + ORDER BY v; + */ \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/pad/lpad/lpad.02.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/pad/lpad/lpad.02.query.sqlpp new file mode 100644 index 0000000..e3b4ca0 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/pad/lpad/lpad.02.query.sqlpp @@ -0,0 +1,24 @@ +/* + * 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. + */ + +/* +select lpad('847.765', 7, '*_'); ->same +select lpad('847.765', 10, '*_'); ->pad +select lpad('847.765', 5, '*_'); -> truncate +*/ \ No newline at end of file diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLpadDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLpadDescriptor.java index 750fe30..08e7c9c 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLpadDescriptor.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLpadDescriptor.java @@ -45,12 +45,7 @@ @Override public IScalarEvaluator createScalarEvaluator(IEvaluatorContext ctx) throws HyracksDataException { - return new StringLpadEvaluator(ctx, args[0], args[1], args[2], StringLpadDescriptor.this.getIdentifier(), sourceLoc) { - -// @Override -// protected void process() throws HyracksDataException { -// -// } + return new StringLpadEval(ctx, args[0], args[1], args[2], StringLpadDescriptor.this.getIdentifier(), sourceLoc) { }; } }; diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLpadEval.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLpadEval.java new file mode 100644 index 0000000..45a2912 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLpadEval.java @@ -0,0 +1,110 @@ +/* + * 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.runtime.evaluators.functions; + +import org.apache.asterix.om.types.ATypeTag; +import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory; +import org.apache.hyracks.api.context.IEvaluatorContext; +import org.apache.hyracks.api.exceptions.HyracksDataException; +import org.apache.hyracks.api.exceptions.SourceLocation; +import org.apache.hyracks.util.string.UTF8StringUtil; + +import java.io.IOException; + +public class StringLpadEval extends StringPadEvaluator{ + public StringLpadEval(IEvaluatorContext context, IScalarEvaluatorFactory eval0, IScalarEvaluatorFactory eval1, IScalarEvaluatorFactory eval2, FunctionIdentifier funcID, SourceLocation sourceLoc) throws HyracksDataException { + super(context, eval0, eval1, eval2, funcID, sourceLoc); + } + + @Override + public void process(byte[] bytes0, int start0, int targetLength, byte[] bytes2, int start2){ + + int originalLength = UTF8StringUtil.getUTFLength(bytes0, start0+1); + //no. of bytes used to encode the target length + int cbytes = UTF8StringUtil.encodeUTF8Length(targetLength, tempLengthArray, 0); + + try { + // Write type tag and encoded targetLength prefix first + out.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG); + out.write(tempLengthArray, 0, cbytes); // cbytes is derived from targetLength + if(targetLength == originalLength){ + //no change + int inputStringStart = start0 + 1 + UTF8StringUtil.getNumBytesToStoreLength(targetLength); + out.write(bytes0,inputStringStart, targetLength); + } else if(targetLength < originalLength) { + //truncate + // Start of actual character data in input + int currentBytePosInText = start0 + 1 + UTF8StringUtil.getNumBytesToStoreLength(originalLength); + int charsWritten = 0; + for (int i = 0; i < originalLength && charsWritten < targetLength; i++) { + int singleCharByteLength = UTF8StringUtil.charSize(bytes0, currentBytePosInText); + out.write(bytes0, currentBytePosInText, singleCharByteLength); + currentBytePosInText += singleCharByteLength; + charsWritten++; + } + } else { + // pad + int numCharsToPad = targetLength - originalLength; + + // padding string length field (type tag, length, ....) + int padCharCount = UTF8StringUtil.getUTFLength(bytes2, start2 + 1); + + // bytes used for padding string length + int padPrefixBytes = UTF8StringUtil.getNumBytesToStoreLength(bytes2, start2 + 1); + // padding string data start offset + int padDataOffset = start2 + 1 + padPrefixBytes; + + int padReadOff = padDataOffset; + int padCurrCycle = 0; + + // write the padding characters one by one + for (int i = 0; i < numCharsToPad; i++) { + // reset if pad string fully consumed + if (padCurrCycle == padCharCount) { + padReadOff = padDataOffset; + padCurrCycle = 0; + } + + // byte length of current char in padding string + int singlePadCharByteLen = UTF8StringUtil.charSize(bytes2, padReadOff); + + // write singlePadCharByteLen bytes from padReadOff + out.write(bytes2, padReadOff, singlePadCharByteLen); + + // move read pointer in pad string content + padReadOff += singlePadCharByteLen; + padCurrCycle++; + } + + // write the base string's content (bytes0) + // bytes used for base string length and the len is at string start start0 + 1 + int basePrefixBytes = UTF8StringUtil.getNumBytesToStoreLength(bytes0, start0 + 1); + // base string data start offset + int baseDataOff = start0 + 1 + basePrefixBytes; + + // write originalLength bytes from baseDataOff + out.write(bytes0, baseDataOff, originalLength); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLpadEvaluator.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLpadEvaluator.java deleted file mode 100644 index b64aca5..0000000 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLpadEvaluator.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * 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.runtime.evaluators.functions; - -import org.apache.asterix.om.base.AMutableInt32; -import org.apache.asterix.om.exceptions.ExceptionUtil; -import org.apache.asterix.om.types.ATypeTag; -import org.apache.asterix.runtime.evaluators.common.ArgumentUtils; -import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; -import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator; -import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory; -import org.apache.hyracks.api.context.IEvaluatorContext; -import org.apache.hyracks.api.exceptions.HyracksDataException; -import org.apache.hyracks.api.exceptions.SourceLocation; -import org.apache.hyracks.data.std.api.IPointable; -import org.apache.hyracks.data.std.primitive.VoidPointable; -import org.apache.hyracks.data.std.util.ArrayBackedValueStorage; -import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference; -import org.apache.hyracks.util.string.UTF8StringUtil; - -import java.io.DataOutput; -import java.io.IOException; - -public class StringLpadEvaluator implements IScalarEvaluator { - - private final IEvaluatorContext ctx; - - private final IScalarEvaluator eval0; - private final IScalarEvaluator eval1; - private final IScalarEvaluator eval2; - - // Argument pointers. - final IPointable argPtrFirst = new VoidPointable(); - final IPointable argPtrSecond = new VoidPointable(); - final IPointable argPtrThird = new VoidPointable(); - private final AMutableInt32 mutableInt = new AMutableInt32(0); - - // For outputting results. - private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage(); - private DataOutput out = resultStorage.getDataOutput(); - private byte[] tempLengthArray = new byte[5]; - - private final FunctionIdentifier funcID; - protected final SourceLocation sourceLoc; - - public StringLpadEvaluator(IEvaluatorContext context, IScalarEvaluatorFactory eval0, - IScalarEvaluatorFactory eval1, IScalarEvaluatorFactory eval2, FunctionIdentifier funcID, SourceLocation sourceLoc) - throws HyracksDataException { - this.eval0 = eval0.createScalarEvaluator(context); - this.eval1 = eval1.createScalarEvaluator(context); - this.eval2 = eval2.createScalarEvaluator(context); - this.funcID = funcID; - this.sourceLoc = sourceLoc; - this.ctx = context; - } - - @Override - public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException { - resultStorage.reset(); - // Gets the arguments - eval0.evaluate(tuple, argPtrFirst); - eval1.evaluate(tuple, argPtrSecond); - eval2.evaluate(tuple, argPtrThird); - - if (PointableHelper.checkAndSetMissingOrNull(result, argPtrFirst, argPtrSecond, argPtrThird)) { - return; - } - - //base string - byte[] bytes0 = argPtrFirst.getByteArray(); - int start0 = argPtrFirst.getStartOffset(); - - if (bytes0[start0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) { - PointableHelper.setNull(result); - ExceptionUtil.warnTypeMismatch(ctx, sourceLoc, funcID, bytes0[start0], 0, ATypeTag.STRING); - return; - } - - //target length - byte[] bytes1 = argPtrSecond.getByteArray(); - int start1 = argPtrSecond.getStartOffset(); - - if (bytes1[start1] != ATypeTag.SERIALIZED_INT64_TYPE_TAG) { - PointableHelper.setNull(result); - ExceptionUtil.warnTypeMismatch(ctx, sourceLoc, funcID, bytes1[start1], 1, ATypeTag.INTEGER); - return; - } - - // Gets the target length. - if (!ArgumentUtils.setInteger(ctx, sourceLoc, funcID, 1, bytes1, start1, mutableInt)) { - PointableHelper.setNull(result); - return; - } - int targetLength = mutableInt.getIntegerValue(); - - //padding string - byte[] bytes2 = argPtrThird.getByteArray(); - int start2 = argPtrThird.getStartOffset(); - - if (bytes2[start2] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) { - PointableHelper.setNull(result); - ExceptionUtil.warnTypeMismatch(ctx, sourceLoc, funcID, bytes2[start2], 2, ATypeTag.STRING); - return; - } - - int originalLength = UTF8StringUtil.getUTFLength(bytes0, start0+1); - //no. of bytes used to encode the target length - int cbytes = UTF8StringUtil.encodeUTF8Length(targetLength, tempLengthArray, 0); - - try { - // Write type tag and encoded targetLength prefix first - out.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG); - out.write(tempLengthArray, 0, cbytes); // cbytes is derived from targetLength - if(targetLength == originalLength){ - //no change - int inputStringStart = start0 + 1 + UTF8StringUtil.getNumBytesToStoreLength(targetLength); - out.write(bytes0,inputStringStart, targetLength); - } else if(targetLength < originalLength) { - //truncate - // Start of actual character data in input - int currentBytePosInText = start0 + 1 + UTF8StringUtil.getNumBytesToStoreLength(originalLength); - int charsWritten = 0; - for (int i = 0; i < originalLength && charsWritten < targetLength; i++) { - int singleCharByteLength = UTF8StringUtil.charSize(bytes0, currentBytePosInText); - out.write(bytes0, currentBytePosInText, singleCharByteLength); - currentBytePosInText += singleCharByteLength; - charsWritten++; - } - } else { - // pad - int numCharsToPad = targetLength - originalLength; - - // padding string length field (type tag, length, ....) - int padCharCount = UTF8StringUtil.getUTFLength(bytes2, start2 + 1); - - // bytes used for padding string length - int padPrefixBytes = UTF8StringUtil.getNumBytesToStoreLength(bytes2, start2 + 1); - // padding string data start offset - int padDataOffset = start2 + 1 + padPrefixBytes; - - int padReadOff = padDataOffset; - int padCurrCycle = 0; - - // write the padding characters one by one - for (int i = 0; i < numCharsToPad; i++) { - // reset if pad string fully consumed - if (padCurrCycle == padCharCount) { - padReadOff = padDataOffset; - padCurrCycle = 0; - } - - // byte length of current char in padding string - int singlePadCharByteLen = UTF8StringUtil.charSize(bytes2, padReadOff); - - // write singlePadCharByteLen bytes from padReadOff - out.write(bytes2, padReadOff, singlePadCharByteLen); - - // move read pointer in pad string content - padReadOff += singlePadCharByteLen; - padCurrCycle++; - } - - // write the base string's content (bytes0) - // bytes used for base string length and the len is at string start start0 + 1 - int basePrefixBytes = UTF8StringUtil.getNumBytesToStoreLength(bytes0, start0 + 1); - // base string data start offset - int baseDataOff = start0 + 1 + basePrefixBytes; - - // write originalLength bytes from baseDataOff - out.write(bytes0, baseDataOff, originalLength); - } - } catch (IOException e) { - throw new RuntimeException(e); - } - result.set(resultStorage); - } -} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringPadEvaluator.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringPadEvaluator.java new file mode 100644 index 0000000..edefc47 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringPadEvaluator.java @@ -0,0 +1,131 @@ +/* + * 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.runtime.evaluators.functions; + +import org.apache.asterix.om.base.AMutableInt32; +import org.apache.asterix.om.exceptions.ExceptionUtil; +import org.apache.asterix.om.types.ATypeTag; +import org.apache.asterix.runtime.evaluators.common.ArgumentUtils; +import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory; +import org.apache.hyracks.api.context.IEvaluatorContext; +import org.apache.hyracks.api.exceptions.HyracksDataException; +import org.apache.hyracks.api.exceptions.SourceLocation; +import org.apache.hyracks.data.std.api.IPointable; +import org.apache.hyracks.data.std.primitive.VoidPointable; +import org.apache.hyracks.data.std.util.ArrayBackedValueStorage; +import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference; +import org.apache.hyracks.util.string.UTF8StringUtil; + +import java.io.DataOutput; +import java.io.IOException; + +public class StringPadEvaluator implements IScalarEvaluator { + + private final IEvaluatorContext ctx; + + private final IScalarEvaluator eval0; + private final IScalarEvaluator eval1; + private final IScalarEvaluator eval2; + + // Argument pointers. + final IPointable argPtrFirst = new VoidPointable(); + final IPointable argPtrSecond = new VoidPointable(); + final IPointable argPtrThird = new VoidPointable(); + private final AMutableInt32 mutableInt = new AMutableInt32(0); + + // For outputting results. + public ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage(); + public DataOutput out = resultStorage.getDataOutput(); + public byte[] tempLengthArray = new byte[5]; + + private final FunctionIdentifier funcID; + protected final SourceLocation sourceLoc; + + public StringPadEvaluator(IEvaluatorContext context, IScalarEvaluatorFactory eval0, + IScalarEvaluatorFactory eval1, IScalarEvaluatorFactory eval2, FunctionIdentifier funcID, SourceLocation sourceLoc) + throws HyracksDataException { + this.eval0 = eval0.createScalarEvaluator(context); + this.eval1 = eval1.createScalarEvaluator(context); + this.eval2 = eval2.createScalarEvaluator(context); + this.funcID = funcID; + this.sourceLoc = sourceLoc; + this.ctx = context; + } + + @Override + public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException { + resultStorage.reset(); + // Gets the arguments + eval0.evaluate(tuple, argPtrFirst); + eval1.evaluate(tuple, argPtrSecond); + eval2.evaluate(tuple, argPtrThird); + + if (PointableHelper.checkAndSetMissingOrNull(result, argPtrFirst, argPtrSecond, argPtrThird)) { + return; + } + + //base string + byte[] bytes0 = argPtrFirst.getByteArray(); + int start0 = argPtrFirst.getStartOffset(); + + if (bytes0[start0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) { + PointableHelper.setNull(result); + ExceptionUtil.warnTypeMismatch(ctx, sourceLoc, funcID, bytes0[start0], 0, ATypeTag.STRING); + return; + } + + //target length + byte[] bytes1 = argPtrSecond.getByteArray(); + int start1 = argPtrSecond.getStartOffset(); + + if (bytes1[start1] != ATypeTag.SERIALIZED_INT64_TYPE_TAG) { + PointableHelper.setNull(result); + ExceptionUtil.warnTypeMismatch(ctx, sourceLoc, funcID, bytes1[start1], 1, ATypeTag.INTEGER); + return; + } + + // Gets the target length. + if (!ArgumentUtils.setInteger(ctx, sourceLoc, funcID, 1, bytes1, start1, mutableInt)) { + PointableHelper.setNull(result); + return; + } + int targetLength = mutableInt.getIntegerValue(); + // negative len is silently taken as zero + targetLength = Math.max(targetLength, 0); + + //padding string + byte[] bytes2 = argPtrThird.getByteArray(); + int start2 = argPtrThird.getStartOffset(); + + if (bytes2[start2] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) { + PointableHelper.setNull(result); + ExceptionUtil.warnTypeMismatch(ctx, sourceLoc, funcID, bytes2[start2], 2, ATypeTag.STRING); + return; + } + process(bytes0, start0, targetLength, bytes2, start2); + result.set(resultStorage); + } + + public void process(byte[] bytes0, int start0, int targetLength, byte[] bytes2, int start2){ + //no-op, to be overridden by subclasses + } +} -- To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/19830 To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-Project: asterixdb Gerrit-Branch: ionic Gerrit-Change-Id: I852598eeb891e1df7e87e12c5122f2114ccce32c Gerrit-Change-Number: 19830 Gerrit-PatchSet: 1 Gerrit-Owner: Janhavi Tripurwar <[email protected]> Gerrit-MessageType: newchange
