@Override
    public TTableDescriptor toThrift(List<DescriptorTable.ReferencedPartitionInfo> partitions) {
        TJDBCTable tJDBCTable = new TJDBCTable();
        if (!Strings.isNullOrEmpty(resourceName)) {
            JDBCResource resource =
                    (JDBCResource) (GlobalStateMgr.getCurrentState().getResourceMgr().getResource(resourceName));
            tJDBCTable.setJdbc_driver_name(resource.getName());
            tJDBCTable.setJdbc_driver_url(resource.getProperty(JDBCResource.DRIVER_URL));
            tJDBCTable.setJdbc_driver_checksum(resource.getProperty(JDBCResource.CHECK_SUM));
            tJDBCTable.setJdbc_driver_class(resource.getProperty(JDBCResource.DRIVER_CLASS));

            tJDBCTable.setJdbc_url(resource.getProperty(JDBCResource.URI));
            tJDBCTable.setJdbc_table(jdbcTable);
            tJDBCTable.setJdbc_user(resource.getProperty(JDBCResource.USER));
            tJDBCTable.setJdbc_passwd(resource.getProperty(JDBCResource.PASSWORD));
        } else {
            String uri = properties.get(JDBCResource.URI);
            String driverName = buildCatalogDriveName(uri);
            tJDBCTable.setJdbc_driver_name(driverName);
            tJDBCTable.setJdbc_driver_url(properties.get(JDBCResource.DRIVER_URL));
            tJDBCTable.setJdbc_driver_checksum(properties.get(JDBCResource.CHECK_SUM));
            tJDBCTable.setJdbc_driver_class(properties.get(JDBCResource.DRIVER_CLASS));

            if (properties.get(JDBC_TABLENAME) != null) {
                tJDBCTable.setJdbc_url(uri);
            } else {
                int delimiterIndex = uri.indexOf("?");
                if (delimiterIndex > 0) {
                    String urlPrefix = uri.substring(0, delimiterIndex);
                    String urlSuffix = uri.substring(delimiterIndex + 1);
                    tJDBCTable.setJdbc_url(urlPrefix + "/" + dbName + "?" + urlSuffix);
                } else {
                    tJDBCTable.setJdbc_url(uri + "/" + dbName);
                }
            }
            tJDBCTable.setJdbc_table(jdbcTable);
            tJDBCTable.setJdbc_user(properties.get(JDBCResource.USER));
            tJDBCTable.setJdbc_passwd(properties.get(JDBCResource.PASSWORD));
        }

        TTableDescriptor tTableDescriptor = new TTableDescriptor(getId(), TTableType.JDBC_TABLE,
                fullSchema.size(), 0, getName(), "");
        tTableDescriptor.setJdbcTable(tJDBCTable);
        return tTableDescriptor;
    }
@Test
    public void testToThrift(@Mocked GlobalStateMgr globalStateMgr,
                             @Mocked ResourceMgr resourceMgr) throws Exception {
        new Expectations() {
            {
                GlobalStateMgr.getCurrentState();
                result = globalStateMgr;

                globalStateMgr.getResourceMgr();
                result = resourceMgr;

                resourceMgr.getResource("jdbc0");
                result = getMockedJDBCResource(resourceName);
            }
        };
        JDBCTable table = new JDBCTable(1000, "jdbc_table", columns, properties);
        TTableDescriptor tableDescriptor = table.toThrift(null);

        // build expected table descriptor
        JDBCResource resource = (JDBCResource) getMockedJDBCResource("jdbc0");
        TTableDescriptor expectedDesc =
                new TTableDescriptor(1000, TTableType.JDBC_TABLE, columns.size(), 0, "jdbc_table", "");
        TJDBCTable expectedTable = new TJDBCTable();
        // we will not compute checksum in ut, so we can skip to setJdbc_driver_checksum
        expectedTable.setJdbc_driver_name(resource.getName());
        expectedTable.setJdbc_driver_url(resource.getProperty(JDBCResource.DRIVER_URL));
        expectedTable.setJdbc_driver_class(resource.getProperty(JDBCResource.DRIVER_CLASS));
        expectedTable.setJdbc_url(resource.getProperty(JDBCResource.URI));
        expectedTable.setJdbc_table(this.table);
        expectedTable.setJdbc_user(resource.getProperty(JDBCResource.USER));
        expectedTable.setJdbc_passwd(resource.getProperty(JDBCResource.PASSWORD));
        expectedDesc.setJdbcTable(expectedTable);

        Assert.assertEquals(tableDescriptor, expectedDesc);
    }