private List<Tuple> getAllTableStats(Schema outSchema) {
    List<TableStatsProto> statList = masterContext.getCatalog().getAllTableStats();
    List<Tuple> tuples = new ArrayList<Tuple>(statList.size());
    List<Column> columns = outSchema.getRootColumns();
    Tuple aTuple;

    for (TableStatsProto stat : statList) {
      aTuple = new VTuple(outSchema.size());

      for (int fieldId = 0; fieldId < columns.size(); fieldId++) {
        Column column = columns.get(fieldId);

        if ("tid".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createInt4(stat.getTid()));
        } else if ("num_rows".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createInt8(stat.getNumRows()));
        } else if ("num_bytes".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createInt8(stat.getNumBytes()));
        }
      }

      tuples.add(aTuple);
    }

    return tuples;
  }
  private List<Tuple> getAllTableOptions(Schema outSchema) {
    List<TableOptionProto> optionList = masterContext.getCatalog().getAllTableOptions();
    List<Tuple> tuples = new ArrayList<Tuple>(optionList.size());
    List<Column> columns = outSchema.getRootColumns();
    Tuple aTuple;

    for (TableOptionProto option : optionList) {
      aTuple = new VTuple(outSchema.size());

      for (int fieldId = 0; fieldId < columns.size(); fieldId++) {
        Column column = columns.get(fieldId);

        if ("tid".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createInt4(option.getTid()));
        } else if ("key_".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createText(option.getKeyval().getKey()));
        } else if ("value_".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createText(option.getKeyval().getValue()));
        }
      }

      tuples.add(aTuple);
    }

    return tuples;
  }
  private List<Tuple> getTables(Schema outSchema) {
    List<TableDescriptorProto> tables = masterContext.getCatalog().getAllTables();
    List<Tuple> tuples = new ArrayList<Tuple>(tables.size());
    List<Column> columns = outSchema.getRootColumns();
    Tuple aTuple;

    for (TableDescriptorProto table : tables) {
      aTuple = new VTuple(outSchema.size());

      for (int fieldId = 0; fieldId < columns.size(); fieldId++) {
        Column column = columns.get(fieldId);
        if ("tid".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createInt4(table.getTid()));
        } else if ("db_id".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createInt4(table.getDbId()));
        } else if ("table_name".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createText(table.getName()));
        } else if ("table_type".equalsIgnoreCase(column.getSimpleName())) {
          if (table.hasTableType()) {
            aTuple.put(fieldId, DatumFactory.createText(table.getTableType()));
          } else {
            aTuple.put(fieldId, DatumFactory.createNullDatum());
          }
        } else if ("path".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createText(table.getPath()));
        } else if ("store_type".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createText(table.getStoreType()));
        }
      }

      tuples.add(aTuple);
    }

    return tuples;
  }
  private List<Tuple> getDatabases(Schema outSchema) {
    List<DatabaseProto> databases = masterContext.getCatalog().getAllDatabases();
    List<Tuple> tuples = new ArrayList<Tuple>(databases.size());
    List<Column> columns = outSchema.getRootColumns();
    Tuple aTuple;

    for (DatabaseProto database : databases) {
      aTuple = new VTuple(outSchema.size());

      for (int fieldId = 0; fieldId < columns.size(); fieldId++) {
        Column column = columns.get(fieldId);
        if ("db_id".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createInt4(database.getId()));
        } else if ("db_name".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createText(database.getName()));
        } else if ("space_id".equalsIgnoreCase(column.getSimpleName())) {
          if (database.hasSpaceId()) {
            aTuple.put(fieldId, DatumFactory.createInt4(database.getSpaceId()));
          } else {
            aTuple.put(fieldId, DatumFactory.createNullDatum());
          }
        }
      }

      tuples.add(aTuple);
    }

    return tuples;
  }
  private List<Tuple> getAllPartitions(Schema outSchema) {
    List<TablePartitionProto> partitionList = masterContext.getCatalog().getAllPartitions();
    List<Tuple> tuples = new ArrayList<Tuple>(partitionList.size());
    List<Column> columns = outSchema.getRootColumns();
    Tuple aTuple;

    for (TablePartitionProto partition : partitionList) {
      aTuple = new VTuple(outSchema.size());

      for (int fieldId = 0; fieldId < columns.size(); fieldId++) {
        Column column = columns.get(fieldId);

        if ("partition_id".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createInt4(partition.getPartitionId()));
        } else if ("tid".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createInt4(partition.getTid()));
        } else if ("partition_name".equalsIgnoreCase(column.getSimpleName())) {
          if (partition.hasPartitionName()) {
            aTuple.put(fieldId, DatumFactory.createText(partition.getPartitionName()));
          } else {
            aTuple.put(fieldId, DatumFactory.createNullDatum());
          }
        } else if ("path".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createText(partition.getPath()));
        }
      }

      tuples.add(aTuple);
    }

    return tuples;
  }
