Search in sources :

Example 66 with AbstractList

use of java.util.AbstractList in project calcite by apache.

the class GeodeToEnumerableConverter method implement.

/**
 * {@inheritDoc}
 *
 * @param implementor GeodeImplementContext
 */
@Override
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    // travers all relations form this to the scan leaf
    final GeodeImplementContext geodeImplementContext = new GeodeImplementContext();
    ((GeodeRel) getInput()).implement(geodeImplementContext);
    // PhysType is Enumerable Adapter class that maps SQL types (getRowType)
    // with physical Java types (getJavaTypes())
    final PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), rowType, pref.prefer(JavaRowFormat.ARRAY));
    final List<Class> physFieldClasses = new AbstractList<Class>() {

        public Class get(int index) {
            return physType.fieldClass(index);
        }

        public int size() {
            return rowType.getFieldCount();
        }
    };
    // Expression meta-program for calling the GeodeTable.GeodeQueryable#query
    // method form the generated code
    final BlockBuilder blockBuilder = new BlockBuilder().append(Expressions.call(geodeImplementContext.table.getExpression(GeodeTable.GeodeQueryable.class), GEODE_QUERY_METHOD, constantArrayList(Pair.zip(geodeFieldNames(rowType), physFieldClasses), Pair.class), // physical fields
    constantArrayList(toListMapPairs(geodeImplementContext.selectFields), Pair.class), // selected fields
    constantArrayList(toListMapPairs(geodeImplementContext.oqlAggregateFunctions), Pair.class), constantArrayList(geodeImplementContext.groupByFields, String.class), constantArrayList(geodeImplementContext.whereClause, String.class), constantArrayList(geodeImplementContext.orderByFields, String.class), Expressions.constant(geodeImplementContext.limitValue)));
    Hook.QUERY_PLAN.run(geodeImplementContext);
    return implementor.result(physType, blockBuilder.toBlock());
}
Also used : AbstractList(java.util.AbstractList) PhysType(org.apache.calcite.adapter.enumerable.PhysType) GeodeImplementContext(org.apache.calcite.adapter.geode.rel.GeodeRel.GeodeImplementContext) BlockBuilder(org.apache.calcite.linq4j.tree.BlockBuilder)

Example 67 with AbstractList

use of java.util.AbstractList in project flink by apache.

the class OrInputTypeStrategy method getArgumentCount.

