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 6880B200BF3 for ; Wed, 21 Dec 2016 17:11:03 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 65C37160B26; Wed, 21 Dec 2016 16:11:03 +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 442E6160B3F for ; Wed, 21 Dec 2016 17:11:02 +0100 (CET) Received: (qmail 93516 invoked by uid 500); 21 Dec 2016 16:11:01 -0000 Mailing-List: contact issues-help@flink.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flink.apache.org Delivered-To: mailing list issues@flink.apache.org Received: (qmail 93091 invoked by uid 99); 21 Dec 2016 16:11:01 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Dec 2016 16:11:01 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id AFCDF2C2ABA for ; Wed, 21 Dec 2016 16:11:00 +0000 (UTC) Date: Wed, 21 Dec 2016 16:11:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@flink.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (FLINK-5348) Support custom field names for RowTypeInfo MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Wed, 21 Dec 2016 16:11:03 -0000 [ https://issues.apache.org/jira/browse/FLINK-5348?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15767435#comment-15767435 ] ASF GitHub Bot commented on FLINK-5348: --------------------------------------- Github user fhueske commented on a diff in the pull request: https://github.com/apache/flink/pull/3020#discussion_r93465385 --- Diff: flink-core/src/main/java/org/apache/flink/api/java/typeutils/RowTypeInfo.java --- @@ -54,6 +76,152 @@ public RowTypeInfo(TypeInformation... types) { } } + public RowTypeInfo(List> types, List fieldNames) { + super(Row.class, types == null ? null : types.toArray(new TypeInformation[types.size()])); + checkNotNull(fieldNames, "FieldNames should not be null."); + checkArgument( + types.size() == fieldNames.size(), + "Number of field types and names is different."); + checkArgument( + types.size() == new HashSet<>(fieldNames).size(), + "Field names are not unique."); + + this.fieldNames = new String[fieldNames.size()]; + + for (int i = 0; i < fieldNames.size(); i++) { + this.fieldNames[i] = fieldNames.get(i); + } + } + + @Override + public void getFlatFields(String fieldExpression, int offset, List result) { + Matcher matcher = PATTERN_NESTED_FIELDS_WILDCARD.matcher(fieldExpression); + + if (!matcher.matches()) { + throw new InvalidFieldReferenceException( + "Invalid tuple field reference \"" + fieldExpression + "\"."); + } + + String field = matcher.group(0); + + if ((field.equals(ExpressionKeys.SELECT_ALL_CHAR)) || + (field.equals(ExpressionKeys.SELECT_ALL_CHAR_SCALA))) { + // handle select all + int keyPosition = 0; + for (TypeInformation fType : types) { + if (fType instanceof CompositeType) { + CompositeType cType = (CompositeType) fType; + cType.getFlatFields(ExpressionKeys.SELECT_ALL_CHAR, offset + keyPosition, result); + keyPosition += cType.getTotalFields() - 1; + } else { + result.add(new FlatFieldDescriptor(offset + keyPosition, fType)); + } + keyPosition++; + } + } else { + field = matcher.group(1); + + Matcher intFieldMatcher = PATTERN_INT_FIELD.matcher(field); + TypeInformation fieldType = null; + if (intFieldMatcher.matches()) { + // field expression is an integer + int fieldIndex = Integer.valueOf(field); + if (fieldIndex > this.getArity()) { --- End diff -- `TupleTypeBase.getFieldAt()` does check for index bounds as well and throws an `IndexOutOfBoundsException`. So we could simplify this a bit here. > Support custom field names for RowTypeInfo > ------------------------------------------ > > Key: FLINK-5348 > URL: https://issues.apache.org/jira/browse/FLINK-5348 > Project: Flink > Issue Type: Improvement > Components: Core > Reporter: Jark Wu > Assignee: Jark Wu > > Currently, the RowTypeInfo doesn't support optional custom field names, but forced to generate {{f0}} ~ {{fn}} as field names. It would be better to support custom names and will benefit some cases (e.g. FLINK-5280). -- This message was sent by Atlassian JIRA (v6.3.4#6332)