Exemple #6
0
  public static void main(String[] args) throws IOException {
    // get the information of table address
    DatabaseCatalog databaseCatalog = DatabaseCatalog.getInstance();
    databaseCatalog.autogetTableInfo();
    Schema schema = Schema.getInstance();
    schema.getSchemaInfor("samples/input/db/schema.txt");
    Aliases aliases = Aliases.getInstance();
    //		aliases.addaliase("S", "Sailors");
    //		ScanOperator scanOperator = new ScanOperator("S");
    //		scanOperator.dump();

    try {
      CCJSqlParser parser =
          new CCJSqlParser(new FileReader("/Users/hanwenwang/Desktop/queries.sql"));
      Statement statement;
      while ((statement = parser.Statement()) != null) {
        Select select = (Select) statement;
        System.out.println("Select body is " + select.getSelectBody());
        PlainSelect plainSelect = (PlainSelect) select.getSelectBody();
        String aliasName = ((Table) plainSelect.getFromItem()).getAlias();
        String tableName = ((Table) plainSelect.getFromItem()).getName();
        aliases.addaliase(aliasName, tableName);
        ScanOperator scanOperator1 = new ScanOperator(aliasName);
        //				scanOperator1.dump();
        ProjectOperator projectOperator =
            new ProjectOperator(scanOperator1, plainSelect.getSelectItems());
        projectOperator.dump();
      }
    } catch (Exception e) {
      System.err.println("Exception occurred during parsing");
      e.printStackTrace();
    }
  }
  @Override
  public String toString() {
    StringBuilder res = new StringBuilder();
    res.append("ReverseEngineering: ").append("\n");

    if (!isBlank(catalogs)) {
      for (Catalog catalog : catalogs) {
        catalog.toString(res, "  ");
      }
    }

    if (!isBlank(schemas)) {
      for (Schema schema : schemas) {
        schema.toString(res, "  ");
      }
    }

    if (skipRelationshipsLoading != null && skipRelationshipsLoading) {
      res.append("\n").append("        Skip Relationships Loading");
    }
    if (skipPrimaryKeyLoading != null && skipPrimaryKeyLoading) {
      res.append("\n").append("        Skip PrimaryKey Loading");
    }

    return super.toString(res, "  ").toString();
  }
  public void createTable(String tableName, String[] columnFamily) {
    try {
      /* drop existing tables */
      boolean if_exists = true;
      client.table_drop(namespace, tableName, if_exists);

      Schema schema = new Schema();

      Map<String, ColumnFamilySpec> column_families = new HashMap<String, ColumnFamilySpec>();

      ColumnFamilySpec cf;
      for (String column : columnFamily) {
        cf = new ColumnFamilySpec();
        cf.setName(column);
        column_families.put(column, cf);
      }

      schema.setColumn_families(column_families);
      client.table_create(namespace, tableName, schema);

    } catch (ClientException e) {
      System.out.println(e.message);
      System.exit(1);
    } catch (TException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Exemple #9
0
  public static SqlOpProject create(SqlOp subOp, List<String> columnNames) {

    Map<String, TypeToken> typeMap = subOp.getSchema().getTypeMap();

    Schema newSchema = new SchemaImpl();

    assert subOp.getSchema().getColumnNames().containsAll(columnNames)
        : "Projection must not reference undefined columns; "
            + "referenced: "
            + columnNames
            + ", defined: "
            + subOp.getSchema().getColumnNames();

    for (String name : columnNames) {

      newSchema.getColumnNames().add(name);

      TypeToken type = typeMap.get(name);
      newSchema.getTypeMap().put(name, type);
    }

    SqlOpProject result = new SqlOpProject(newSchema, subOp, columnNames);

    return result;
  }
  @Test
  public void simpleTest() {
    final String id = "1";

    SchemaRegistryMultiple registry = createSchemaRegistry();

    // Get schema for ads
    Schema tempAdsSchema = registry.getSchema(SCHEMA_ADS_KEYS);
    Assert.assertEquals(SCHEMA_ADS_KEYS, tempAdsSchema.getSchemaKeys());

    // Get schema for sales
    Schema tempSalesSchema = registry.getSchema(SCHEMA_SALES_KEYS);
    Assert.assertEquals(SCHEMA_SALES_KEYS, tempSalesSchema.getSchemaKeys());

    // Query schema for ads
    SchemaQuery schemaQueryAds = new SchemaQuery(id, SCHEMA_ADS_KEYS);
    SchemaResult result = registry.getSchemaResult(schemaQueryAds);
    Assert.assertEquals(1, result.getGenericSchemas().length);
    Assert.assertEquals(SCHEMA_ADS_KEYS, result.getGenericSchemas()[0].getSchemaKeys());

    // Query schema for sales
    SchemaQuery schemaQuerySales = new SchemaQuery(id, SCHEMA_SALES_KEYS);
    result = registry.getSchemaResult(schemaQuerySales);
    Assert.assertEquals(1, result.getGenericSchemas().length);
    Assert.assertEquals(SCHEMA_SALES_KEYS, result.getGenericSchemas()[0].getSchemaKeys());
  }
Exemple #11
0
 @Test
 /**
  * Test that equals() and hashCode() don't require exponential time on certain pathological
  * schemas.
  */
 public void testSchemaExplosion() throws Exception {
   for (int i = 1; i < 15; i++) { // 15 is big enough to trigger
     // create a list of records, each with a single field whose type is a
     // union of all of the records.
     List<Schema> recs = new ArrayList<Schema>();
     for (int j = 0; j < i; j++)
       recs.add(Schema.createRecord("" + (char) ('A' + j), null, null, false));
     for (Schema s : recs) {
       Schema union = Schema.createUnion(recs);
       Field f = new Field("x", union, null, null);
       List<Field> fields = new ArrayList<Field>();
       fields.add(f);
       s.setFields(fields);
     }
     // check that equals and hashcode are correct and complete in a
     // reasonable amount of time
     for (Schema s1 : recs) {
       Schema s2 = Schema.parse(s1.toString());
       assertEquals(s1.hashCode(), s2.hashCode());
       assertEquals(s1, s2);
     }
   }
 }
Exemple #12
0
  /**
   * Initialization to be done after constructor assignments, such as setting of the all-important
   * DDFManager.
   */
  protected void initialize(
      DDFManager manager,
      Object data,
      Class<?>[] typeSpecs,
      String namespace,
      String name,
      Schema schema)
      throws DDFException {
    this.validateSchema(schema);
    this.setManager(manager); // this must be done first in case later stuff needs a manager

    if (typeSpecs != null) {
      this.getRepresentationHandler().set(data, typeSpecs);
    }

    this.getSchemaHandler().setSchema(schema);
    if (schema != null && schema.getTableName() == null) {
      String tableName = this.getSchemaHandler().newTableName();
      schema.setTableName(tableName);
    }

    if (Strings.isNullOrEmpty(namespace)) namespace = this.getManager().getNamespace();
    this.setNamespace(namespace);

    manager.setDDFUUID(this, UUID.randomUUID());

    if (!Strings.isNullOrEmpty(name)) manager.setDDFName(this, name);

    // Facades
    this.ML = new MLFacade(this, this.getMLSupporter());
    this.VIEWS = new ViewsFacade(this, this.getViewHandler());
    this.Transform = new TransformFacade(this, this.getTransformationHandler());
    this.R = new RFacade(this, this.getAggregationHandler());
    this.mCreatedTime = new Date();
  }
  /** testEndObjectStates */
  public void testEndObjectStates() {
    // create object and configure it
    Schema schema = new Schema();
    SchemaObject state = schema.createObject();
    String propertyName = "myProperty";
    state.addProperty(propertyName, "String");

    // build tests
    List<EventResult> goodList =
        this.createGoodList( //
            EnumSet.of(SchemaEventType.END_OBJECT, SchemaEventType.START_OBJECT_ENTRY), //
            propertyName //
            );

    // build initializer used before each test runs
    StateInitializer initializer =
        new StateInitializer() {
          public void initialize(IState state) {
            state.enter();
            state.transition(_context, SchemaEventType.START_OBJECT, null);
          }
        };

    this.testStates(state, initializer, goodList.toArray(new EventResult[goodList.size()]));
  }
  /** Initialize dictionaries for dimension values */
  private void initializeAndBuildDictionaries(
      Schema schema, Map<String, ColumnIndexCreationInfo> columnInfo, File file) throws Exception {
    for (final FieldSpec spec : schema.getAllFieldSpecs()) {
      final ColumnIndexCreationInfo info = columnInfo.get(spec.getName());
      if (info.isCreateDictionary()) {
        dictionaryCreatorMap.put(
            spec.getName(),
            new SegmentDictionaryCreator(
                info.hasNulls(), info.getSortedUniqueElementsArray(), spec, file));
      } else {
        throw new RuntimeException("Creation of indices without dictionaries is not implemented!");
      }
      dictionaryCreatorMap.get(spec.getName()).build();
    }

    // Add __ALL__ to dimension dictionaries
    for (DimensionFieldSpec spec : schema.getDimensionFieldSpecs()) {
      Object allValue = StarTreeIndexNode.getAllValue(spec);
      if (schema.getFieldSpecFor(spec.getName()).isSingleValueField()) {
        Object allIndex = dictionaryCreatorMap.get(spec.getName()).indexOfSV(allValue);
      } else {
        Object allIndex = dictionaryCreatorMap.get(spec.getName()).indexOfMV(allValue);
      }
    }
  }
Exemple #15
0
  @Test
  public void structuredAndUnstructuredOptions() throws Exception {
    // From https://developers.google.com/protocol-buffers/docs/proto#options
    Schema schema =
        new SchemaBuilder()
            .add(
                "foo.proto",
                ""
                    + "import \"google/protobuf/descriptor.proto\";\n"
                    + "message FooOptions {\n"
                    + "  optional int32 opt1 = 1;\n"
                    + "  optional string opt2 = 2;\n"
                    + "}\n"
                    + "\n"
                    + "extend google.protobuf.FieldOptions {\n"
                    + "  optional FooOptions foo_options = 1234;\n"
                    + "}\n"
                    + "\n"
                    + "message Bar {\n"
                    + "  optional int32 a = 1 [(foo_options).opt1 = 123, (foo_options).opt2 = \"baz\"];\n"
                    + "  optional int32 b = 2 [(foo_options) = { opt1: 456 opt2: \"quux\" }];\n"
                    + "}\n")
            .add("google/protobuf/descriptor.proto")
            .build();

    ProtoMember fooOptions = ProtoMember.get(Options.FIELD_OPTIONS, "foo_options");
    ProtoMember opt1 = ProtoMember.get(ProtoType.get("FooOptions"), "opt1");
    ProtoMember opt2 = ProtoMember.get(ProtoType.get("FooOptions"), "opt2");

    MessageType bar = (MessageType) schema.getType("Bar");
    assertThat(bar.field("a").options().map())
        .isEqualTo(ImmutableMap.of(fooOptions, ImmutableMap.of(opt1, "123", opt2, "baz")));
    assertThat(bar.field("b").options().map())
        .isEqualTo(ImmutableMap.of(fooOptions, ImmutableMap.of(opt1, "456", opt2, "quux")));
  }
  private List<Tuple> getTablespaces(Schema outSchema) {
    List<TablespaceProto> tablespaces = masterContext.getCatalog().getAllTablespaces();
    List<Tuple> tuples = new ArrayList<Tuple>(tablespaces.size());
    List<Column> columns = outSchema.getRootColumns();
    Tuple aTuple;

    for (TablespaceProto tablespace : tablespaces) {
      aTuple = new VTuple(outSchema.size());

      for (int fieldId = 0; fieldId < columns.size(); fieldId++) {
        Column column = columns.get(fieldId);
        if ("space_id".equalsIgnoreCase(column.getSimpleName())) {
          if (tablespace.hasId()) {
            aTuple.put(fieldId, DatumFactory.createInt4(tablespace.getId()));
          } else {
            aTuple.put(fieldId, DatumFactory.createNullDatum());
          }
        } else if ("space_name".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createText(tablespace.getSpaceName()));
        } else if ("space_handler".equalsIgnoreCase(column.getSimpleName())) {
          if (tablespace.hasHandler()) {
            aTuple.put(fieldId, DatumFactory.createText(tablespace.getHandler()));
          } else {
            aTuple.put(fieldId, DatumFactory.createNullDatum());
          }
        } else if ("space_uri".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createText(tablespace.getUri()));
        }
      }
      tuples.add(aTuple);
    }

    return tuples;
  }
