From commits-return-14791-apmail-kafka-commits-archive=kafka.apache.org@kafka.apache.org Wed Jun 10 07:47:25 2020 Return-Path: X-Original-To: apmail-kafka-commits-archive@www.apache.org Delivered-To: apmail-kafka-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with SMTP id B380E198C0 for ; Wed, 10 Jun 2020 07:47:24 +0000 (UTC) Received: (qmail 9256 invoked by uid 500); 10 Jun 2020 07:47:23 -0000 Delivered-To: apmail-kafka-commits-archive@kafka.apache.org Received: (qmail 9185 invoked by uid 500); 10 Jun 2020 07:47:23 -0000 Mailing-List: contact commits-help@kafka.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@kafka.apache.org Delivered-To: mailing list commits@kafka.apache.org Received: (qmail 9175 invoked by uid 99); 10 Jun 2020 07:47:23 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Jun 2020 07:47:23 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 452628D417; Wed, 10 Jun 2020 07:47:23 +0000 (UTC) Date: Wed, 10 Jun 2020 07:47:19 +0000 To: "commits@kafka.apache.org" Subject: [kafka] branch 2.5 updated: KAFKA-8938: Improve allocations during Struct validation in ConnectSchema (#7384) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <159177523650.18651.3862543869530631930@gitbox.apache.org> From: kkarantasis@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: kafka X-Git-Refname: refs/heads/2.5 X-Git-Reftype: branch X-Git-Oldrev: 1444ec6586fc3e65026cf99982e857296b607528 X-Git-Newrev: 8134f0cec6d6dcadeaf15abbd9a06d324b304118 X-Git-Rev: 8134f0cec6d6dcadeaf15abbd9a06d324b304118 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. kkarantasis pushed a commit to branch 2.5 in repository https://gitbox.apache.org/repos/asf/kafka.git The following commit(s) were added to refs/heads/2.5 by this push: new 8134f0c KAFKA-8938: Improve allocations during Struct validation in ConnectSchema (#7384) 8134f0c is described below commit 8134f0cec6d6dcadeaf15abbd9a06d324b304118 Author: Auston AuthorDate: Tue Jun 9 14:55:56 2020 -0700 KAFKA-8938: Improve allocations during Struct validation in ConnectSchema (#7384) Struct value validation in Kafka Connect can be optimized to avoid creating an Iterator when the expectedClasses list is of size 1. This is a meaningful enhancement for high throughput connectors. Reviewers: Konstantine Karantasis --- .../java/org/apache/kafka/connect/data/ConnectSchema.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/connect/api/src/main/java/org/apache/kafka/connect/data/ConnectSchema.java b/connect/api/src/main/java/org/apache/kafka/connect/data/ConnectSchema.java index 66630d1..a465b12 100644 --- a/connect/api/src/main/java/org/apache/kafka/connect/data/ConnectSchema.java +++ b/connect/api/src/main/java/org/apache/kafka/connect/data/ConnectSchema.java @@ -229,12 +229,17 @@ public class ConnectSchema implements Schema { + " for field: \"" + name + "\""); boolean foundMatch = false; - for (Class expectedClass : expectedClasses) { - if (expectedClass.isInstance(value)) { - foundMatch = true; - break; + if (expectedClasses.size() == 1) { + foundMatch = expectedClasses.get(0).isInstance(value); + } else { + for (Class expectedClass : expectedClasses) { + if (expectedClass.isInstance(value)) { + foundMatch = true; + break; + } } } + if (!foundMatch) throw new DataException("Invalid Java object for schema type " + schema.type() + ": " + value.getClass()