[ 
https://issues.apache.org/jira/browse/PHOENIX-1673?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14662426#comment-14662426
 ] 

ASF GitHub Bot commented on PHOENIX-1673:
-----------------------------------------

Github user JeffreyLyonsD2L commented on a diff in the pull request:

    https://github.com/apache/phoenix/pull/104#discussion_r36560020
  
    --- Diff: 
phoenix-core/src/it/java/org/apache/phoenix/end2end/MultiTenantTableIT.java ---
    @@ -0,0 +1,140 @@
    +/*
    + * 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.phoenix.end2end;
    +
    +import static org.junit.Assert.assertEquals;
    +import static org.junit.Assert.assertFalse;
    +import static org.junit.Assert.assertTrue;
    +import static org.junit.Assert.fail;
    +
    +import java.sql.*;
    +import java.util.Properties;
    +import java.util.Collection;
    +import java.util.List;
    +import com.google.common.collect.Lists;
    +
    +import org.apache.phoenix.exception.SQLExceptionCode;
    +import org.apache.phoenix.schema.TableAlreadyExistsException;
    +import org.apache.phoenix.util.PhoenixRuntime;
    +import org.junit.Test;
    +import org.junit.runner.RunWith;
    +import org.junit.runners.Parameterized;
    +import org.junit.runners.Parameterized.Parameters;
    +
    +@RunWith(Parameterized.class)
    +public class MultiTenantTableIT extends BaseClientManagedTimeIT {
    +
    +    private Connection regularConnection(String url) throws SQLException {
    +        Properties props = new Properties();
    +        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, 
Long.toString(nextTimestamp()));
    +        return DriverManager.getConnection(url, props);
    +    }
    +
    +    private Connection tenantConnection(String url) throws SQLException {
    +        Properties props = new Properties();
    +        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, 
Long.toString(nextTimestamp()));
    +        String tenantIdProperty = this.tenantId.replaceAll("\'", "");
    +        props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, 
tenantIdProperty);
    +        return DriverManager.getConnection(url, props);
    +    }
    +
    +    private final String ddl;
    +    private final String dataType;
    +    private final String tenantId;
    +    private final String otherTenantId;
    +    private final String table;
    +
    +    public MultiTenantTableIT( String dataType, String tenantId, String 
otherTenantId ) {
    +        this.dataType = dataType;
    +        this.tenantId = tenantId;
    +        this.otherTenantId = otherTenantId;
    +        String tbl = "foo" + dataType;
    +        if(tbl.contains("(")){
    +            tbl = tbl.substring(0, tbl.indexOf("("));
    +        }
    +        this.table = tbl;
    +        this.ddl = "create table " + table + " (" + "tid "+ dataType + " 
NOT NULL," + "id INTEGER NOT NULL, \n"
    +                + "val VARCHAR " + "CONSTRAINT pk PRIMARY KEY(tid, id)) \n"
    +                + "MULTI_TENANT=true";
    +    }
    +
    +    @Parameters
    +    public static Collection<Object[]> data() {
    +        List<Object[]> testCases = Lists.newArrayList();
    +        testCases.add(new Object[] { "INTEGER", "2147483647", "2147483646" 
});
    +        testCases.add(new Object[] { "UNSIGNED_INT", "2147483647", 
"2147483646" });
    +        testCases.add(new Object[] { "BIGINT", "9223372036854775807", 
"9223372036854775806" });
    +        testCases.add(new Object[] { "UNSIGNED_LONG", 
"9223372036854775807", "9223372036854775806" });
    +        testCases.add(new Object[] { "TINYINT", "127", "126" });
    +        testCases.add(new Object[] { "UNSIGNED_TINYINT", "85", "84" });
    +        testCases.add(new Object[] { "SMALLINT", "32767", "32766" });
    +        testCases.add(new Object[] { "UNSIGNED_SMALLINT", "32767", "32766" 
});
    +        testCases.add(new Object[] { "FLOAT", "3.4028234", "3.4028232" });
    +        testCases.add(new Object[] { "UNSIGNED_FLOAT", "3.4028234", 
"3.4028232" });
    +        testCases.add(new Object[] { "DOUBLE", "1.7976931348623157", 
"1.7976931348623156" });
    +        testCases.add(new Object[] { "UNSIGNED_DOUBLE", 
"1.7976931348623157", "1.7976931348623156" });
    +        testCases.add(new Object[] { "DECIMAL", "3.402823466", 
"3.402823465" });
    +        testCases.add(new Object[] { "VARCHAR", "\'NameOfTenant\'", 
"\'Nemesis\'" });
    +        testCases.add(new Object[] { "CHAR(10)", "\'1234567890\'", 
"\'Nemesis\'" });
    +
    +        return testCases;
    +    }
    +
    +    @Test
    +    public void testMultiTenantTables() throws Exception {
    +        Connection conn = regularConnection(getUrl());
    +        conn.setAutoCommit(true);
    +        conn.createStatement().execute(ddl);
    +
    +
    +        try {
    +            conn.createStatement().execute(ddl);
    --- End diff --
    
    So I think this is convention I picked up from some other tests, but the 
goal of that try block is to actually throw the exception and then catch it and 
carry on. It seemed like the way that other tests were verifying table creation 
was to try creating it again and verifying that the second create fails because 
it already exists. I do want to verify the table got created, because prior to 
my changes a tenantId of anything but CHAR or VARCHAR would fail at creation. 
If there is a better way of checking if a table exists, I would certainly be 
open to it though.


> Allow tenant ID to be of any integral data type
> -----------------------------------------------
>
>                 Key: PHOENIX-1673
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-1673
>             Project: Phoenix
>          Issue Type: Improvement
>    Affects Versions: 4.3.0
>            Reporter: Mark Tse
>              Labels: Newbie, multi-tenant
>             Fix For: 4.4.1
>
>
> When creating multi-tenant tables and views, the column that identifies the 
> tenant (first primary key column) must be of type 'VARCHAR' or 'CHAR'.
> It should be possible to relax this restriction to use any integral data 
> type. The tenant ID from the connection property can be converted based on 
> the data type of the first primary key column.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to