Exemple #17
0
  @Test
  public void testUDF() throws Exception {
    String ddl =
        "CREATE VIRTUAL FUNCTION SourceFunc(flag boolean, msg varchar) RETURNS varchar "
            + "OPTIONS(CATEGORY 'misc', DETERMINISM 'DETERMINISTIC', "
            + "\"NULL-ON-NULL\" 'true', JAVA_CLASS 'foo', JAVA_METHOD 'bar', RANDOM 'any', UUID 'x')";

    Schema s = helpParse(ddl, "model").getSchema();

    FunctionMethod fm = s.getFunction("x");
    assertNotNull(fm);
    assertEquals("string", fm.getOutputParameter().getType());
    assertEquals(FunctionMethod.PushDown.CAN_PUSHDOWN, fm.getPushdown());
    assertEquals(2, fm.getInputParameterCount());
    assertEquals("flag", fm.getInputParameters().get(0).getName());
    assertEquals("boolean", fm.getInputParameters().get(0).getType());
    assertEquals("msg", fm.getInputParameters().get(1).getName());
    assertEquals("string", fm.getInputParameters().get(1).getType());
    assertFalse(fm.getInputParameters().get(1).isVarArg());

    assertEquals(FunctionMethod.Determinism.DETERMINISTIC, fm.getDeterminism());
    assertEquals("misc", fm.getCategory());
    assertEquals(true, fm.isNullOnNull());
    assertEquals("foo", fm.getInvocationClass());
    assertEquals("bar", fm.getInvocationMethod());
    assertEquals("any", fm.getProperties().get("RANDOM"));
  }
