Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A696E200B88 for ; Thu, 22 Sep 2016 21:49:28 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id A531F160AAD; Thu, 22 Sep 2016 19:49:28 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C2C08160AA9 for ; Thu, 22 Sep 2016 21:49:27 +0200 (CEST) Received: (qmail 52351 invoked by uid 500); 22 Sep 2016 19:49:27 -0000 Mailing-List: contact notifications-help@asterixdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@asterixdb.apache.org Delivered-To: mailing list notifications@asterixdb.apache.org Received: (qmail 52342 invoked by uid 99); 22 Sep 2016 19:49:27 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Sep 2016 19:49:27 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 983BEC86FD for ; Thu, 22 Sep 2016 19:49:26 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.919 X-Spam-Level: X-Spam-Status: No, score=0.919 tagged_above=-999 required=6.31 tests=[SPF_FAIL=0.919] autolearn=disabled Received: from mx2-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id SNKI1FrD7NTE for ; Thu, 22 Sep 2016 19:49:24 +0000 (UTC) Received: from unhygienix.ics.uci.edu (unhygienix.ics.uci.edu [128.195.14.130]) by mx2-lw-eu.apache.org (ASF Mail Server at mx2-lw-eu.apache.org) with ESMTP id A5BE45F177 for ; Thu, 22 Sep 2016 19:49:23 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by unhygienix.ics.uci.edu (Postfix) with ESMTP id B8092241E41; Thu, 22 Sep 2016 12:49:22 -0700 (PDT) Date: Thu, 22 Sep 2016 12:49:22 -0700 From: "abdullah alamoudi (Code Review)" Message-ID: Reply-To: bamousaa@gmail.com X-Gerrit-MessageType: newchange Subject: Change in asterixdb[master]: Add Record To Map Methods X-Gerrit-Change-Id: I525b99fa56251579e3ba42d79dd578c625fcab67 X-Gerrit-ChangeURL: X-Gerrit-Commit: d0a087e5ab3321bfe308d142e1460da83a66d9c4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-Disposition: inline User-Agent: Gerrit/2.8.4 To: undisclosed-recipients:; archived-at: Thu, 22 Sep 2016 19:49:28 -0000 abdullah alamoudi has uploaded a new change for review. https://asterix-gerrit.ics.uci.edu/1198 Change subject: Add Record To Map Methods ...................................................................... Add Record To Map Methods Change-Id: I525b99fa56251579e3ba42d79dd578c625fcab67 --- M asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/LangRecordParseUtil.java 1 file changed, 51 insertions(+), 7 deletions(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/98/1198/1 diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/LangRecordParseUtil.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/LangRecordParseUtil.java index c46b0be..00d8683 100644 --- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/LangRecordParseUtil.java +++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/LangRecordParseUtil.java @@ -22,6 +22,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Map; import org.apache.asterix.builders.OrderedListBuilder; import org.apache.asterix.builders.RecordBuilder; @@ -38,9 +39,14 @@ import org.apache.asterix.om.base.AInt64; import org.apache.asterix.om.base.AMutableString; import org.apache.asterix.om.base.ANull; +import org.apache.asterix.om.base.AOrderedList; +import org.apache.asterix.om.base.ARecord; import org.apache.asterix.om.base.AString; +import org.apache.asterix.om.base.IACursor; +import org.apache.asterix.om.base.IAObject; import org.apache.asterix.om.types.ARecordType; import org.apache.asterix.om.types.BuiltinType; +import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; import org.apache.hyracks.algebricks.common.utils.Pair; import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer; import org.apache.hyracks.api.exceptions.HyracksDataException; @@ -78,16 +84,14 @@ break; default: throw new HyracksDataException(ErrorCode.ASTERIX, ErrorCode.ERROR_PARSE_ERROR, - NOT_ALLOWED_EXPRESSIONS_ERROR_MESSAGE, - new Serializable[] { Expression.Kind.LITERAL_EXPRESSION.toString(), - Expression.Kind.RECORD_CONSTRUCTOR_EXPRESSION.toString(), + NOT_ALLOWED_EXPRESSIONS_ERROR_MESSAGE, new Serializable[] { Expression.Kind.LITERAL_EXPRESSION + .toString(), Expression.Kind.RECORD_CONSTRUCTOR_EXPRESSION.toString(), Expression.Kind.LIST_CONSTRUCTOR_EXPRESSION.toString() }); } } public static void parseRecord(RecordConstructor recordValue, ArrayBackedValueStorage serialized, boolean tagged, - List> defaults) - throws HyracksDataException { + List> defaults) throws HyracksDataException { AMutableString fieldNameString = new AMutableString(null); ArrayBackedValueStorage fieldName = new ArrayBackedValueStorage(); ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage(); @@ -102,8 +106,8 @@ // get key fieldNameString.setValue(exprToStringLiteral(fb.getLeftExpr()).getStringValue()); if (!fieldNames.add(fieldNameString.getStringValue())) { - throw new HyracksDataException( - "Field " + fieldNameString.getStringValue() + " was specified multiple times"); + throw new HyracksDataException("Field " + fieldNameString.getStringValue() + + " was specified multiple times"); } stringSerde.serialize(fieldNameString, fieldName.getDataOutput()); // get value @@ -187,4 +191,44 @@ "Unknown Literal Type %1$s", value.getLiteralType()); } } + + public static void recordToMap(Map map, ARecord record) + throws AlgebricksException { + String[] keys = record.getType().getFieldNames(); + for (int i = 0; i < keys.length; i++) { + String key = keys[i]; + String value = aObjToString(record.getValueByPos(i)); + map.put(key, value); + } + } + + public static String aObjToString(IAObject aObj) throws AlgebricksException { + switch (aObj.getType().getTypeTag()) { + case DOUBLE: + return Double.toString(((ADouble) aObj).getDoubleValue()); + case INT64: + return Long.toString(((AInt64) aObj).getLongValue()); + case ORDEREDLIST: + return aOrderedListToString((AOrderedList) aObj); + case STRING: + return ((AString) aObj).getStringValue(); + default: + throw new AlgebricksException("value of type " + aObj.getType() + " is not supported yet"); + } + } + + private static String aOrderedListToString(AOrderedList ol) throws AlgebricksException { + StringBuilder delimitedList = new StringBuilder(); + IACursor cursor = ol.getCursor(); + if (cursor.next()) { + IAObject next = cursor.get(); + delimitedList.append(aObjToString(next)); + } + while (cursor.next()) { + IAObject next = cursor.get(); + delimitedList.append(","); + delimitedList.append(aObjToString(next)); + } + return delimitedList.toString(); + } } -- To view, visit https://asterix-gerrit.ics.uci.edu/1198 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I525b99fa56251579e3ba42d79dd578c625fcab67 Gerrit-PatchSet: 1 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: abdullah alamoudi