package com.facebook.presto.metadata;

import javax.inject.Inject;

import static com.facebook.presto.metadata.InformationSchemaMetadata.INFORMATION_SCHEMA;
import static com.facebook.presto.metadata.MetadataUtil.checkTableName;
import static com.facebook.presto.metadata.SystemTables.SYSTEM_SCHEMA;
import static com.google.common.base.Preconditions.checkNotNull;

public class InternalMetadata
        extends AbstractMetadata
{
    private final InformationSchemaMetadata informationSchema;
    private final SystemTables systemTables;

    @Inject
    public InternalMetadata(InformationSchemaMetadata informationSchema, SystemTables systemTables)
    {
        this.informationSchema = checkNotNull(informationSchema, "informationSchema is null");
        this.systemTables = checkNotNull(systemTables, "systemTables is null");
    }

    @Override
    public TableMetadata getTable(String catalogName, String schemaName, String tableName)
    {
        checkTableName(catalogName, schemaName, tableName);

        if (tableName.equals(DualTable.NAME)) {
            return DualTable.getMetadata(catalogName, schemaName, tableName);
        }

        if (schemaName.equals(INFORMATION_SCHEMA)) {
            return informationSchema.getTableMetadata(catalogName, schemaName, tableName);
        }

        if (schemaName.equals(SYSTEM_SCHEMA)) {
            return systemTables.getTableMetadata(catalogName, schemaName, tableName);
        }

        return null;
    }
}

@@ -43,26 +43,98 @@
 ort 
-javax.inject.Injec
+com.google.common.collect.ImmutableList;%0A%0Aimport javax.inject.Inject;%0Aimport java.util.Lis
 t;%0A%0A
@@ -214,32 +214,130 @@
 RMATION_SCHEMA;%0A
+import static com.facebook.presto.metadata.InformationSchemaMetadata.listInformationSchemaTables;%0A
 import static co
@@ -455,32 +455,106 @@
 .SYSTEM_SCHEMA;%0A
+import static com.facebook.presto.metadata.SystemTables.listSystemTables;%0A
 import static co
@@ -1386,34 +1386,38 @@
      %7D%0A%0A        
-if
+switch
  (schemaName.equ
@@ -1412,24 +1412,37 @@
 hemaName
-.equals(
+) %7B%0A            case 
 INFORMAT
@@ -1447,29 +1447,29 @@
 ATION_SCHEMA
-)) %7B%0A
+:%0A   
             
@@ -1464,24 +1464,25 @@
             
+ 
 return infor
@@ -1560,41 +1560,416 @@
     
-%7D%0A%0A        if (schemaName.equals(
+    case SYSTEM_SCHEMA:%0A                return systemTables.getTableMetadata(catalogName, schemaName, tableName);%0A        %7D%0A%0A        return null;%0A    %7D%0A%0A    @Override%0A    public List%3CQualifiedTableName%3E listTables(String catalogName, String schemaName)%0A    %7B%0A        switch (schemaName) %7B%0A            case INFORMATION_SCHEMA:%0A                return listInformationSchemaTables(catalogName);%0A            case 
 SYST
@@ -1977,21 +1977,22 @@
 M_SCHEMA
-)) %7B%0A
+:%0A    
         
@@ -1994,33 +1994,37 @@
          return 
-s
+listS
 ystemTables.getT
@@ -2018,34 +2018,150 @@
 emTables
-.getTableMetadata(
+(catalogName);%0A        %7D%0A        return ImmutableList.of();%0A    %7D%0A%0A    @Override%0A    public List%3CTableColumn%3E listTableColumns(String 
 catalogN
@@ -2156,32 +2156,39 @@
 ing catalogName,
+ String
  schemaName, tab
@@ -2175,32 +2175,39 @@
 ring schemaName,
+ String
  tableName);%0A   
@@ -2193,33 +2193,38 @@
 tring tableName)
-;
+%0A    %7B
 %0A        %7D%0A%0A    
@@ -2216,38 +2216,74 @@
         
-%7D%0A%0A        return null
+// hack for SHOW COLUMNS%0A        return ImmutableList.of()
 ;%0A    %7D%0A

Fix SHOW TABLES and SHOW COLUMNS for internal tables