Exemple #18
0
  @Test
  public void testMultipleCommands2() throws Exception {
    String ddl =
        "             CREATE VIRTUAL PROCEDURE getTweets(query varchar) RETURNS (created_on varchar(25), from_user varchar(25), to_user varchar(25), \n"
            + "                 profile_image_url varchar(25), source varchar(25), text varchar(140)) AS \n"
            + "                select tweet.* from \n"
            + "	                (call twitter.invokeHTTP(action => 'GET', endpoint =>querystring('',query as \"q\"))) w, \n"
            + "	                XMLTABLE('results' passing JSONTOXML('myxml', w.result) columns \n"
            + "	                created_on string PATH 'created_at', \n"
            + "	                from_user string PATH 'from_user',\n"
            + "	                to_user string PATH 'to_user',	\n"
            + "	                profile_image_url string PATH 'profile_image_url',	\n"
            + "	                source string PATH 'source',	\n"
            + "	                text string PATH 'text') tweet;"
            + "                CREATE VIEW Tweet AS select * FROM twitterview.getTweets;";

    Schema s = helpParse(ddl, "model").getSchema();
    Map<String, Table> tableMap = s.getTables();
    Table table = tableMap.get("Tweet");
    assertNotNull(table);

    Map<String, Procedure> procedureMap = s.getProcedures();
    Procedure p = procedureMap.get("getTweets");
    assertNotNull(p);
  }