@Override
public ArgumentCount getArgumentCount() {
    final List<ArgumentCount> counts = new AbstractList<ArgumentCount>() {

        public ArgumentCount get(int index) {
            return inputStrategies.get(index).getArgumentCount();
        }

        public int size() {
            return inputStrategies.size();
        }
    };
    final Integer min = commonMin(counts);
    final Integer max = commonMax(counts);
    final ArgumentCount compositeCount = new ArgumentCount() {

        @Override
        public boolean isValidCount(int count) {
            for (ArgumentCount c : counts) {
                if (c.isValidCount(count)) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public Optional<Integer> getMinCount() {
            return Optional.ofNullable(min);
        }

        @Override
        public Optional<Integer> getMaxCount() {
            return Optional.ofNullable(max);
        }
    };
    // use constant count if applicable
    if (min == null || max == null) {
        // no boundaries
        return compositeCount;
    }
    for (int i = min; i <= max; i++) {
        if (!compositeCount.isValidCount(i)) {
            // not the full range
            return compositeCount;
        }
    }
    if (min.equals(max)) {
        return ConstantArgumentCount.of(min);
    }
    return ConstantArgumentCount.between(min, max);
}
Also used : ArgumentCount(org.apache.flink.table.types.inference.ArgumentCount) ConstantArgumentCount(org.apache.flink.table.types.inference.ConstantArgumentCount) AbstractList(java.util.AbstractList)

Example 68 with AbstractList

use of java.util.AbstractList in project neo4j by neo4j.

the class DependenciesTest method givenSatisfiedTypeWhenResolveWithSuperTypeThenInstanceReturned.

@Test
void givenSatisfiedTypeWhenResolveWithSuperTypeThenInstanceReturned() {
    // Given
    Dependencies dependencies = new Dependencies();
    AbstractList foo = new ArrayList();
    dependencies.satisfyDependency(foo);
    // When
    AbstractList instance = dependencies.resolveDependency(AbstractList.class);
    // Then
    assertThat(instance).isEqualTo(foo);
}
Also used : AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 69 with AbstractList

use of java.util.AbstractList in project drill by apache.

the class SqlHandlerUtil method qualifyPartitionCol.

/**
 *  Resolve the partition columns specified in "PARTITION BY" clause of CTAS statement.
 *
 *  A partition column is resolved, either (1) the same column appear in the select list of CTAS
 *  or (2) CTAS has a * in select list.
 *
 *  In the second case, a PROJECT with ITEM expression would be created and returned.
 *  Throw validation error if a partition column is not resolved correctly.
 *
 * @param input : the RelNode represents the select statement in CTAS.
 * @param partitionColumns : the list of partition columns.
 * @return : 1) the original RelNode input, if all partition columns are in select list of CTAS
 *           2) a New Project, if a partition column is resolved to * column in select list
 *           3) validation error, if partition column is not resolved.
 */
public static RelNode qualifyPartitionCol(RelNode input, List<String> partitionColumns) {
    final RelDataType inputRowType = input.getRowType();
    final List<RexNode> colRefStarExprs = Lists.newArrayList();
    final List<String> colRefStarNames = Lists.newArrayList();
    final RexBuilder builder = input.getCluster().getRexBuilder();
    final int originalFieldSize = inputRowType.getFieldCount();
    for (final String col : partitionColumns) {
        final RelDataTypeField field = inputRowType.getField(col, false, false);
        if (field == null) {
            throw UserException.validationError().message("Partition column %s is not in the SELECT list of CTAS!", col).build(logger);
        } else {
            if (SchemaPath.DYNAMIC_STAR.equals(field.getName())) {
                colRefStarNames.add(col);
                final List<RexNode> operands = Lists.newArrayList();
                operands.add(new RexInputRef(field.getIndex(), field.getType()));
                operands.add(builder.makeLiteral(col));
                final RexNode item = builder.makeCall(SqlStdOperatorTable.ITEM, operands);
                colRefStarExprs.add(item);
            }
        }
    }
    if (colRefStarExprs.isEmpty()) {
        return input;
    } else {
        final List<String> names = new AbstractList<String>() {

            @Override
            public String get(int index) {
                if (index < originalFieldSize) {
                    return inputRowType.getFieldNames().get(index);
                } else {
                    return colRefStarNames.get(index - originalFieldSize);
                }
            }

            @Override
            public int size() {
                return originalFieldSize + colRefStarExprs.size();
            }
        };
        final List<RexNode> refs = new AbstractList<RexNode>() {

            @Override
            public int size() {
                return originalFieldSize + colRefStarExprs.size();
            }

            @Override
            public RexNode get(int index) {
                if (index < originalFieldSize) {
                    return RexInputRef.of(index, inputRowType.getFieldList());
                } else {
                    return colRefStarExprs.get(index - originalFieldSize);
                }
            }
        };
        return DrillRelFactories.LOGICAL_BUILDER.create(input.getCluster(), null).push(input).projectNamed(refs, names, true).build();
    }
}
Also used : AbstractList(java.util.AbstractList) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RexBuilder(org.apache.calcite.rex.RexBuilder) RexInputRef(org.apache.calcite.rex.RexInputRef) RelDataType(org.apache.calcite.rel.type.RelDataType) RexNode(org.apache.calcite.rex.RexNode)

Example 70 with AbstractList

use of java.util.AbstractList in project pentaho-kettle by pentaho.

the class PurRepositoryIT method testExportWithRules.

@Test
public void testExportWithRules() throws Exception {
    String fileName = "testExportWithRuled.xml";
    // $NON-NLS-1$
    final String exportFileName = new File(fileName).getAbsolutePath();
    RepositoryDirectoryInterface rootDir = initRepo();
    String transWithoutNoteName = "2" + EXP_DBMETA_NAME;
    TransMeta transWithoutNote = createTransMeta(transWithoutNoteName);
    String transUniqueName = EXP_TRANS_NAME.concat(transWithoutNoteName);
    RepositoryDirectoryInterface transDir = rootDir.findDirectory(DIR_TRANSFORMATIONS);
    repository.save(transWithoutNote, VERSION_COMMENT_V1, null);
    // So this transformation is cleaned up afterward
    deleteStack.push(transWithoutNote);
    assertNotNull(transWithoutNote.getObjectId());
    assertTrue(hasVersionWithComment(transWithoutNote, VERSION_COMMENT_V1));
    assertTrue(repository.exists(transUniqueName, transDir, RepositoryObjectType.TRANSFORMATION));
    // Second transformation (contained note)
    String transWithNoteName = "1" + EXP_DBMETA_NAME;
    TransMeta transWithNote = createTransMeta(transWithNoteName);
    transUniqueName = EXP_TRANS_NAME.concat(EXP_DBMETA_NAME);
    TransMeta transWithRules = createTransMeta(EXP_DBMETA_NAME);
    NotePadMeta note = new NotePadMeta("Note Message", 1, 1, 100, 5);
    transWithRules.addNote(note);
    repository.save(transWithRules, VERSION_COMMENT_V1, null);
    // So this transformation is cleaned up afterward
    deleteStack.push(transWithRules);
    assertNotNull(transWithRules.getObjectId());
    assertTrue(hasVersionWithComment(transWithRules, VERSION_COMMENT_V1));
    assertTrue(repository.exists(transUniqueName, transDir, RepositoryObjectType.TRANSFORMATION));
    // create rules for export to .xml file
    List<ImportRuleInterface> rules = new AbstractList<ImportRuleInterface>() {

        @Override
        public ImportRuleInterface get(int index) {
            TransformationHasANoteImportRule rule = new TransformationHasANoteImportRule();
            rule.setEnabled(true);
            return rule;
        }

        @Override
        public int size() {
            return 1;
        }
    };
    ImportRules importRules = new ImportRules();
    importRules.setRules(rules);
    // create exporter
    IRepositoryExporter exporter = repository.getExporter();
    exporter.setImportRulesToValidate(importRules);
    // export itself
    try {
        // $NON-NLS-1$
        exporter.exportAllObjects(new MockProgressMonitorListener(), exportFileName, null, "all");
        FileObject exportFile = KettleVFS.getFileObject(exportFileName);
        assertNotNull(exportFile);
        MockRepositoryExportParser parser = new MockRepositoryExportParser();
        SAXParserFactory.newInstance().newSAXParser().parse(KettleVFS.getInputStream(exportFile), parser);
        if (parser.getFatalError() != null) {
            throw parser.getFatalError();
        }
        // assumed transformation with note will be here and only it
        assertEquals("Incorrect number of transformations", 1, parser.getNodesWithName(RepositoryObjectType.TRANSFORMATION.getTypeDescription()).size());
    } finally {
        KettleVFS.getFileObject(exportFileName).delete();
    }
}
Also used : AbstractList(java.util.AbstractList) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) ImportRuleInterface(org.pentaho.di.imp.rule.ImportRuleInterface) TransMeta(org.pentaho.di.trans.TransMeta) Matchers.anyString(org.mockito.Matchers.anyString) ImportRules(org.pentaho.di.imp.ImportRules) TransformationHasANoteImportRule(org.pentaho.di.imp.rules.TransformationHasANoteImportRule) NotePadMeta(org.pentaho.di.core.NotePadMeta) FileObject(org.apache.commons.vfs2.FileObject) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IRepositoryExporter(org.pentaho.di.repository.IRepositoryExporter) Test(org.junit.Test)

Aggregations

AbstractList (java.util.AbstractList)76 ArrayList (java.util.ArrayList)30 List (java.util.List)17 HashMap (java.util.HashMap)10 NodeRef (org.alfresco.service.cmr.repository.NodeRef)10 QName (org.alfresco.service.namespace.QName)9 UserInfo (org.alfresco.rest.api.model.UserInfo)8 FileInfo (org.alfresco.service.cmr.model.FileInfo)8 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)7 RexNode (org.apache.calcite.rex.RexNode)7 Collection (java.util.Collection)6 ConcurrentModificationException (java.util.ConcurrentModificationException)6 Iterator (java.util.Iterator)6 Paging (org.alfresco.rest.framework.resource.parameters.Paging)6 IOException (java.io.IOException)5 Set (java.util.Set)5 FilterProp (org.alfresco.repo.node.getchildren.FilterProp)5 Test (org.junit.Test)5 ListIterator (java.util.ListIterator)4 RandomAccess (java.util.RandomAccess)4