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 3CF87200CD1 for ; Wed, 26 Jul 2017 20:33:43 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 3B68F167D54; Wed, 26 Jul 2017 18:33:43 +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 7FCA7167CF8 for ; Wed, 26 Jul 2017 20:33:42 +0200 (CEST) Received: (qmail 40318 invoked by uid 500); 26 Jul 2017 18:33:40 -0000 Mailing-List: contact dev-help@drill.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@drill.apache.org Delivered-To: mailing list dev@drill.apache.org Received: (qmail 40174 invoked by uid 99); 26 Jul 2017 18:33:40 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Jul 2017 18:33:40 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5C3CFE3C41; Wed, 26 Jul 2017 18:33:39 +0000 (UTC) From: vdiravka To: dev@drill.apache.org Reply-To: dev@drill.apache.org References: In-Reply-To: Subject: [GitHub] drill pull request #877: DRILL-5660: Drill 1.10 queries fail due to Parquet ... Content-Type: text/plain Message-Id: <20170726183339.5C3CFE3C41@git1-us-west.apache.org> Date: Wed, 26 Jul 2017 18:33:39 +0000 (UTC) archived-at: Wed, 26 Jul 2017 18:33:43 -0000 Github user vdiravka commented on a diff in the pull request: https://github.com/apache/drill/pull/877#discussion_r129653855 --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/store/parquet/MetadataVersions.java --- @@ -0,0 +1,115 @@ +/* + * 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.drill.exec.store.parquet; + +import com.google.common.collect.Lists; +import org.apache.drill.common.Version; +import org.apache.drill.common.exceptions.DrillRuntimeException; + +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Supported metadata versions. + *

+ * Note: keep them synchronized with {@link Metadata.ParquetTableMetadataBase} versions + */ +public class MetadataVersions { + static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Metadata.class); + + /** + * Version 1: Introduces parquet file metadata caching.
+ * See DRILL-2743 + */ + public static final String V1 = "v1"; + /** + * Version 2: Metadata cache file size is reduced.
+ * See DRILL-4053 + */ + public static final String V2 = "v2"; + /** + * Version 3: Difference between v3 and v2 : min/max, type_length, precision, scale, repetitionLevel, definitionLevel.
+ * Filter pushdown for Parquet is implemented.
+ * See DRILL-1950 + */ + public static final String V3 = "v3"; + /** + * Version 3.1: Absolute paths of files and directories are replaced with relative ones.
+ * See DRILL-3867 + */ + public static final String V3_1 = "v3.1"; + + /** + * All historical versions of the Drill metadata cache files + */ + public static final List SUPPORTED_VERSIONS = Lists.newArrayList(V1, V2, V3, V3_1); + + /** + * @param metadataVersion parquet metadata version + * @return true if metadata version is supported, false otherwise + */ + public static boolean isVersionSupported(String metadataVersion) { + return SUPPORTED_VERSIONS.contains(metadataVersion); + } + + /** + * Helper compare method similar to {@link java.util.Comparator#compare} + * + * @param metadataVersion1 the first metadata version to be compared + * @param metadataVersion2 the second metadata version to be compared + * @return a negative integer, zero, or a positive integer as the + * first argument is less than, equal to, or greater than the + * second. + */ + public static int compare(String metadataVersion1, String metadataVersion2) { + if (isVersionSupported(metadataVersion1) && isVersionSupported(metadataVersion2)) { + return VersionParser.parse(metadataVersion1).compareTo(VersionParser.parse(metadataVersion2)); + } else { + // this is never reached + throw new DrillRuntimeException(String.format("Unsupported metadata version. '%s' version can't be compared with '%s'", + metadataVersion1, metadataVersion2)); + } + } + + /** + * Parses a parquet metadata version string + */ + public static class VersionParser { + // example: v3.1 or v2 + private static final String FORMAT = "v(\\d)\\.?(\\d)?"; + private static final Pattern PATTERN = Pattern.compile(FORMAT); + + /** + * @param metadataVersion text metadata version + * @return comparable metadata version object + */ + public static Version parse(String metadataVersion) { + Matcher matcher = PATTERN.matcher(metadataVersion); + if (!matcher.matches()) { + DrillRuntimeException.format("Could not parse metadata version '%s' using format '%s'", metadataVersion, FORMAT); + } + int majorVersion = Integer.parseInt(matcher.group(1)); + int minorVersion = 0; + if (matcher.group(2) != null) { + minorVersion = Integer.parseInt(matcher.group(2)); + } + return new Version(metadataVersion, majorVersion, minorVersion, 0, 0, ""); --- End diff -- `MetadataVersion` is introduced. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---