Exemple #19
0
 public RelOptTableImpl getTable(final String[] names) {
   List<Pair<String, Object>> pairs = new ArrayList<Pair<String, Object>>();
   Schema schema2 = schema;
   for (int i = 0; i < names.length; i++) {
     final String name = names[i];
     Schema subSchema = schema2.getSubSchema(name);
     if (subSchema != null) {
       pairs.add(Pair.<String, Object>of(name, subSchema));
       schema2 = subSchema;
       continue;
     }
     final Table table = schema2.getTable(name);
     if (table != null) {
       pairs.add(Pair.<String, Object>of(name, table));
       if (i != names.length - 1) {
         // not enough objects to match all names
         return null;
       }
       return new RelOptTableImpl(
           this, typeFactory.createType(table.getElementType()), names, table);
     }
     return null;
   }
   return null;
 }
Exemple #20
0
  protected void init2ndPassNamesWithDefaults() {
    if (tableName == null) {
      tableName = DaoUtil.dbName(className);
    }

    if (classNameDao == null) {
      classNameDao = className + "Dao";
    }
    if (classNameTest == null) {
      classNameTest = className + "Test";
    }

    if (javaPackage == null) {
      javaPackage = schema.getDefaultJavaPackage();
    }

    if (javaPackageDao == null) {
      javaPackageDao = schema.getDefaultJavaPackageDao();
      if (javaPackageDao == null) {
        javaPackageDao = javaPackage;
      }
    }
    if (javaPackageTest == null) {
      javaPackageTest = schema.getDefaultJavaPackageTest();
      if (javaPackageTest == null) {
        javaPackageTest = javaPackage;
      }
    }
  }
