美文网首页
Pilosa 快速开始

Pilosa 快速开始

作者: kaiker | 来源:发表于2021-08-27 16:36 被阅读0次

    https://www.pilosa.com/docs/latest/getting-started/

    1、安装

    brew update
    
    brew install pilosa
    

    2、启动pilosa server

    pilosa server
    有可能会提示一个错误 试一下先 ulimit -n 4096再启动
    然后在http://localhost:10101/就能看到了

    10101

    3、Java的例子

    • 如果报no host,是没启动server;
    • 文件如下;
    curl -O https://raw.githubusercontent.com/pilosa/getting-started/master/stargazer.csv
    curl -O https://raw.githubusercontent.com/pilosa/getting-started/master/language.csv
    
    • pom在官网能找到。
    image.png
    import com.pilosa.client.PilosaClient;
    import com.pilosa.client.QueryResponse;
    import com.pilosa.client.exceptions.PilosaException;
    import com.pilosa.client.orm.*;
    import com.pilosa.client.csv.FileRecordIterator;
    import com.pilosa.client.TimeQuantum;
    
    import java.io.IOException;
    import java.text.SimpleDateFormat;
    
    public class StarTrace {
        public static void main(String []args) throws IOException {
            // Create the Schema
            PilosaClient client = PilosaClient.defaultClient();
            Schema schema = client.readSchema();
            Index repository = schema.index("repository");
    
            FieldOptions stargazerOptions = FieldOptions.builder()
                    .fieldTime(TimeQuantum.YEAR_MONTH_DAY)
                    .build();
            Field stargazer = repository.field("stargazer", stargazerOptions);
    
            Field language = repository.field("language");
            client.syncSchema(schema);
    
            String resourcePath = 
            SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm");
            FileRecordIterator iterator = FileRecordIterator.fromPath(resourcePath + "stargazer.csv", stargazer, timestampFormat);
            client.importField(stargazer, iterator);
    
            iterator = FileRecordIterator.fromPath(resourcePath + "language.csv", language);
            client.importField(language, iterator);
    
            QueryResponse response = client.query(stargazer.row(14));
            System.out.println("User 14 starred: " + response.getResult().getRow().getColumns());
    
            response = client.query(language.topN(5));
            System.out.println("Top Languages: " + response.getResult().getCountItems());
    
            response = client.query(repository.intersect(stargazer.row(14), stargazer.row(19)));
            System.out.println("Both user 14 and 19 starred: " + response.getResult().getRow().getColumns());
    
            response = client.query(repository.union(stargazer.row(14), stargazer.row(19)));
            System.out.println("User 14 or 19 starred: " + response.getResult().getRow().getColumns());
    
            response = client.query(repository.intersect(stargazer.row(14), stargazer.row(19), language.row(1)));
            System.out.println("Both user 14 and 19 starred and were written in language 1: " + response.getResult().getRow().getColumns());
    
            client.query(stargazer.set(99999, 77777));
            System.out.println("Set user 99999 as a stargazer for repository 77777");
        }
    }
    
    

    相关文章

      网友评论

          本文标题:Pilosa 快速开始

          本文链接:https://www.haomeiwen.com/subject/oxbmiltx.html