Exemple #21
0
  public void execExplain(
      Session session,
      String query,
      LogicalPlan plan,
      QueryContext queryContext,
      boolean isGlobal,
      SubmitQueryResponse.Builder response)
      throws Exception {

    String explainStr;
    boolean isTest = queryContext.getBool(SessionVars.TEST_PLAN_SHAPE_FIX_ENABLED);
    if (isTest) {
      ExplainPlanPreprocessorForTest preprocessorForTest = new ExplainPlanPreprocessorForTest();
      preprocessorForTest.prepareTest(plan);
    }

    if (isGlobal) {
      GlobalPlanner planner = new GlobalPlanner(context.getConf(), context.getCatalog());
      MasterPlan masterPlan = compileMasterPlan(plan, queryContext, planner);
      if (isTest) {
        ExplainGlobalPlanPreprocessorForTest globalPlanPreprocessorForTest =
            new ExplainGlobalPlanPreprocessorForTest();
        globalPlanPreprocessorForTest.prepareTest(masterPlan);
      }
      explainStr = masterPlan.toString();
    } else {
      explainStr = PlannerUtil.buildExplainString(plan.getRootBlock().getRoot());
    }

    Schema schema = new Schema();
    schema.addColumn("explain", TajoDataTypes.Type.TEXT);
    RowStoreUtil.RowStoreEncoder encoder = RowStoreUtil.createEncoder(schema);

    SerializedResultSet.Builder serializedResBuilder = SerializedResultSet.newBuilder();

    VTuple tuple = new VTuple(1);
    String[] lines = explainStr.split("\n");
    int bytesNum = 0;
    for (String line : lines) {
      tuple.put(0, DatumFactory.createText(line));
      byte[] encodedData = encoder.toBytes(tuple);
      bytesNum += encodedData.length;
      serializedResBuilder.addSerializedTuples(ByteString.copyFrom(encodedData));
    }
    serializedResBuilder.setSchema(schema.getProto());
    serializedResBuilder.setBytesNum(bytesNum);

    QueryInfo queryInfo =
        context
            .getQueryJobManager()
            .createNewSimpleQuery(
                queryContext, session, query, (LogicalRootNode) plan.getRootBlock().getRoot());

    response.setState(OK);
    response.setQueryId(queryInfo.getQueryId().getProto());
    response.setResultType(ResultType.ENCLOSED);
    response.setResultSet(serializedResBuilder.build());
    response.setMaxRowNum(lines.length);
  }
 public void write(Kml kml) throws KmlException {
   kml.println("<Document" + getIdAndTargetIdFormatted(kml) + ">", 1);
   writeInner(kml);
   if (schemas != null) {
     for (Schema schema : schemas) schema.write(kml);
   }
   kml.println(-1, "</Document>");
 }
Exemple #23
0
 public void addSchema(Schema schema) {
   if (this.schemas.put(schema.getName(), schema) != null) {
     throw new DuplicateRecordException(
         DataPlugin.Event.TEIID60012,
         DataPlugin.Util.gs(DataPlugin.Event.TEIID60012, schema.getName()));
   }
   this.schemaList.add(schema);
 }
Exemple #24
0
  @Test
  public void testGlobalTemp() throws Exception {
    String ddl = "CREATE GLOBAL TEMPORARY TABLE T (col string);";

    Schema s = helpParse(ddl, "model").getSchema();
    Table t = s.getTable("T");
    assertEquals(1, t.getColumns().size());
  }
  private Tuple getWorkerTuple(Schema outSchema, Worker aWorker) {
    List<Column> columns = outSchema.getRootColumns();
    Tuple aTuple = new VTuple(outSchema.size());
    WorkerResource aResource = aWorker.getResource();

    for (int fieldId = 0; fieldId < columns.size(); fieldId++) {
      Column column = columns.get(fieldId);

      if ("host".equalsIgnoreCase(column.getSimpleName())) {
        if (aWorker.getConnectionInfo() != null && aWorker.getConnectionInfo().getHost() != null) {
          aTuple.put(fieldId, DatumFactory.createText(aWorker.getConnectionInfo().getHost()));
        } else {
          aTuple.put(fieldId, DatumFactory.createNullDatum());
        }
      } else if ("port".equalsIgnoreCase(column.getSimpleName())) {
        if (aWorker.getConnectionInfo() != null) {
          aTuple.put(
              fieldId, DatumFactory.createInt4(aWorker.getConnectionInfo().getPeerRpcPort()));
        } else {
          aTuple.put(fieldId, DatumFactory.createNullDatum());
        }
      } else if ("type".equalsIgnoreCase(column.getSimpleName())) {
        aTuple.put(fieldId, DatumFactory.createText("Worker"));
      } else if ("status".equalsIgnoreCase(column.getSimpleName())) {
        aTuple.put(fieldId, DatumFactory.createText(aWorker.getState().toString()));
      } else if ("RUNNING".equalsIgnoreCase(aWorker.getState().toString())) {
        if ("total_cpu".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createInt4(aResource.getCpuCoreSlots()));
        } else if ("used_mem".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createInt8(aResource.getUsedMemoryMB() * 1048576l));
        } else if ("total_mem".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createInt8(aResource.getMemoryMB() * 1048576l));
        } else if ("free_heap".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createInt8(aResource.getFreeHeap()));
        } else if ("max_heap".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createInt8(aResource.getMaxHeap()));
        } else if ("used_diskslots".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createFloat4(aResource.getUsedDiskSlots()));
        } else if ("total_diskslots".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createFloat4(aResource.getDiskSlots()));
        } else if ("running_tasks".equalsIgnoreCase(column.getSimpleName())) {
          aTuple.put(fieldId, DatumFactory.createInt4(aResource.getNumRunningTasks()));
        } else if ("last_heartbeat_ts".equalsIgnoreCase(column.getSimpleName())) {
          if (aWorker.getLastHeartbeatTime() > 0) {
            aTuple.put(
                fieldId,
                DatumFactory.createTimestmpDatumWithJavaMillis(aWorker.getLastHeartbeatTime()));
          } else {
            aTuple.put(fieldId, DatumFactory.createNullDatum());
          }
        }
      } else {
        aTuple.put(fieldId, DatumFactory.createNullDatum());
      }
    }

    return aTuple;
  }
Exemple #26
0
  @Test
  public void testMixedCaseTypes() throws Exception {
    String ddl = "CREATE FUNCTION SourceFunc(flag Boolean) RETURNS varchaR options (UUID 'z')";

    Schema s = helpParse(ddl, "model").getSchema();

    FunctionMethod fm = s.getFunction("z");
    assertEquals("boolean", fm.getInputParameters().get(0).getType());
  }
Exemple #27
0
  @Test(expected = MetadataException.class)
  public void testInvalidProcedureBody() throws Exception {
    String ddl = "CREATE FOREIGN PROCEDURE SourceFunc(flag boolean) RETURNS varchar AS SELECT 'a';";

    Schema s = helpParse(ddl, "model").getSchema();

    FunctionMethod fm = s.getFunction("z");
    assertTrue(fm.getInputParameters().get(0).isVarArg());
  }
Exemple #28
0
 /** Returns the root schema. */
 public static Schema root(Schema schema) {
   for (Schema s = schema; ; ) {
     Schema previous = s;
     s = s.getParentSchema();
     if (s == null) {
       return previous;
     }
   }
 }
Exemple #29
0
 public void testTableTree() {
   BasicTable table = (BasicTable) populatedSchema.getTables().getByName("Test_Three");
   BasicTable.BasicTableTreeNode treeNode =
       (BasicTable.BasicTableTreeNode)
           table.createTreeNode(populatedSchema.getStructure(), null, 0);
   assertSame(populatedSchema.getStructure(), treeNode.getOwner());
   assertNotNull(treeNode.toString());
   assertTrue(treeNode.hasChildren());
 }
Exemple #30
0
  void init2ndPass() {
    init2ndPassNamesWithDefaults();

    for (int i = 0; i < properties.size(); i++) {
      Property property = properties.get(i);
      property.setOrdinal(i);
      property.init2ndPass();
      if (property.isPrimaryKey()) {
        propertiesPk.add(property);
      } else {
        propertiesNonPk.add(property);
      }
    }

    if (propertiesPk.size() == 1) {
      pkProperty = propertiesPk.get(0);
      pkType = schema.mapToJavaTypeNullable(pkProperty.getPropertyType());
    } else {
      pkType = "Void";
    }

    propertiesColumns = new ArrayList<Property>(properties);
    for (ToOne toOne : toOneRelations) {
      toOne.init2ndPass();
      Property[] fkProperties = toOne.getFkProperties();
      for (Property fkProperty : fkProperties) {
        if (!propertiesColumns.contains(fkProperty)) {
          propertiesColumns.add(fkProperty);
        }
      }
    }

    for (ToMany toMany : toManyRelations) {
      toMany.init2ndPass();
      // Source Properties may not be virtual, so we do not need the following code:
      // for (Property sourceProperty : toMany.getSourceProperties()) {
      // if (!propertiesColumns.contains(sourceProperty)) {
      // propertiesColumns.add(sourceProperty);
      // }
      // }
    }

    if (active == null) {
      active = schema.isUseActiveEntitiesByDefault();
    }
    active |= !toOneRelations.isEmpty() || !toManyRelations.isEmpty();

    if (hasKeepSections == null) {
      hasKeepSections = schema.isHasKeepSectionsByDefault();
    }

    init2ndPassIndexNamesWithDefaults();

    for (ContentProvider contentProvider : contentProviders) {
      contentProvider.init2ndPass();
    }
  }